-
Notifications
You must be signed in to change notification settings - Fork 3
/
Oembed.php
84 lines (72 loc) · 1.74 KB
/
Oembed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php namespace Pingpong\Oembed;
use Illuminate\Cache\Repository;
/**
* Class Oembed
*
* @package Pingpong\Oembed
* @author Pingpong Labs <pingpong.labs@gmail.com>
* @author Gravitano <gravitano16@gmail.com>
* @license https://github.com/pingpong-labs/oembed/blob/master/LICENSE MIT
*/
class Oembed {
/**
* The Embed instance.
*
* @var \Pingpong\Oembed\Embed
*/
protected $embed;
/**
* The Cache Repository.
*
* @var Repository
*/
protected $cache;
/**
* The constructor.
*
* @param Embed $embed
*/
public function __construct(Embed $embed, Repository $cache)
{
$this->embed = $embed;
$this->cache = $cache;
}
/**
* Get info from a specify url.
*
* @param string $url
* @param null|array $options
* @return false|\Embed\Adapters\AdapterInterface
*/
public function get($url, array $options = null)
{
return $this->embed->get($url, $options);
}
/**
* Get info from a specify url and cache that using laravel cache manager.
*
* @param string $url
* @param null|array $options
* @return mixed
*/
public function cache($url, array $options = null)
{
$lifetime = array_get($options, 'lifetime', 60);
array_forget($options, 'lifetime');
$self = $this;
return $this->cache->remember($url, $lifetime, function() use ($self, $url, $options)
{
return $self->get($url, $options);
});
}
/**
* Gets the info from a source (list of urls).
*
* @param string|Request $url The url or a request with the source url
* @return false|\Embed\Sources\SourceInterface
*/
public function createSource($url)
{
return $this->embed->source($url);
}
}