Adapters
9 years ago
Providers
9 years ago
Autoload.php
9 years ago
Embera.php
9 years ago
FakeResponse.php
9 years ago
Formatter.php
9 years ago
HttpRequest.php
9 years ago
Oembed.php
9 years ago
Providers.php
9 years ago
Url.php
9 years ago
FakeResponse.php
84 lines
| 1 | <?php |
| 2 | /** |
| 3 | * FakeResponse.php |
| 4 | * |
| 5 | * @package Embera |
| 6 | * @author Michael Pratt <pratt@hablarmierda.net> |
| 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 | public function __construct(array $config = array(), array $response = array()) |
| 43 | { |
| 44 | $this->config = array_replace_recursive(array( |
| 45 | 'fake' => array( |
| 46 | 'width' => 420, |
| 47 | 'height' => 315 |
| 48 | ), |
| 49 | 'params' => array( |
| 50 | 'maxwidth' => 0, |
| 51 | 'maxheight' => 0, |
| 52 | ) |
| 53 | ), $config); |
| 54 | |
| 55 | $this->config['fake']['width'] = max($this->config['fake']['width'], $this->config['params']['maxwidth']); |
| 56 | $this->config['fake']['height'] = max($this->config['fake']['height'], $this->config['params']['maxheight']); |
| 57 | unset($this->config['params']); |
| 58 | |
| 59 | $this->response = array_merge($this->response, $this->config['fake'], $response); |
| 60 | } |
| 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 | public function buildResponse() |
| 70 | { |
| 71 | $return = array(); |
| 72 | foreach ($this->response as $k => $v) |
| 73 | { |
| 74 | $return[$k] = str_replace(array_map(function ($name){ |
| 75 | return '{' . $name . '}'; |
| 76 | }, array_keys($this->config['fake'])), array_values($this->config['fake']), $v); |
| 77 | } |
| 78 | |
| 79 | return $return; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | ?> |
| 84 |