|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* FakeResponse.php |
|
4
|
|
|
* |
|
5
|
|
|
* @package Embera |
|
6
|
|
|
* @author Michael Pratt <[email protected]> |
|
7
|
|
|
* @link http://www.michael-pratt.com/ |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Embera; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* This class manages fake oembed responses |
|
17
|
|
|
*/ |
|
18
|
|
|
class FakeResponse |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var array Configuration Array */ |
|
21
|
|
|
protected $config = array(); |
|
22
|
|
|
|
|
23
|
|
|
/** @var array Array with default oembed data */ |
|
24
|
|
|
protected $response = array( |
|
25
|
|
|
'version' => '1.0', |
|
26
|
|
|
'provider_name' => '', |
|
27
|
|
|
'url' => '', |
|
28
|
|
|
'title' => '', |
|
29
|
|
|
'author_name' => '', |
|
30
|
|
|
'author_url' => '', |
|
31
|
|
|
'cache_age' => 0, |
|
32
|
|
|
'embera_using_fake' => 1 |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Construct |
|
37
|
|
|
* |
|
38
|
|
|
* @param array $config |
|
39
|
|
|
* @param array $response |
|
40
|
|
|
* @return void |
|
|
|
|
|
|
41
|
|
|
*/ |
|
42
|
88 |
|
public function __construct(array $config = array(), array $response = array()) |
|
43
|
|
|
{ |
|
44
|
88 |
|
$this->config = array_replace_recursive(array( |
|
45
|
|
|
'fake' => array( |
|
46
|
88 |
|
'width' => 420, |
|
47
|
|
|
'height' => 315 |
|
48
|
88 |
|
), |
|
49
|
|
|
'params' => array( |
|
50
|
88 |
|
'maxwidth' => 0, |
|
51
|
88 |
|
'maxheight' => 0, |
|
52
|
|
|
) |
|
53
|
88 |
|
), $config); |
|
54
|
|
|
|
|
55
|
88 |
|
$this->config['fake']['width'] = max($this->config['fake']['width'], $this->config['params']['maxwidth']); |
|
56
|
88 |
|
$this->config['fake']['height'] = max($this->config['fake']['height'], $this->config['params']['maxheight']); |
|
57
|
88 |
|
unset($this->config['params']); |
|
58
|
|
|
|
|
59
|
88 |
|
$this->response = array_merge($this->response, $this->config['fake'], $response); |
|
60
|
88 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Builds the fake response. |
|
64
|
|
|
* This replaces placeholders that are present in $config['fake'] |
|
65
|
|
|
* into the response array |
|
66
|
|
|
* |
|
67
|
|
|
* @return array |
|
68
|
|
|
*/ |
|
69
|
88 |
|
public function buildResponse() |
|
70
|
|
|
{ |
|
71
|
88 |
|
$return = array(); |
|
72
|
88 |
|
foreach ($this->response as $k => $v) |
|
73
|
|
|
{ |
|
74
|
88 |
|
$return[$k] = str_replace(array_map(function ($name){ |
|
75
|
88 |
|
return '{' . $name . '}'; |
|
76
|
88 |
|
}, array_keys($this->config['fake'])), array_values($this->config['fake']), $v); |
|
77
|
88 |
|
} |
|
78
|
|
|
|
|
79
|
88 |
|
return $return; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
?> |
|
|
|
|
|
|
84
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.