1 | <?php namespace Arcanedev\EmbedVideo\Parsers; |
||
13 | abstract class AbstractParser implements Parser |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Properties |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | /** |
||
20 | * The given URL to be parsed. |
||
21 | * |
||
22 | * @var string|null |
||
23 | */ |
||
24 | protected $url; |
||
25 | |||
26 | /** |
||
27 | * The parser's URL patterns. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $patterns = []; |
||
32 | |||
33 | /** |
||
34 | * The iframe attribute. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $attributes = []; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $cachedMatches; |
||
44 | |||
45 | /** |
||
46 | * Use a secure HTTP Protocol. |
||
47 | * |
||
48 | * @var bool |
||
49 | */ |
||
50 | protected $useSecure = true; |
||
51 | |||
52 | /** |
||
53 | * The HTTP Protocol. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $protocol = 'https'; |
||
58 | |||
59 | /** |
||
60 | * Timestamp pattern and param. |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $timestamp = [ |
||
65 | 'pattern' => null, |
||
66 | 'param' => null, |
||
67 | ]; |
||
68 | |||
69 | /** |
||
70 | * The URL Queries. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $queries = []; |
||
75 | |||
76 | /* ----------------------------------------------------------------- |
||
77 | | Constructor |
||
78 | | ----------------------------------------------------------------- |
||
79 | */ |
||
80 | /** |
||
81 | * AbstractParser constructor. |
||
82 | * |
||
83 | * @param array $options |
||
84 | */ |
||
85 | 30 | public function __construct(array $options) |
|
92 | |||
93 | /* ----------------------------------------------------------------- |
||
94 | | Getters & Setters |
||
95 | | ----------------------------------------------------------------- |
||
96 | */ |
||
97 | /** |
||
98 | * Get the URL. |
||
99 | * |
||
100 | * @return string|null |
||
101 | */ |
||
102 | 6 | public function url() |
|
106 | |||
107 | /** |
||
108 | * Set the URL. |
||
109 | * |
||
110 | * @param string $url |
||
111 | * |
||
112 | * @return self |
||
113 | */ |
||
114 | 24 | protected function setUrl($url) |
|
121 | |||
122 | /** |
||
123 | * Set the URL patterns. |
||
124 | * |
||
125 | * @param array $patterns |
||
126 | * |
||
127 | * @return self |
||
128 | */ |
||
129 | public function setPatterns(array $patterns) |
||
135 | |||
136 | /** |
||
137 | * Get the attributes. |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | 27 | public function attributes() |
|
145 | |||
146 | /** |
||
147 | * Set the attributes. |
||
148 | * |
||
149 | * @param array $attributes |
||
150 | * |
||
151 | * @return self |
||
152 | */ |
||
153 | 30 | public function setAttributes(array $attributes) |
|
159 | |||
160 | /** |
||
161 | * Get the URL queries. |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | 27 | public function queries() |
|
169 | |||
170 | /** |
||
171 | * Create an iframe entity. |
||
172 | * |
||
173 | * @return \Arcanedev\EmbedVideo\Entities\Iframe |
||
174 | */ |
||
175 | 21 | public function iframe() |
|
184 | |||
185 | /** |
||
186 | * Get value from cached matches. |
||
187 | * |
||
188 | * @param int $key |
||
189 | * @param mixed|null $default |
||
190 | * |
||
191 | * @return mixed |
||
192 | */ |
||
193 | 21 | public function getCached($key, $default = null) |
|
197 | |||
198 | /** |
||
199 | * Get the video id from cached matches. |
||
200 | * |
||
201 | * @return mixed |
||
202 | */ |
||
203 | abstract protected function videoId(); |
||
204 | |||
205 | /** |
||
206 | * Get the default URL queries. |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | abstract protected function defaultQueries(); |
||
211 | |||
212 | /** |
||
213 | * Get the iframe pattern. |
||
214 | * |
||
215 | * @return string |
||
216 | */ |
||
217 | abstract protected function getIframePattern(); |
||
218 | |||
219 | /** |
||
220 | * Get the iframe replace. |
||
221 | * |
||
222 | * @return array |
||
223 | */ |
||
224 | abstract protected function getIframeReplacer(); |
||
225 | |||
226 | /* ----------------------------------------------------------------- |
||
227 | | Main method |
||
228 | | ----------------------------------------------------------------- |
||
229 | */ |
||
230 | /** |
||
231 | * Parse the given url. |
||
232 | * |
||
233 | * @param string $url |
||
234 | * |
||
235 | * @return self |
||
236 | */ |
||
237 | 24 | public function parse($url) |
|
253 | |||
254 | /* ----------------------------------------------------------------- |
||
255 | | Other Methods |
||
256 | | ----------------------------------------------------------------- |
||
257 | */ |
||
258 | /** |
||
259 | * Parse the HTTP protocol. |
||
260 | * |
||
261 | * @throws \Exception |
||
262 | */ |
||
263 | 24 | private function parseProtocol() |
|
275 | |||
276 | /** |
||
277 | * Parse the timestamp. |
||
278 | */ |
||
279 | 24 | protected function parseTimestamp() |
|
293 | |||
294 | /** |
||
295 | * Check if the parser has a defined timestamp parsing. |
||
296 | * |
||
297 | * @return bool |
||
298 | */ |
||
299 | 24 | protected function hasTimestampOption() |
|
304 | |||
305 | /** |
||
306 | * Enable to perform custom parsing. |
||
307 | */ |
||
308 | 24 | protected function parseCustomParsing() |
|
312 | |||
313 | /** |
||
314 | * Reset the parser. |
||
315 | */ |
||
316 | 24 | private function reset() |
|
321 | } |
||
322 |