1 | <?php |
||
20 | abstract class AbstractRequest |
||
21 | implements RequestInterface, InputInterface |
||
22 | { |
||
23 | /** |
||
24 | * Headers |
||
25 | * |
||
26 | * @var array |
||
27 | * @access protected |
||
28 | */ |
||
29 | protected $headers; |
||
30 | |||
31 | /** |
||
32 | * Settings |
||
33 | * |
||
34 | * @var array |
||
35 | * @access protected |
||
36 | */ |
||
37 | protected $settings; |
||
38 | |||
39 | /** |
||
40 | * Cookies |
||
41 | * |
||
42 | * @var array |
||
43 | * @access protected |
||
44 | */ |
||
45 | protected $cookies; |
||
46 | |||
47 | /** |
||
48 | * Request data |
||
49 | * |
||
50 | * @var array |
||
51 | * @access protected |
||
52 | */ |
||
53 | protected $data; |
||
54 | |||
55 | /** |
||
56 | * Request URL |
||
57 | * |
||
58 | * @var string |
||
59 | * @access protected |
||
60 | */ |
||
61 | protected $url; |
||
62 | |||
63 | /** |
||
64 | * Request method |
||
65 | * |
||
66 | * @var string |
||
67 | * @access protected |
||
68 | */ |
||
69 | protected $method; |
||
70 | |||
71 | /** |
||
72 | * Timeout period |
||
73 | * |
||
74 | * @var int |
||
75 | * @access protected |
||
76 | */ |
||
77 | protected $timeout; |
||
78 | |||
79 | /** |
||
80 | * Page load delay time. |
||
81 | * |
||
82 | * @var int |
||
83 | * @access protected |
||
84 | */ |
||
85 | protected $delay; |
||
86 | |||
87 | /** |
||
88 | * Viewport width. |
||
89 | * |
||
90 | * @var int |
||
91 | * @access protected |
||
92 | */ |
||
93 | protected $viewportWidth; |
||
94 | |||
95 | /** |
||
96 | * Viewport height. |
||
97 | * |
||
98 | * @var int |
||
99 | * @access protected |
||
100 | */ |
||
101 | protected $viewportHeight; |
||
102 | |||
103 | /** |
||
104 | * Body styles. |
||
105 | * |
||
106 | * @var array |
||
107 | * @access protected |
||
108 | */ |
||
109 | protected $bodyStyles; |
||
110 | |||
111 | 118 | /** |
|
112 | * Internal constructor |
||
113 | 118 | * |
|
114 | 118 | * @access public |
|
115 | 118 | * @param string $url (default: null) |
|
116 | 118 | * @param string $method (default: RequestInterface::METHOD_GET) |
|
117 | 118 | * @param int $timeout (default: 5000) |
|
118 | 118 | */ |
|
119 | 118 | public function __construct($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000) |
|
141 | |||
142 | 118 | /** |
|
143 | 3 | * Set request method |
|
144 | * |
||
145 | * @access public |
||
146 | 118 | * @param string $method |
|
147 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
148 | 118 | * @throws \JonnyW\PhantomJs\Exception\InvalidMethodException |
|
149 | */ |
||
150 | public function setMethod($method) |
||
163 | |||
164 | /** |
||
165 | * Get request method |
||
166 | * |
||
167 | * @access public |
||
168 | * @return string |
||
169 | 118 | */ |
|
170 | public function getMethod() |
||
174 | |||
175 | /** |
||
176 | * Set timeout period |
||
177 | * |
||
178 | * @access public |
||
179 | * @param int $timeout |
||
180 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
181 | */ |
||
182 | 8 | public function setTimeout($timeout) |
|
188 | |||
189 | /** |
||
190 | * Get timeout period |
||
191 | * |
||
192 | * @access public |
||
193 | * @return int |
||
194 | */ |
||
195 | public function getTimeout() |
||
203 | |||
204 | /** |
||
205 | * Set page load delay time (seconds). |
||
206 | * |
||
207 | * @access public |
||
208 | * @param int $delay |
||
209 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
210 | */ |
||
211 | 28 | public function setDelay($delay) |
|
217 | |||
218 | /** |
||
219 | * Get page load delay time (seconds). |
||
220 | * |
||
221 | * @access public |
||
222 | * @return int |
||
223 | */ |
||
224 | 8 | public function getDelay() |
|
228 | |||
229 | 8 | /** |
|
230 | * Set viewport size. |
||
231 | * |
||
232 | * @access public |
||
233 | * @param int $width |
||
234 | * @param int $height |
||
235 | * @return void |
||
236 | */ |
||
237 | public function setViewportSize($width, $height) |
||
244 | |||
245 | /** |
||
246 | * Get viewport width. |
||
247 | * |
||
248 | * @access public |
||
249 | 33 | * @return int |
|
250 | */ |
||
251 | 33 | public function getViewportWidth() |
|
255 | |||
256 | /** |
||
257 | * Get viewport height. |
||
258 | * |
||
259 | * @access public |
||
260 | * @return int |
||
261 | 54 | */ |
|
262 | public function getViewportHeight() |
||
266 | |||
267 | /** |
||
268 | * Set request URL |
||
269 | * |
||
270 | * @access public |
||
271 | * @param string $url |
||
272 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
273 | */ |
||
274 | public function setUrl($url) |
||
280 | |||
281 | /** |
||
282 | 43 | * Get request URL |
|
283 | * - Assembles query string for GET |
||
284 | 43 | * and HEAD requests |
|
285 | * |
||
286 | 10 | * @access public |
|
287 | 10 | * @return string |
|
288 | 10 | */ |
|
289 | public function getUrl() |
||
305 | |||
306 | 4 | /** |
|
307 | * Get content body |
||
308 | * - Returns query string if not GET or HEAD |
||
309 | * |
||
310 | * @access public |
||
311 | * @return string |
||
312 | */ |
||
313 | public function getBody() |
||
321 | |||
322 | /** |
||
323 | * Set request data |
||
324 | * |
||
325 | * @access public |
||
326 | * @param array $data |
||
327 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
328 | */ |
||
329 | public function setRequestData(array $data) |
||
335 | |||
336 | 3 | /** |
|
337 | * Get request data |
||
338 | * |
||
339 | * @access public |
||
340 | * @param boolean $flat |
||
341 | * @return array |
||
342 | */ |
||
343 | public function getRequestData($flat = true) |
||
351 | |||
352 | /** |
||
353 | * Set headers |
||
354 | * |
||
355 | * @access public |
||
356 | * @param array $headers |
||
357 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
358 | */ |
||
359 | 1 | public function setHeaders(array $headers) |
|
363 | 1 | ||
364 | /** |
||
365 | * Add single header |
||
366 | * |
||
367 | * @access public |
||
368 | * @param string $header |
||
369 | * @param string $value |
||
370 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
371 | */ |
||
372 | public function addHeader($header, $value) |
||
378 | |||
379 | /** |
||
380 | * Merge headers with existing |
||
381 | * |
||
382 | * @access public |
||
383 | * @param array $headers |
||
384 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
385 | */ |
||
386 | public function addHeaders(array $headers) |
||
392 | |||
393 | 36 | /** |
|
394 | * Get request headers |
||
395 | * |
||
396 | * @access public |
||
397 | * @param string $format |
||
398 | * @return array|string |
||
399 | */ |
||
400 | public function getHeaders($format = 'default') |
||
408 | 2 | ||
409 | /** |
||
410 | * Add single setting |
||
411 | * |
||
412 | * @access public |
||
413 | * @param string $setting |
||
414 | * @param string $value |
||
415 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
416 | */ |
||
417 | 32 | public function addSetting($setting, $value) |
|
423 | |||
424 | /** |
||
425 | * Get settings |
||
426 | * |
||
427 | * @access public |
||
428 | * @return array |
||
429 | 1 | */ |
|
430 | public function getSettings() |
||
434 | |||
435 | /** |
||
436 | * Add cookie. |
||
437 | * |
||
438 | * @access public |
||
439 | * @param string $name |
||
440 | * @param mixed $value |
||
441 | * @param string $path |
||
442 | * @param string $domain |
||
443 | 30 | * @param bool $httpOnly (default: true) |
|
444 | * @param bool $secure (default: false) |
||
445 | 30 | * @param int $expires (default: null) |
|
446 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
447 | */ |
||
448 | public function addCookie($name, $value, $path, $domain, $httpOnly = true, $secure = false, $expires = null) |
||
466 | 7 | ||
467 | /** |
||
468 | 7 | * Delete cookie. |
|
469 | * |
||
470 | 7 | * @access public |
|
471 | * @param string $name |
||
472 | 3 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
|
473 | 3 | */ |
|
474 | public function deleteCookie($name) |
||
480 | |||
481 | /** |
||
482 | * Get cookies |
||
483 | * |
||
484 | * @access public |
||
485 | * @return array |
||
486 | */ |
||
487 | public function getCookies() |
||
491 | |||
492 | /** |
||
493 | * Set body styles |
||
494 | * |
||
495 | * @access public |
||
496 | * @param array $styles |
||
497 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
498 | */ |
||
499 | public function setBodyStyles(array $styles) |
||
505 | |||
506 | /** |
||
507 | * Get body styles |
||
508 | * |
||
509 | * @access public |
||
510 | * @param string $format (default: 'default') |
||
511 | * @return array|string |
||
512 | */ |
||
513 | public function getBodyStyles($format = 'default') |
||
521 | |||
522 | /** |
||
523 | * Flatten data into single |
||
524 | * dimensional array |
||
525 | * |
||
526 | * @access protected |
||
527 | * @param array $data |
||
528 | * @param string $prefix |
||
529 | * @param string $format |
||
530 | * @return array |
||
531 | */ |
||
532 | protected function flattenData(array $data, $prefix = '', $format = '%s') |
||
551 | } |
||
552 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: