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 | * Request data |
||
41 | * |
||
42 | * @var array |
||
43 | * @access protected |
||
44 | */ |
||
45 | protected $data; |
||
46 | |||
47 | /** |
||
48 | * Request URL |
||
49 | * |
||
50 | * @var string |
||
51 | * @access protected |
||
52 | */ |
||
53 | protected $url; |
||
54 | |||
55 | /** |
||
56 | * Request method |
||
57 | * |
||
58 | * @var string |
||
59 | * @access protected |
||
60 | */ |
||
61 | protected $method; |
||
62 | |||
63 | /** |
||
64 | * Timeout period |
||
65 | * |
||
66 | * @var int |
||
67 | * @access protected |
||
68 | */ |
||
69 | protected $timeout; |
||
70 | |||
71 | /** |
||
72 | * Page load delay time. |
||
73 | * |
||
74 | * @var int |
||
75 | * @access protected |
||
76 | */ |
||
77 | protected $delay; |
||
78 | |||
79 | /** |
||
80 | * Viewport width. |
||
81 | * |
||
82 | * @var int |
||
83 | * @access protected |
||
84 | */ |
||
85 | protected $viewportWidth; |
||
86 | |||
87 | /** |
||
88 | * Viewport height. |
||
89 | * |
||
90 | * @var int |
||
91 | * @access protected |
||
92 | */ |
||
93 | protected $viewportHeight; |
||
94 | |||
95 | /** |
||
96 | * Body styles. |
||
97 | * |
||
98 | * @var array |
||
99 | * @access protected |
||
100 | */ |
||
101 | protected $bodyStyles; |
||
102 | |||
103 | /** |
||
104 | * Internal constructor |
||
105 | * |
||
106 | * @access public |
||
107 | * @param string $url (default: null) |
||
108 | * @param string $method (default: RequestInterface::METHOD_GET) |
||
109 | * @param int $timeout (default: 5000) |
||
110 | */ |
||
111 | 118 | public function __construct($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000) |
|
128 | |||
129 | /** |
||
130 | * Set request method |
||
131 | * |
||
132 | * @access public |
||
133 | * @param string $method |
||
134 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
135 | * @throws \JonnyW\PhantomJs\Exception\InvalidMethodException |
||
136 | */ |
||
137 | 118 | public function setMethod($method) |
|
150 | |||
151 | /** |
||
152 | * Get request method |
||
153 | * |
||
154 | * @access public |
||
155 | * @return string |
||
156 | */ |
||
157 | 61 | public function getMethod() |
|
161 | |||
162 | /** |
||
163 | * Set timeout period |
||
164 | * |
||
165 | * @access public |
||
166 | * @param int $timeout |
||
167 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
168 | */ |
||
169 | 118 | public function setTimeout($timeout) |
|
175 | |||
176 | /** |
||
177 | * Get timeout period |
||
178 | * |
||
179 | * @access public |
||
180 | * @return int |
||
181 | */ |
||
182 | 8 | public function getTimeout() |
|
190 | |||
191 | /** |
||
192 | * Set page load delay time (seconds). |
||
193 | * |
||
194 | * @access public |
||
195 | * @param int $delay |
||
196 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
197 | */ |
||
198 | 6 | public function setDelay($delay) |
|
204 | |||
205 | /** |
||
206 | * Get page load delay time (seconds). |
||
207 | * |
||
208 | * @access public |
||
209 | * @return int |
||
210 | */ |
||
211 | 28 | public function getDelay() |
|
215 | |||
216 | /** |
||
217 | * Set viewport size. |
||
218 | * |
||
219 | * @access public |
||
220 | * @param int $width |
||
221 | * @param int $height |
||
222 | * @return void |
||
223 | */ |
||
224 | 8 | public function setViewportSize($width, $height) |
|
231 | |||
232 | /** |
||
233 | * Get viewport width. |
||
234 | * |
||
235 | * @access public |
||
236 | * @return int |
||
237 | */ |
||
238 | 33 | public function getViewportWidth() |
|
242 | |||
243 | /** |
||
244 | * Get viewport height. |
||
245 | * |
||
246 | * @access public |
||
247 | * @return int |
||
248 | */ |
||
249 | 33 | public function getViewportHeight() |
|
253 | |||
254 | /** |
||
255 | * Set request URL |
||
256 | * |
||
257 | * @access public |
||
258 | * @param string $url |
||
259 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
260 | */ |
||
261 | 54 | public function setUrl($url) |
|
267 | |||
268 | /** |
||
269 | * Get request URL |
||
270 | * - Assembles query string for GET |
||
271 | * and HEAD requests |
||
272 | * |
||
273 | * @access public |
||
274 | * @return string |
||
275 | */ |
||
276 | 47 | public function getUrl() |
|
292 | |||
293 | /** |
||
294 | * Get content body |
||
295 | * - Returns query string if not GET or HEAD |
||
296 | * |
||
297 | * @access public |
||
298 | * @return string |
||
299 | */ |
||
300 | 39 | public function getBody() |
|
308 | |||
309 | /** |
||
310 | * Set request data |
||
311 | * |
||
312 | * @access public |
||
313 | * @param array $data |
||
314 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
315 | */ |
||
316 | 29 | public function setRequestData(array $data) |
|
322 | |||
323 | /** |
||
324 | * Get request data |
||
325 | * |
||
326 | * @access public |
||
327 | * @param boolean $flat |
||
328 | * @return array |
||
329 | */ |
||
330 | 10 | public function getRequestData($flat = true) |
|
338 | |||
339 | /** |
||
340 | * Set headers |
||
341 | * |
||
342 | * @access public |
||
343 | * @param array $headers |
||
344 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
345 | */ |
||
346 | 9 | public function setHeaders(array $headers) |
|
350 | |||
351 | /** |
||
352 | * Add single header |
||
353 | * |
||
354 | * @access public |
||
355 | * @param string $header |
||
356 | * @param string $value |
||
357 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
358 | */ |
||
359 | 1 | public function addHeader($header, $value) |
|
365 | |||
366 | /** |
||
367 | * Merge headers with existing |
||
368 | * |
||
369 | * @access public |
||
370 | * @param array $headers |
||
371 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
372 | */ |
||
373 | 3 | public function addHeaders(array $headers) |
|
379 | |||
380 | /** |
||
381 | * Get request headers |
||
382 | * |
||
383 | * @access public |
||
384 | * @param string $format |
||
385 | * @return array|string |
||
386 | */ |
||
387 | 40 | public function getHeaders($format = 'default') |
|
395 | |||
396 | /** |
||
397 | * Add single setting |
||
398 | * |
||
399 | * @access public |
||
400 | * @param string $setting |
||
401 | * @param string $value |
||
402 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
403 | */ |
||
404 | 2 | public function addSetting($setting, $value) |
|
410 | |||
411 | /** |
||
412 | * Get settings |
||
413 | * |
||
414 | * @access public |
||
415 | * @return array |
||
416 | */ |
||
417 | 32 | public function getSettings() |
|
421 | |||
422 | /** |
||
423 | * Set body styles |
||
424 | * |
||
425 | * @access public |
||
426 | * @param array $styles |
||
427 | * @return \JonnyW\PhantomJs\Http\AbstractRequest |
||
428 | */ |
||
429 | 1 | public function setBodyStyles(array $styles) |
|
435 | |||
436 | /** |
||
437 | * Get body styles |
||
438 | * |
||
439 | * @access public |
||
440 | * @param string $format (default: 'default') |
||
441 | * @return array|string |
||
442 | */ |
||
443 | 30 | public function getBodyStyles($format = 'default') |
|
451 | |||
452 | /** |
||
453 | * Flatten data into single |
||
454 | * dimensional array |
||
455 | * |
||
456 | * @access protected |
||
457 | * @param array $data |
||
458 | * @param string $prefix |
||
459 | * @param string $format |
||
460 | * @return array |
||
461 | */ |
||
462 | 7 | protected function flattenData(array $data, $prefix = '', $format = '%s') |
|
481 | } |
||
482 |
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: