@@ -39,42 +39,42 @@ discard block |
||
39 | 39 | const TYPE_PHONE = 'phone'; |
40 | 40 | const TYPE_URL = 'url'; |
41 | 41 | |
42 | - /** |
|
43 | - * The original URL that was passed to the constructor. |
|
44 | - * @var string |
|
45 | - */ |
|
42 | + /** |
|
43 | + * The original URL that was passed to the constructor. |
|
44 | + * @var string |
|
45 | + */ |
|
46 | 46 | protected $rawURL; |
47 | 47 | |
48 | - /** |
|
49 | - * @var array |
|
50 | - */ |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + */ |
|
51 | 51 | protected $info; |
52 | 52 | |
53 | - /** |
|
54 | - * @var string[] |
|
55 | - */ |
|
53 | + /** |
|
54 | + * @var string[] |
|
55 | + */ |
|
56 | 56 | protected $excludedParams = array(); |
57 | 57 | |
58 | - /** |
|
59 | - * @var bool |
|
60 | - * @see URLInfo::setParamExclusion() |
|
61 | - */ |
|
58 | + /** |
|
59 | + * @var bool |
|
60 | + * @see URLInfo::setParamExclusion() |
|
61 | + */ |
|
62 | 62 | protected $paramExclusion = false; |
63 | 63 | |
64 | - /** |
|
65 | - * @var array |
|
66 | - * @see URLInfo::getTypeLabel() |
|
67 | - */ |
|
64 | + /** |
|
65 | + * @var array |
|
66 | + * @see URLInfo::getTypeLabel() |
|
67 | + */ |
|
68 | 68 | protected static $typeLabels; |
69 | 69 | |
70 | - /** |
|
71 | - * @var bool |
|
72 | - */ |
|
70 | + /** |
|
71 | + * @var bool |
|
72 | + */ |
|
73 | 73 | protected $highlightExcluded = false; |
74 | 74 | |
75 | - /** |
|
76 | - * @var array |
|
77 | - */ |
|
75 | + /** |
|
76 | + * @var array |
|
77 | + */ |
|
78 | 78 | protected $infoKeys = array( |
79 | 79 | 'scheme', |
80 | 80 | 'host', |
@@ -86,19 +86,19 @@ discard block |
||
86 | 86 | 'fragment' |
87 | 87 | ); |
88 | 88 | |
89 | - /** |
|
90 | - * @var string |
|
91 | - */ |
|
89 | + /** |
|
90 | + * @var string |
|
91 | + */ |
|
92 | 92 | protected $url; |
93 | 93 | |
94 | - /** |
|
95 | - * @var URLInfo_Parser |
|
96 | - */ |
|
94 | + /** |
|
95 | + * @var URLInfo_Parser |
|
96 | + */ |
|
97 | 97 | protected $parser; |
98 | 98 | |
99 | - /** |
|
100 | - * @var URLInfo_Normalizer |
|
101 | - */ |
|
99 | + /** |
|
100 | + * @var URLInfo_Normalizer |
|
101 | + */ |
|
102 | 102 | protected $normalizer; |
103 | 103 | |
104 | 104 | public function __construct(string $url) |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | $this->info = $this->parser->getInfo(); |
111 | 111 | } |
112 | 112 | |
113 | - /** |
|
114 | - * Filters an URL: removes control characters and the |
|
115 | - * like to have a clean URL to work with. |
|
116 | - * |
|
117 | - * @param string $url |
|
118 | - * @return string |
|
119 | - */ |
|
113 | + /** |
|
114 | + * Filters an URL: removes control characters and the |
|
115 | + * like to have a clean URL to work with. |
|
116 | + * |
|
117 | + * @param string $url |
|
118 | + * @return string |
|
119 | + */ |
|
120 | 120 | public static function filterURL(string $url) |
121 | 121 | { |
122 | 122 | return URLInfo_Filter::filter($url); |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | return $this->info['type'] === self::TYPE_PHONE; |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
150 | - * Whether the URL is a regular URL, not one of the |
|
151 | - * other types like a phone number or email address. |
|
152 | - * |
|
153 | - * @return bool |
|
154 | - */ |
|
149 | + /** |
|
150 | + * Whether the URL is a regular URL, not one of the |
|
151 | + * other types like a phone number or email address. |
|
152 | + * |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | 155 | public function isURL() : bool |
156 | 156 | { |
157 | 157 | $host = $this->getHost(); |
@@ -163,20 +163,20 @@ discard block |
||
163 | 163 | return $this->parser->isValid(); |
164 | 164 | } |
165 | 165 | |
166 | - /** |
|
167 | - * Retrieves the host name, or an empty string if none is present. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
166 | + /** |
|
167 | + * Retrieves the host name, or an empty string if none is present. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | 171 | public function getHost() : string |
172 | 172 | { |
173 | 173 | return $this->getInfoKey('host'); |
174 | 174 | } |
175 | 175 | |
176 | - /** |
|
177 | - * Retrieves the path, or an empty string if none is present. |
|
178 | - * @return string |
|
179 | - */ |
|
176 | + /** |
|
177 | + * Retrieves the path, or an empty string if none is present. |
|
178 | + * @return string |
|
179 | + */ |
|
180 | 180 | public function getPath() : string |
181 | 181 | { |
182 | 182 | return $this->getInfoKey('path'); |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | return $this->getInfoKey('scheme'); |
193 | 193 | } |
194 | 194 | |
195 | - /** |
|
196 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
197 | - * @return int |
|
198 | - */ |
|
195 | + /** |
|
196 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
197 | + * @return int |
|
198 | + */ |
|
199 | 199 | public function getPort() : int |
200 | 200 | { |
201 | 201 | $port = $this->getInfoKey('port'); |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | return -1; |
208 | 208 | } |
209 | 209 | |
210 | - /** |
|
211 | - * Retrieves the raw query string, or an empty string if none is present. |
|
212 | - * |
|
213 | - * @return string |
|
214 | - * |
|
215 | - * @see URLInfo::getParams() |
|
216 | - */ |
|
210 | + /** |
|
211 | + * Retrieves the raw query string, or an empty string if none is present. |
|
212 | + * |
|
213 | + * @return string |
|
214 | + * |
|
215 | + * @see URLInfo::getParams() |
|
216 | + */ |
|
217 | 217 | public function getQuery() : string |
218 | 218 | { |
219 | 219 | return $this->getInfoKey('query'); |
@@ -229,20 +229,20 @@ discard block |
||
229 | 229 | return $this->getInfoKey('pass'); |
230 | 230 | } |
231 | 231 | |
232 | - /** |
|
233 | - * Whether the URL contains a port number. |
|
234 | - * @return bool |
|
235 | - */ |
|
232 | + /** |
|
233 | + * Whether the URL contains a port number. |
|
234 | + * @return bool |
|
235 | + */ |
|
236 | 236 | public function hasPort() : bool |
237 | 237 | { |
238 | 238 | return $this->getPort() !== -1; |
239 | 239 | } |
240 | 240 | |
241 | - /** |
|
242 | - * Alias for the hasParams() method. |
|
243 | - * @return bool |
|
244 | - * @see URLInfo::hasParams() |
|
245 | - */ |
|
241 | + /** |
|
242 | + * Alias for the hasParams() method. |
|
243 | + * @return bool |
|
244 | + * @see URLInfo::hasParams() |
|
245 | + */ |
|
246 | 246 | public function hasQuery() : bool |
247 | 247 | { |
248 | 248 | return $this->hasParams(); |
@@ -314,25 +314,25 @@ discard block |
||
314 | 314 | return $this->normalizer->normalize(); |
315 | 315 | } |
316 | 316 | |
317 | - /** |
|
318 | - * Creates a hash of the URL, which can be used for comparisons. |
|
319 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
320 | - * the same links with a different parameter order will have the |
|
321 | - * same hash. |
|
322 | - * |
|
323 | - * @return string |
|
324 | - */ |
|
317 | + /** |
|
318 | + * Creates a hash of the URL, which can be used for comparisons. |
|
319 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
320 | + * the same links with a different parameter order will have the |
|
321 | + * same hash. |
|
322 | + * |
|
323 | + * @return string |
|
324 | + */ |
|
325 | 325 | public function getHash() |
326 | 326 | { |
327 | 327 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
328 | 328 | } |
329 | 329 | |
330 | - /** |
|
331 | - * Highlights the URL using HTML tags with specific highlighting |
|
332 | - * class names. |
|
333 | - * |
|
334 | - * @return string Will return an empty string if the URL is not valid. |
|
335 | - */ |
|
330 | + /** |
|
331 | + * Highlights the URL using HTML tags with specific highlighting |
|
332 | + * class names. |
|
333 | + * |
|
334 | + * @return string Will return an empty string if the URL is not valid. |
|
335 | + */ |
|
336 | 336 | public function getHighlighted() : string |
337 | 337 | { |
338 | 338 | if(!$this->isValid()) { |
@@ -366,15 +366,15 @@ discard block |
||
366 | 366 | return count($params); |
367 | 367 | } |
368 | 368 | |
369 | - /** |
|
370 | - * Retrieves all parameters specified in the url, |
|
371 | - * if any, as an associative array. |
|
372 | - * |
|
373 | - * NOTE: Ignores parameters that have been added |
|
374 | - * to the excluded parameters list. |
|
375 | - * |
|
376 | - * @return array |
|
377 | - */ |
|
369 | + /** |
|
370 | + * Retrieves all parameters specified in the url, |
|
371 | + * if any, as an associative array. |
|
372 | + * |
|
373 | + * NOTE: Ignores parameters that have been added |
|
374 | + * to the excluded parameters list. |
|
375 | + * |
|
376 | + * @return array |
|
377 | + */ |
|
378 | 378 | public function getParams() : array |
379 | 379 | { |
380 | 380 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -392,22 +392,22 @@ discard block |
||
392 | 392 | return $keep; |
393 | 393 | } |
394 | 394 | |
395 | - /** |
|
396 | - * Retrieves the names of all parameters present in the URL, if any. |
|
397 | - * @return string[] |
|
398 | - */ |
|
395 | + /** |
|
396 | + * Retrieves the names of all parameters present in the URL, if any. |
|
397 | + * @return string[] |
|
398 | + */ |
|
399 | 399 | public function getParamNames() : array |
400 | 400 | { |
401 | 401 | $params = $this->getParams(); |
402 | 402 | return array_keys($params); |
403 | 403 | } |
404 | 404 | |
405 | - /** |
|
406 | - * Retrieves a specific parameter value from the URL. |
|
407 | - * |
|
408 | - * @param string $name |
|
409 | - * @return string The parameter value, or an empty string if it does not exist. |
|
410 | - */ |
|
405 | + /** |
|
406 | + * Retrieves a specific parameter value from the URL. |
|
407 | + * |
|
408 | + * @param string $name |
|
409 | + * @return string The parameter value, or an empty string if it does not exist. |
|
410 | + */ |
|
411 | 411 | public function getParam(string $name) : string |
412 | 412 | { |
413 | 413 | if(isset($this->info['params'][$name])) { |
@@ -417,16 +417,16 @@ discard block |
||
417 | 417 | return ''; |
418 | 418 | } |
419 | 419 | |
420 | - /** |
|
421 | - * Excludes an URL parameter entirely if present: |
|
422 | - * the parser will act as if the parameter was not |
|
423 | - * even present in the source URL, effectively |
|
424 | - * stripping it. |
|
425 | - * |
|
426 | - * @param string $name |
|
427 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
428 | - * @return URLInfo |
|
429 | - */ |
|
420 | + /** |
|
421 | + * Excludes an URL parameter entirely if present: |
|
422 | + * the parser will act as if the parameter was not |
|
423 | + * even present in the source URL, effectively |
|
424 | + * stripping it. |
|
425 | + * |
|
426 | + * @param string $name |
|
427 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
428 | + * @return URLInfo |
|
429 | + */ |
|
430 | 430 | public function excludeParam(string $name, string $reason) : URLInfo |
431 | 431 | { |
432 | 432 | if(!isset($this->excludedParams[$name])) |
@@ -479,25 +479,25 @@ discard block |
||
479 | 479 | return self::$typeLabels[$this->getType()]; |
480 | 480 | } |
481 | 481 | |
482 | - /** |
|
483 | - * Whether excluded parameters should be highlighted in |
|
484 | - * a different color in the URL when using the |
|
485 | - * {@link URLInfo::getHighlighted()} method. |
|
486 | - * |
|
487 | - * @param bool $highlight |
|
488 | - * @return URLInfo |
|
489 | - */ |
|
482 | + /** |
|
483 | + * Whether excluded parameters should be highlighted in |
|
484 | + * a different color in the URL when using the |
|
485 | + * {@link URLInfo::getHighlighted()} method. |
|
486 | + * |
|
487 | + * @param bool $highlight |
|
488 | + * @return URLInfo |
|
489 | + */ |
|
490 | 490 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
491 | 491 | { |
492 | 492 | $this->highlightExcluded = $highlight; |
493 | 493 | return $this; |
494 | 494 | } |
495 | 495 | |
496 | - /** |
|
497 | - * Returns an array with all relevant URL information. |
|
498 | - * |
|
499 | - * @return array |
|
500 | - */ |
|
496 | + /** |
|
497 | + * Returns an array with all relevant URL information. |
|
498 | + * |
|
499 | + * @return array |
|
500 | + */ |
|
501 | 501 | public function toArray() : array |
502 | 502 | { |
503 | 503 | return array( |
@@ -541,24 +541,24 @@ discard block |
||
541 | 541 | return $this; |
542 | 542 | } |
543 | 543 | |
544 | - /** |
|
545 | - * Whether the parameter exclusion mode is enabled: |
|
546 | - * In this case, if any parameters have been added to the |
|
547 | - * exclusion list, all relevant methods will exclude these. |
|
548 | - * |
|
549 | - * @return bool |
|
550 | - */ |
|
544 | + /** |
|
545 | + * Whether the parameter exclusion mode is enabled: |
|
546 | + * In this case, if any parameters have been added to the |
|
547 | + * exclusion list, all relevant methods will exclude these. |
|
548 | + * |
|
549 | + * @return bool |
|
550 | + */ |
|
551 | 551 | public function isParamExclusionEnabled() : bool |
552 | 552 | { |
553 | 553 | return $this->paramExclusion; |
554 | 554 | } |
555 | 555 | |
556 | - /** |
|
557 | - * Checks whether the link contains any parameters that |
|
558 | - * are on the list of excluded parameters. |
|
559 | - * |
|
560 | - * @return bool |
|
561 | - */ |
|
556 | + /** |
|
557 | + * Checks whether the link contains any parameters that |
|
558 | + * are on the list of excluded parameters. |
|
559 | + * |
|
560 | + * @return bool |
|
561 | + */ |
|
562 | 562 | public function containsExcludedParams() : bool |
563 | 563 | { |
564 | 564 | if(empty($this->excludedParams)) { |
@@ -626,16 +626,16 @@ discard block |
||
626 | 626 | return $this->highlightExcluded; |
627 | 627 | } |
628 | 628 | |
629 | - /** |
|
630 | - * Checks if the URL exists, i.e. can be connected to. Will return |
|
631 | - * true if the returned HTTP status code is `200` or `302`. |
|
632 | - * |
|
633 | - * NOTE: If the target URL requires HTTP authentication, the username |
|
634 | - * and password should be integrated into the URL. |
|
635 | - * |
|
636 | - * @return bool |
|
637 | - * @throws BaseException |
|
638 | - */ |
|
629 | + /** |
|
630 | + * Checks if the URL exists, i.e. can be connected to. Will return |
|
631 | + * true if the returned HTTP status code is `200` or `302`. |
|
632 | + * |
|
633 | + * NOTE: If the target URL requires HTTP authentication, the username |
|
634 | + * and password should be integrated into the URL. |
|
635 | + * |
|
636 | + * @return bool |
|
637 | + * @throws BaseException |
|
638 | + */ |
|
639 | 639 | public function tryConnect(bool $verifySSL=true) : bool |
640 | 640 | { |
641 | 641 | requireCURL(); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | { |
201 | 201 | $port = $this->getInfoKey('port'); |
202 | 202 | |
203 | - if(!empty($port)) { |
|
203 | + if (!empty($port)) { |
|
204 | 204 | return (int)$port; |
205 | 205 | } |
206 | 206 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | |
281 | 281 | protected function getInfoKey(string $name) : string |
282 | 282 | { |
283 | - if(isset($this->info[$name])) { |
|
283 | + if (isset($this->info[$name])) { |
|
284 | 284 | return (string)$this->info[$name]; |
285 | 285 | } |
286 | 286 | |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | |
290 | 290 | public function getNormalized() : string |
291 | 291 | { |
292 | - if(!$this->isValid()) { |
|
292 | + if (!$this->isValid()) { |
|
293 | 293 | return ''; |
294 | 294 | } |
295 | 295 | |
296 | - if(!isset($this->normalizer)) { |
|
296 | + if (!isset($this->normalizer)) { |
|
297 | 297 | $this->normalizer = new URLInfo_Normalizer($this); |
298 | 298 | } |
299 | 299 | |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | |
303 | 303 | public function getNormalizedWithoutAuth() : string |
304 | 304 | { |
305 | - if(!$this->isValid()) { |
|
305 | + if (!$this->isValid()) { |
|
306 | 306 | return ''; |
307 | 307 | } |
308 | 308 | |
309 | - if(!isset($this->normalizer)) { |
|
309 | + if (!isset($this->normalizer)) { |
|
310 | 310 | $this->normalizer = new URLInfo_Normalizer($this); |
311 | 311 | $this->normalizer->disableAuth(); |
312 | 312 | } |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function getHighlighted() : string |
337 | 337 | { |
338 | - if(!$this->isValid()) { |
|
338 | + if (!$this->isValid()) { |
|
339 | 339 | return ''; |
340 | 340 | } |
341 | 341 | |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function getParams() : array |
379 | 379 | { |
380 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
380 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
381 | 381 | return $this->info['params']; |
382 | 382 | } |
383 | 383 | |
384 | 384 | $keep = array(); |
385 | - foreach($this->info['params'] as $name => $value) |
|
385 | + foreach ($this->info['params'] as $name => $value) |
|
386 | 386 | { |
387 | - if(!isset($this->excludedParams[$name])) { |
|
387 | + if (!isset($this->excludedParams[$name])) { |
|
388 | 388 | $keep[$name] = $value; |
389 | 389 | } |
390 | 390 | } |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | */ |
411 | 411 | public function getParam(string $name) : string |
412 | 412 | { |
413 | - if(isset($this->info['params'][$name])) { |
|
413 | + if (isset($this->info['params'][$name])) { |
|
414 | 414 | return $this->info['params'][$name]; |
415 | 415 | } |
416 | 416 | |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | */ |
430 | 430 | public function excludeParam(string $name, string $reason) : URLInfo |
431 | 431 | { |
432 | - if(!isset($this->excludedParams[$name])) |
|
432 | + if (!isset($this->excludedParams[$name])) |
|
433 | 433 | { |
434 | 434 | $this->excludedParams[$name] = $reason; |
435 | 435 | $this->setParamExclusion(); |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | |
456 | 456 | public function getTypeLabel() : string |
457 | 457 | { |
458 | - if(!isset(self::$typeLabels)) |
|
458 | + if (!isset(self::$typeLabels)) |
|
459 | 459 | { |
460 | 460 | self::$typeLabels = array( |
461 | 461 | self::TYPE_EMAIL => t('Email'), |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | |
468 | 468 | $type = $this->getType(); |
469 | 469 | |
470 | - if(!isset(self::$typeLabels[$type])) |
|
470 | + if (!isset(self::$typeLabels[$type])) |
|
471 | 471 | { |
472 | 472 | throw new BaseException( |
473 | 473 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @param bool $highlight |
488 | 488 | * @return URLInfo |
489 | 489 | */ |
490 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
490 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
491 | 491 | { |
492 | 492 | $this->highlightExcluded = $highlight; |
493 | 493 | return $this; |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * @see URLInfo::isParamExclusionEnabled() |
536 | 536 | * @see URLInfo::setHighlightExcluded() |
537 | 537 | */ |
538 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
538 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
539 | 539 | { |
540 | 540 | $this->paramExclusion = $enabled; |
541 | 541 | return $this; |
@@ -561,13 +561,13 @@ discard block |
||
561 | 561 | */ |
562 | 562 | public function containsExcludedParams() : bool |
563 | 563 | { |
564 | - if(empty($this->excludedParams)) { |
|
564 | + if (empty($this->excludedParams)) { |
|
565 | 565 | return false; |
566 | 566 | } |
567 | 567 | |
568 | 568 | $names = array_keys($this->info['params']); |
569 | - foreach($names as $name) { |
|
570 | - if(isset($this->excludedParams[$name])) { |
|
569 | + foreach ($names as $name) { |
|
570 | + if (isset($this->excludedParams[$name])) { |
|
571 | 571 | return true; |
572 | 572 | } |
573 | 573 | } |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | |
584 | 584 | public function offsetSet($offset, $value) |
585 | 585 | { |
586 | - if(in_array($offset, $this->infoKeys)) { |
|
586 | + if (in_array($offset, $this->infoKeys)) { |
|
587 | 587 | $this->info[$offset] = $value; |
588 | 588 | } |
589 | 589 | } |
@@ -600,11 +600,11 @@ discard block |
||
600 | 600 | |
601 | 601 | public function offsetGet($offset) |
602 | 602 | { |
603 | - if($offset === 'port') { |
|
603 | + if ($offset === 'port') { |
|
604 | 604 | return $this->getPort(); |
605 | 605 | } |
606 | 606 | |
607 | - if(in_array($offset, $this->infoKeys)) { |
|
607 | + if (in_array($offset, $this->infoKeys)) { |
|
608 | 608 | return $this->getInfoKey($offset); |
609 | 609 | } |
610 | 610 | |
@@ -636,12 +636,12 @@ discard block |
||
636 | 636 | * @return bool |
637 | 637 | * @throws BaseException |
638 | 638 | */ |
639 | - public function tryConnect(bool $verifySSL=true) : bool |
|
639 | + public function tryConnect(bool $verifySSL = true) : bool |
|
640 | 640 | { |
641 | 641 | requireCURL(); |
642 | 642 | |
643 | 643 | $ch = curl_init(); |
644 | - if($ch === false) |
|
644 | + if ($ch === false) |
|
645 | 645 | { |
646 | 646 | throw new BaseException( |
647 | 647 | 'Could not initialize a new cURL instance.', |
@@ -657,13 +657,13 @@ discard block |
||
657 | 657 | curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
658 | 658 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
659 | 659 | |
660 | - if(!$verifySSL) |
|
660 | + if (!$verifySSL) |
|
661 | 661 | { |
662 | 662 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
663 | 663 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
664 | 664 | } |
665 | 665 | |
666 | - if($this->hasUsername()) |
|
666 | + if ($this->hasUsername()) |
|
667 | 667 | { |
668 | 668 | curl_setopt($ch, CURLOPT_USERNAME, $this->getUsername()); |
669 | 669 | curl_setopt($ch, CURLOPT_PASSWORD, $this->getPassword()); |
@@ -64,26 +64,26 @@ |
||
64 | 64 | { |
65 | 65 | $normalized = $this->info->getScheme().'://'; |
66 | 66 | |
67 | - if($this->info->hasUsername() && $this->auth) { |
|
67 | + if ($this->info->hasUsername() && $this->auth) { |
|
68 | 68 | $normalized .= urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $normalized .= $this->info->getHost(); |
72 | 72 | |
73 | - if($this->info->hasPort()) { |
|
73 | + if ($this->info->hasPort()) { |
|
74 | 74 | $normalized .= ':'.$this->info->getPort(); |
75 | 75 | } |
76 | 76 | |
77 | - if($this->info->hasPath()) { |
|
77 | + if ($this->info->hasPath()) { |
|
78 | 78 | $normalized .= $this->info->getPath(); |
79 | 79 | } |
80 | 80 | |
81 | 81 | $params = $this->info->getParams(); |
82 | - if(!empty($params)) { |
|
82 | + if (!empty($params)) { |
|
83 | 83 | $normalized .= '?'.http_build_query($params); |
84 | 84 | } |
85 | 85 | |
86 | - if($this->info->hasFragment()) { |
|
86 | + if ($this->info->hasFragment()) { |
|
87 | 87 | $normalized .= '#'.$this->info->getFragment(); |
88 | 88 | } |
89 | 89 |
@@ -21,35 +21,35 @@ discard block |
||
21 | 21 | { |
22 | 22 | protected $request; |
23 | 23 | |
24 | - /** |
|
25 | - * @var string |
|
26 | - */ |
|
24 | + /** |
|
25 | + * @var string |
|
26 | + */ |
|
27 | 27 | protected $body = ''; |
28 | 28 | |
29 | - /** |
|
30 | - * @var array |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var array |
|
31 | + */ |
|
32 | 32 | protected $info; |
33 | 33 | |
34 | - /** |
|
35 | - * @var bool |
|
36 | - */ |
|
34 | + /** |
|
35 | + * @var bool |
|
36 | + */ |
|
37 | 37 | protected $isError = false; |
38 | 38 | |
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | 42 | protected $errorMessage = ''; |
43 | 43 | |
44 | - /** |
|
45 | - * @var integer |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var integer |
|
46 | + */ |
|
47 | 47 | protected $errorCode = 0; |
48 | 48 | |
49 | - /** |
|
50 | - * @param RequestHelper $helper |
|
51 | - * @param array $info The CURL info array from curl_getinfo(). |
|
52 | - */ |
|
49 | + /** |
|
50 | + * @param RequestHelper $helper |
|
51 | + * @param array $info The CURL info array from curl_getinfo(). |
|
52 | + */ |
|
53 | 53 | public function __construct(RequestHelper $helper, array $info) |
54 | 54 | { |
55 | 55 | $this->request = $helper; |
@@ -71,70 +71,70 @@ discard block |
||
71 | 71 | return $this; |
72 | 72 | } |
73 | 73 | |
74 | - /** |
|
75 | - * Whether an error occurred in the request. |
|
76 | - * @return bool |
|
77 | - */ |
|
74 | + /** |
|
75 | + * Whether an error occurred in the request. |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | 78 | public function isError() : bool |
79 | 79 | { |
80 | 80 | return $this->isError; |
81 | 81 | } |
82 | 82 | |
83 | - /** |
|
84 | - * Retrieves the native error message, if an error occurred. |
|
85 | - * @return string |
|
86 | - */ |
|
83 | + /** |
|
84 | + * Retrieves the native error message, if an error occurred. |
|
85 | + * @return string |
|
86 | + */ |
|
87 | 87 | public function getErrorMessage() : string |
88 | 88 | { |
89 | 89 | return $this->errorMessage; |
90 | 90 | } |
91 | 91 | |
92 | - /** |
|
93 | - * Retrieves the native error code, if an error occurred. |
|
94 | - * @return int |
|
95 | - */ |
|
92 | + /** |
|
93 | + * Retrieves the native error code, if an error occurred. |
|
94 | + * @return int |
|
95 | + */ |
|
96 | 96 | public function getErrorCode() : int |
97 | 97 | { |
98 | 98 | return $this->errorCode; |
99 | 99 | } |
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * Retrieves the full body of the request. |
|
104 | - * |
|
105 | - * @return string |
|
106 | - */ |
|
102 | + /** |
|
103 | + * Retrieves the full body of the request. |
|
104 | + * |
|
105 | + * @return string |
|
106 | + */ |
|
107 | 107 | public function getRequestBody() : string |
108 | 108 | { |
109 | 109 | return $this->request->getBody(); |
110 | 110 | } |
111 | 111 | |
112 | - /** |
|
113 | - * Retrieves the body of the response, if any. |
|
114 | - * |
|
115 | - * @return string |
|
116 | - */ |
|
112 | + /** |
|
113 | + * Retrieves the body of the response, if any. |
|
114 | + * |
|
115 | + * @return string |
|
116 | + */ |
|
117 | 117 | public function getResponseBody() : string |
118 | 118 | { |
119 | 119 | return $this->body; |
120 | 120 | } |
121 | 121 | |
122 | - /** |
|
123 | - * The response HTTP code. |
|
124 | - * |
|
125 | - * @return int The code, or 0 if none was sent (on error). |
|
126 | - */ |
|
122 | + /** |
|
123 | + * The response HTTP code. |
|
124 | + * |
|
125 | + * @return int The code, or 0 if none was sent (on error). |
|
126 | + */ |
|
127 | 127 | public function getCode() : int |
128 | 128 | { |
129 | 129 | return intval($this->getInfoKey('http_code')); |
130 | 130 | } |
131 | 131 | |
132 | - /** |
|
133 | - * Retrieves the actual headers that were sent in the request: |
|
134 | - * one header by entry in the indexed array. |
|
135 | - * |
|
136 | - * @return array |
|
137 | - */ |
|
132 | + /** |
|
133 | + * Retrieves the actual headers that were sent in the request: |
|
134 | + * one header by entry in the indexed array. |
|
135 | + * |
|
136 | + * @return array |
|
137 | + */ |
|
138 | 138 | public function getHeaders() : array |
139 | 139 | { |
140 | 140 | return ConvertHelper::explodeTrim("\n", $this->getInfoKey('request_header')); |
@@ -142,7 +142,7 @@ |
||
142 | 142 | |
143 | 143 | protected function getInfoKey(string $name) : string |
144 | 144 | { |
145 | - if(isset($this->info[$name])) { |
|
145 | + if (isset($this->info[$name])) { |
|
146 | 146 | return (string)$this->info[$name]; |
147 | 147 | } |
148 | 148 |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class RequestHelper_Exception extends BaseException |
24 | 24 | { |
25 | - /** |
|
26 | - * @var RequestHelper_Response|NULL |
|
27 | - */ |
|
25 | + /** |
|
26 | + * @var RequestHelper_Response|NULL |
|
27 | + */ |
|
28 | 28 | protected $response = null; |
29 | 29 | |
30 | 30 | public function setResponse(RequestHelper_Response $response) |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | $this->response = $response; |
33 | 33 | } |
34 | 34 | |
35 | - /** |
|
36 | - * Retrieves the related response instance, if available. |
|
37 | - * |
|
38 | - * @return RequestHelper_Response|NULL |
|
39 | - */ |
|
35 | + /** |
|
36 | + * Retrieves the related response instance, if available. |
|
37 | + * |
|
38 | + * @return RequestHelper_Response|NULL |
|
39 | + */ |
|
40 | 40 | public function getResponse() : ?RequestHelper_Response |
41 | 41 | { |
42 | 42 | return $this->response; |
@@ -19,29 +19,29 @@ |
||
19 | 19 | */ |
20 | 20 | class RequestHelper_Boundaries_Boundary |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | 25 | protected $content; |
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | 30 | protected $dispositionParams = array(); |
31 | 31 | |
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | 35 | protected $contentType = ''; |
36 | 36 | |
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | 40 | protected $contentEncoding = ''; |
41 | 41 | |
42 | - /** |
|
43 | - * @var RequestHelper_Boundaries |
|
44 | - */ |
|
42 | + /** |
|
43 | + * @var RequestHelper_Boundaries |
|
44 | + */ |
|
45 | 45 | protected $boundaries; |
46 | 46 | |
47 | 47 | public function __construct(RequestHelper_Boundaries $boundaries, string $content) |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $lines[] = '--'.$this->boundaries->getMimeBoundary(); |
92 | 92 | $lines[] = $this->renderContentDisposition(); |
93 | 93 | |
94 | - if(!empty($this->contentType)) { |
|
94 | + if (!empty($this->contentType)) { |
|
95 | 95 | $lines[] = $this->renderContentType(); |
96 | 96 | } |
97 | 97 | |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | { |
106 | 106 | $result = 'Content-Disposition: form-data'; |
107 | 107 | |
108 | - foreach($this->dispositionParams as $name => $value) |
|
108 | + foreach ($this->dispositionParams as $name => $value) |
|
109 | 109 | { |
110 | - $result .= '; '.$name.'="' . $value . '"'; |
|
110 | + $result .= '; '.$name.'="'.$value.'"'; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return $result; |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | |
116 | 116 | protected function renderContentType() : string |
117 | 117 | { |
118 | - $result = 'Content-Type: ' . $this->contentType; |
|
118 | + $result = 'Content-Type: '.$this->contentType; |
|
119 | 119 | |
120 | - if(!empty($this->contentEncoding)) |
|
120 | + if (!empty($this->contentEncoding)) |
|
121 | 121 | { |
122 | - $result .= '; charset=' . $this->contentEncoding; |
|
122 | + $result .= '; charset='.$this->contentEncoding; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | return $result; |
@@ -20,19 +20,19 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class RequestHelper_Boundaries |
22 | 22 | { |
23 | - /** |
|
24 | - * @var RequestHelper |
|
25 | - */ |
|
23 | + /** |
|
24 | + * @var RequestHelper |
|
25 | + */ |
|
26 | 26 | protected $helper; |
27 | 27 | |
28 | - /** |
|
29 | - * @var RequestHelper_Boundaries_Boundary[] |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var RequestHelper_Boundaries_Boundary[] |
|
30 | + */ |
|
31 | 31 | protected $boundaries = array(); |
32 | 32 | |
33 | - /** |
|
34 | - * @var integer |
|
35 | - */ |
|
33 | + /** |
|
34 | + * @var integer |
|
35 | + */ |
|
36 | 36 | protected $contentLength = 0; |
37 | 37 | |
38 | 38 | public function __construct(RequestHelper $helper) |
@@ -50,24 +50,24 @@ discard block |
||
50 | 50 | return $this->helper->getEOL(); |
51 | 51 | } |
52 | 52 | |
53 | - /** |
|
54 | - * Retrieves the total content length of all boundaries. |
|
55 | - * @return int |
|
56 | - */ |
|
53 | + /** |
|
54 | + * Retrieves the total content length of all boundaries. |
|
55 | + * @return int |
|
56 | + */ |
|
57 | 57 | public function getContentLength() : int |
58 | 58 | { |
59 | 59 | return $this->contentLength; |
60 | 60 | } |
61 | 61 | |
62 | - /** |
|
63 | - * Adds a file to be sent with the request. |
|
64 | - * |
|
65 | - * @param string $varName The variable name to send the file in |
|
66 | - * @param string $fileName The name of the file as it should be received at the destination |
|
67 | - * @param string $content The raw content of the file |
|
68 | - * @param string $contentType The content type, use the constants to specify this |
|
69 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
70 | - */ |
|
62 | + /** |
|
63 | + * Adds a file to be sent with the request. |
|
64 | + * |
|
65 | + * @param string $varName The variable name to send the file in |
|
66 | + * @param string $fileName The name of the file as it should be received at the destination |
|
67 | + * @param string $content The raw content of the file |
|
68 | + * @param string $contentType The content type, use the constants to specify this |
|
69 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
70 | + */ |
|
71 | 71 | public function addFile(string $varName, string $fileName, string $content, string $contentType = RequestHelper::FILETYPE_TEXT, string $encoding = RequestHelper::ENCODING_UTF8) : RequestHelper_Boundaries |
72 | 72 | { |
73 | 73 | $boundary = $this->createBoundary(chunk_split(base64_encode($content))) |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | $this->addBoundary($boundary); |
80 | 80 | } |
81 | 81 | |
82 | - /** |
|
83 | - * Adds arbitrary content. |
|
84 | - * |
|
85 | - * @param string $varName |
|
86 | - * @param string $content |
|
87 | - * @param string $contentType |
|
88 | - */ |
|
82 | + /** |
|
83 | + * Adds arbitrary content. |
|
84 | + * |
|
85 | + * @param string $varName |
|
86 | + * @param string $content |
|
87 | + * @param string $contentType |
|
88 | + */ |
|
89 | 89 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper_Boundaries |
90 | 90 | { |
91 | 91 | $boundary = $this->createBoundary($content) |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | return $this->addBoundary($boundary); |
97 | 97 | } |
98 | 98 | |
99 | - /** |
|
100 | - * Adds a variable to be sent with the request. If it |
|
101 | - * already exists, its value is overwritten. |
|
102 | - * |
|
103 | - * @param string $name |
|
104 | - * @param string $value |
|
105 | - */ |
|
99 | + /** |
|
100 | + * Adds a variable to be sent with the request. If it |
|
101 | + * already exists, its value is overwritten. |
|
102 | + * |
|
103 | + * @param string $name |
|
104 | + * @param string $value |
|
105 | + */ |
|
106 | 106 | public function addVariable(string $name, string $value) : RequestHelper_Boundaries |
107 | 107 | { |
108 | 108 | $boundary = $this->createBoundary($value) |
@@ -123,13 +123,13 @@ |
||
123 | 123 | { |
124 | 124 | $result = ''; |
125 | 125 | |
126 | - foreach($this->boundaries as $boundary) |
|
126 | + foreach ($this->boundaries as $boundary) |
|
127 | 127 | { |
128 | 128 | $result .= $boundary->render(); |
129 | 129 | } |
130 | 130 | |
131 | - $result .= "--" . $this->getMimeBoundary() . "--" . |
|
132 | - $this->getEOL() . $this->getEOL(); // always finish with two eol's!! |
|
131 | + $result .= "--".$this->getMimeBoundary()."--". |
|
132 | + $this->getEOL().$this->getEOL(); // always finish with two eol's!! |
|
133 | 133 | |
134 | 134 | return $result; |
135 | 135 | } |
@@ -29,56 +29,56 @@ discard block |
||
29 | 29 | |
30 | 30 | const ERROR_CURL_INIT_FAILED = 17903; |
31 | 31 | |
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | 35 | protected $eol = "\r\n"; |
36 | 36 | |
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | 40 | protected $mimeBoundary; |
41 | 41 | |
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | 45 | protected $data = ''; |
46 | 46 | |
47 | - /** |
|
48 | - * @var string |
|
49 | - */ |
|
47 | + /** |
|
48 | + * @var string |
|
49 | + */ |
|
50 | 50 | protected $destination; |
51 | 51 | |
52 | - /** |
|
53 | - * @var array |
|
54 | - */ |
|
52 | + /** |
|
53 | + * @var array |
|
54 | + */ |
|
55 | 55 | protected $headers = array(); |
56 | 56 | |
57 | - /** |
|
58 | - * Whether to verify SSL certificates. |
|
59 | - * @var bool |
|
60 | - */ |
|
57 | + /** |
|
58 | + * Whether to verify SSL certificates. |
|
59 | + * @var bool |
|
60 | + */ |
|
61 | 61 | protected $verifySSL = true; |
62 | 62 | |
63 | - /** |
|
64 | - * @var RequestHelper_Boundaries |
|
65 | - */ |
|
63 | + /** |
|
64 | + * @var RequestHelper_Boundaries |
|
65 | + */ |
|
66 | 66 | protected $boundaries; |
67 | 67 | |
68 | - /** |
|
69 | - * @var RequestHelper_Response|NULL |
|
70 | - */ |
|
68 | + /** |
|
69 | + * @var RequestHelper_Response|NULL |
|
70 | + */ |
|
71 | 71 | protected $response; |
72 | 72 | |
73 | - /** |
|
74 | - * @var integer |
|
75 | - */ |
|
73 | + /** |
|
74 | + * @var integer |
|
75 | + */ |
|
76 | 76 | protected $timeout = 30; |
77 | 77 | |
78 | - /** |
|
79 | - * Creates a new request helper to send POST data to the specified destination URL. |
|
80 | - * @param string $destinationURL |
|
81 | - */ |
|
78 | + /** |
|
79 | + * Creates a new request helper to send POST data to the specified destination URL. |
|
80 | + * @param string $destinationURL |
|
81 | + */ |
|
82 | 82 | public function __construct(string $destinationURL) |
83 | 83 | { |
84 | 84 | $this->destination = $destinationURL; |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | return $this; |
106 | 106 | } |
107 | 107 | |
108 | - /** |
|
109 | - * Adds a file to be sent with the request. |
|
110 | - * |
|
111 | - * @param string $varName The variable name to send the file in |
|
112 | - * @param string $fileName The name of the file as it should be received at the destination |
|
113 | - * @param string $content The raw content of the file |
|
114 | - * @param string $contentType The content type, use the constants to specify this |
|
115 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
116 | - */ |
|
108 | + /** |
|
109 | + * Adds a file to be sent with the request. |
|
110 | + * |
|
111 | + * @param string $varName The variable name to send the file in |
|
112 | + * @param string $fileName The name of the file as it should be received at the destination |
|
113 | + * @param string $content The raw content of the file |
|
114 | + * @param string $contentType The content type, use the constants to specify this |
|
115 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
116 | + */ |
|
117 | 117 | public function addFile(string $varName, string $fileName, string $content, string $contentType = self::FILETYPE_TEXT, string $encoding = self::ENCODING_UTF8) : RequestHelper |
118 | 118 | { |
119 | 119 | $this->boundaries->addFile($varName, $fileName, $content, $contentType, $encoding); |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | return $this; |
122 | 122 | } |
123 | 123 | |
124 | - /** |
|
125 | - * Adds arbitrary content. |
|
126 | - * |
|
127 | - * @param string $varName The variable name to send the content in. |
|
128 | - * @param string $content |
|
129 | - * @param string $contentType |
|
130 | - */ |
|
124 | + /** |
|
125 | + * Adds arbitrary content. |
|
126 | + * |
|
127 | + * @param string $varName The variable name to send the content in. |
|
128 | + * @param string $content |
|
129 | + * @param string $contentType |
|
130 | + */ |
|
131 | 131 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper |
132 | 132 | { |
133 | 133 | $this->boundaries->addContent($varName, $content, $contentType); |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | return $this; |
150 | 150 | } |
151 | 151 | |
152 | - /** |
|
153 | - * Sets an HTTP header to include in the request. |
|
154 | - * |
|
155 | - * @param string $name |
|
156 | - * @param string $value |
|
157 | - * @return RequestHelper |
|
158 | - */ |
|
152 | + /** |
|
153 | + * Sets an HTTP header to include in the request. |
|
154 | + * |
|
155 | + * @param string $name |
|
156 | + * @param string $value |
|
157 | + * @return RequestHelper |
|
158 | + */ |
|
159 | 159 | public function setHeader(string $name, string $value) : RequestHelper |
160 | 160 | { |
161 | 161 | $this->headers[$name] = $value; |
@@ -163,36 +163,36 @@ discard block |
||
163 | 163 | return $this; |
164 | 164 | } |
165 | 165 | |
166 | - /** |
|
167 | - * Disables SSL certificate checking. |
|
168 | - * |
|
169 | - * @return RequestHelper |
|
170 | - */ |
|
166 | + /** |
|
167 | + * Disables SSL certificate checking. |
|
168 | + * |
|
169 | + * @return RequestHelper |
|
170 | + */ |
|
171 | 171 | public function disableSSLChecks() : RequestHelper |
172 | 172 | { |
173 | 173 | $this->verifySSL = false; |
174 | 174 | return $this; |
175 | 175 | } |
176 | 176 | |
177 | - /** |
|
178 | - * @var integer |
|
179 | - */ |
|
177 | + /** |
|
178 | + * @var integer |
|
179 | + */ |
|
180 | 180 | protected $contentLength = 0; |
181 | 181 | |
182 | - /** |
|
183 | - * Sends the POST request to the destination, and returns |
|
184 | - * the response text. |
|
185 | - * |
|
186 | - * The response object is stored internally, so after calling |
|
187 | - * this method it may be retrieved at any moment using the |
|
188 | - * {@link getResponse()} method. |
|
189 | - * |
|
190 | - * @return string |
|
191 | - * @see RequestHelper::getResponse() |
|
192 | - * @throws RequestHelper_Exception |
|
193 | - * |
|
194 | - * @see RequestHelper::ERROR_REQUEST_FAILED |
|
195 | - */ |
|
182 | + /** |
|
183 | + * Sends the POST request to the destination, and returns |
|
184 | + * the response text. |
|
185 | + * |
|
186 | + * The response object is stored internally, so after calling |
|
187 | + * this method it may be retrieved at any moment using the |
|
188 | + * {@link getResponse()} method. |
|
189 | + * |
|
190 | + * @return string |
|
191 | + * @see RequestHelper::getResponse() |
|
192 | + * @throws RequestHelper_Exception |
|
193 | + * |
|
194 | + * @see RequestHelper::ERROR_REQUEST_FAILED |
|
195 | + */ |
|
196 | 196 | public function send() : string |
197 | 197 | { |
198 | 198 | $this->data = $this->boundaries->render(); |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | return $this->data; |
233 | 233 | } |
234 | 234 | |
235 | - /** |
|
236 | - * Creates a new CURL resource configured according to the |
|
237 | - * request's settings. |
|
238 | - * |
|
239 | - * @param URLInfo $url |
|
240 | - * @throws RequestHelper_Exception |
|
241 | - * @return resource |
|
242 | - */ |
|
235 | + /** |
|
236 | + * Creates a new CURL resource configured according to the |
|
237 | + * request's settings. |
|
238 | + * |
|
239 | + * @param URLInfo $url |
|
240 | + * @throws RequestHelper_Exception |
|
241 | + * @return resource |
|
242 | + */ |
|
243 | 243 | protected function createCURL(URLInfo $url) |
244 | 244 | { |
245 | 245 | $ch = curl_init(); |
@@ -290,10 +290,10 @@ discard block |
||
290 | 290 | return $result; |
291 | 291 | } |
292 | 292 | |
293 | - /** |
|
294 | - * Retrieves the raw response header, in the form of an indexed |
|
295 | - * array containing all response header lines, for example: |
|
296 | - */ |
|
293 | + /** |
|
294 | + * Retrieves the raw response header, in the form of an indexed |
|
295 | + * array containing all response header lines, for example: |
|
296 | + */ |
|
297 | 297 | public function getResponseHeader() |
298 | 298 | { |
299 | 299 | return $this->response->getInfo(); |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | // CURL will complain about an empty response when the |
211 | 211 | // server sends a 100-continue code. That should not be |
212 | 212 | // regarded as an error. |
213 | - if($output === false && $this->response->getCode() !== 100) |
|
213 | + if ($output === false && $this->response->getCode() !== 100) |
|
214 | 214 | { |
215 | 215 | $this->response->setError( |
216 | 216 | curl_errno($ch), |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | protected function createCURL(URLInfo $url) |
244 | 244 | { |
245 | 245 | $ch = curl_init(); |
246 | - if($ch === false) |
|
246 | + if ($ch === false) |
|
247 | 247 | { |
248 | 248 | throw new RequestHelper_Exception( |
249 | 249 | 'Could not initialize a new cURL instance.', |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | } |
254 | 254 | |
255 | 255 | $this->setHeader('Content-Length', $this->boundaries->getContentLength()); |
256 | - $this->setHeader('Content-Type', 'multipart/form-data; charset=UTF-8; boundary=' . $this->mimeBoundary); |
|
256 | + $this->setHeader('Content-Type', 'multipart/form-data; charset=UTF-8; boundary='.$this->mimeBoundary); |
|
257 | 257 | |
258 | 258 | //curl_setopt($ch, CURLOPT_VERBOSE, true); |
259 | 259 | curl_setopt($ch, CURLOPT_POST, true); |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
265 | 265 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->renderHeaders()); |
266 | 266 | |
267 | - if($this->verifySSL) |
|
267 | + if ($this->verifySSL) |
|
268 | 268 | { |
269 | 269 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
270 | 270 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
271 | 271 | } |
272 | 272 | |
273 | - if($url->hasUsername()) |
|
273 | + if ($url->hasUsername()) |
|
274 | 274 | { |
275 | 275 | curl_setopt($ch, CURLOPT_USERNAME, $url->getUsername()); |
276 | 276 | curl_setopt($ch, CURLOPT_PASSWORD, $url->getPassword()); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | { |
284 | 284 | $result = array(); |
285 | 285 | |
286 | - foreach($this->headers as $name => $value) { |
|
286 | + foreach ($this->headers as $name => $value) { |
|
287 | 287 | $result[] = $name.': '.$value; |
288 | 288 | } |
289 | 289 |
@@ -216,8 +216,7 @@ |
||
216 | 216 | curl_errno($ch), |
217 | 217 | curl_error($ch) |
218 | 218 | ); |
219 | - } |
|
220 | - else |
|
219 | + } else |
|
221 | 220 | { |
222 | 221 | $this->response->setBody($output); |
223 | 222 | } |