PluginProbe
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.9.9
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.9.9
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 All 189 releases
embedpress / vendor / wpdevelopers / embera / src / Embera / Provider / ProviderAdapter.php
ProviderAdapter.php
148 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ProviderAdapter.php
4 *
5 * @package Adapters
6 * @author Michael Pratt <yo@michael-pratt.com>
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\Provider;
14
15 use Embera\Url;
16
17 /**
18 * ProviderAdapter has boilerplate methods that help remove code
19 * from the other providers. It has the basic boilerplate to instantiate
20 * and validate Providers.
21 */
22 abstract class ProviderAdapter
23 {
24 /** @var bool $shouldSendRequest It determins wether we should send api request to get the embed data or we will create embed data manually */
25 protected $shouldSendRequest = true;
26 /** @var Url */
27 protected $url;
28
29 /** @var array with hosts where the provider belongs */
30 protected static $hosts = [];
31
32 /** @var array Associative array with config/parameters to be sent to the oembed provider */
33 protected $config = [];
34
35 /** @var array Array with allowed params for the current Provider */
36 protected $allowedParams = [ 'maxwidth', 'maxheight' ];
37
38 /** @var string The api url for the current service */
39 protected $endpoint = null;
40
41 /** @var bool Wether the provider supports https */
42 protected $httpsSupport = false;
43
44 /** @var bool Wether the provider supports responsive embeds */
45 protected $responsiveSupport = false;
46
47 /** inline {@inheritdoc} */
48 public function __construct($url, array $config = [])
49 {
50 $this->config = $config;
51 $this->url = $this->normalizeUrl(new Url($url));
52 }
53
54 /** inline {@inheritdoc} */
55 public function getParams()
56 {
57 $params = [];
58 foreach ($this->allowedParams as $key) {
59 if (isset($this->config[$key])) {
60 $params[$key] = $this->config[$key];
61 }
62
63 $customKey = strtolower($this->getProviderName() . '_' . $key);
64 if (isset($this->config[$customKey])) {
65 $params[$key] = $this->config[$customKey];
66 }
67 }
68
69 return array_filter(array_merge($params,[
70 'url' => $this->getUrl(),
71 ]));
72 }
73
74 /** inline {@inheritdoc} */
75 public function getProviderName()
76 {
77 return basename(str_replace('\\', '/', get_class($this)));
78 }
79
80 /** inline {@inheritdoc} */
81 public function getEndpoint()
82 {
83 return (string) $this->endpoint;
84 }
85
86 /** inline {@inheritdoc} */
87 public function getUrl($asString = true)
88 {
89 if ($asString) {
90 return $this->url->__toString();
91 }
92
93 return $this->url;
94 }
95
96 /** inline {@inheritdoc} */
97 public function hasHttpsSupport()
98 {
99 return (bool) $this->httpsSupport;
100 }
101
102 /** inline {@inheritdoc} */
103 public function hasResponsiveSupport()
104 {
105 return (bool) $this->responsiveSupport;
106 }
107
108 /** inline {@inheritdoc} */
109 public function modifyResponse(array $response = [])
110 {
111 return $response;
112 }
113
114 /** inline {@inheritdoc} */
115 public function getFakeResponse()
116 {
117 return array();
118 }
119
120 /** inline {@inheritdoc} */
121 public function normalizeUrl(Url $url)
122 {
123 return $url;
124 }
125
126 /** inline {@inheritdoc} */
127 public static function getHosts()
128 {
129 return static::$hosts;
130 }
131
132 /** inline {@inheritdoc} */
133 public static function addHost($host)
134 {
135 static::$hosts[] = $host;
136 }
137
138 /** inline {@inheritdoc} */
139 public function shouldSendRequest()
140 {
141 return (bool) $this->shouldSendRequest;
142 }
143 /** inline {@inheritdoc} */
144 public function getStaticResponse() {
145 return [];
146 }
147 }
148