@@ -36,42 +36,42 @@ discard block |
||
36 | 36 | public const TYPE_PHONE = 'phone'; |
37 | 37 | public const TYPE_URL = 'url'; |
38 | 38 | |
39 | - /** |
|
40 | - * The original URL that was passed to the constructor. |
|
41 | - * @var string |
|
42 | - */ |
|
39 | + /** |
|
40 | + * The original URL that was passed to the constructor. |
|
41 | + * @var string |
|
42 | + */ |
|
43 | 43 | protected $rawURL; |
44 | 44 | |
45 | - /** |
|
46 | - * @var array |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var array |
|
47 | + */ |
|
48 | 48 | protected $info; |
49 | 49 | |
50 | - /** |
|
51 | - * @var string[] |
|
52 | - */ |
|
50 | + /** |
|
51 | + * @var string[] |
|
52 | + */ |
|
53 | 53 | protected $excludedParams = array(); |
54 | 54 | |
55 | - /** |
|
56 | - * @var bool |
|
57 | - * @see URLInfo::setParamExclusion() |
|
58 | - */ |
|
55 | + /** |
|
56 | + * @var bool |
|
57 | + * @see URLInfo::setParamExclusion() |
|
58 | + */ |
|
59 | 59 | protected $paramExclusion = false; |
60 | 60 | |
61 | - /** |
|
62 | - * @var array<string,string>|NULL |
|
63 | - * @see URLInfo::getTypeLabel() |
|
64 | - */ |
|
61 | + /** |
|
62 | + * @var array<string,string>|NULL |
|
63 | + * @see URLInfo::getTypeLabel() |
|
64 | + */ |
|
65 | 65 | protected static $typeLabels = null; |
66 | 66 | |
67 | - /** |
|
68 | - * @var bool |
|
69 | - */ |
|
67 | + /** |
|
68 | + * @var bool |
|
69 | + */ |
|
70 | 70 | protected $highlightExcluded = false; |
71 | 71 | |
72 | - /** |
|
73 | - * @var array |
|
74 | - */ |
|
72 | + /** |
|
73 | + * @var array |
|
74 | + */ |
|
75 | 75 | protected $infoKeys = array( |
76 | 76 | 'scheme', |
77 | 77 | 'host', |
@@ -83,24 +83,24 @@ discard block |
||
83 | 83 | 'fragment' |
84 | 84 | ); |
85 | 85 | |
86 | - /** |
|
87 | - * @var string |
|
88 | - */ |
|
86 | + /** |
|
87 | + * @var string |
|
88 | + */ |
|
89 | 89 | protected $url; |
90 | 90 | |
91 | - /** |
|
92 | - * @var URLInfo_Parser |
|
93 | - */ |
|
91 | + /** |
|
92 | + * @var URLInfo_Parser |
|
93 | + */ |
|
94 | 94 | protected $parser; |
95 | 95 | |
96 | - /** |
|
97 | - * @var URLInfo_Normalizer|NULL |
|
98 | - */ |
|
96 | + /** |
|
97 | + * @var URLInfo_Normalizer|NULL |
|
98 | + */ |
|
99 | 99 | protected $normalizer; |
100 | 100 | |
101 | - /** |
|
102 | - * @var bool |
|
103 | - */ |
|
101 | + /** |
|
102 | + * @var bool |
|
103 | + */ |
|
104 | 104 | protected $encodeUTFChars = false; |
105 | 105 | |
106 | 106 | public function __construct(string $url) |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | $this->info = $this->parser->getInfo(); |
118 | 118 | } |
119 | 119 | |
120 | - /** |
|
121 | - * Whether to URL encode any non-encoded UTF8 characters in the URL. |
|
122 | - * Default is to leave them as-is for better readability, since |
|
123 | - * browsers handle this well. |
|
124 | - * |
|
125 | - * @param bool $enabled |
|
126 | - * @return URLInfo |
|
127 | - */ |
|
120 | + /** |
|
121 | + * Whether to URL encode any non-encoded UTF8 characters in the URL. |
|
122 | + * Default is to leave them as-is for better readability, since |
|
123 | + * browsers handle this well. |
|
124 | + * |
|
125 | + * @param bool $enabled |
|
126 | + * @return URLInfo |
|
127 | + */ |
|
128 | 128 | public function setUTFEncoding(bool $enabled=true) : URLInfo |
129 | 129 | { |
130 | 130 | if($this->encodeUTFChars !== $enabled) |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | return $this->encodeUTFChars; |
142 | 142 | } |
143 | 143 | |
144 | - /** |
|
145 | - * Filters an URL: removes control characters and the |
|
146 | - * like to have a clean URL to work with. |
|
147 | - * |
|
148 | - * @param string $url |
|
149 | - * @return string |
|
150 | - */ |
|
144 | + /** |
|
145 | + * Filters an URL: removes control characters and the |
|
146 | + * like to have a clean URL to work with. |
|
147 | + * |
|
148 | + * @param string $url |
|
149 | + * @return string |
|
150 | + */ |
|
151 | 151 | public static function filterURL(string $url) |
152 | 152 | { |
153 | 153 | return URLInfo_Filter::filter($url); |
@@ -177,12 +177,12 @@ discard block |
||
177 | 177 | return $this->info['type'] === self::TYPE_PHONE; |
178 | 178 | } |
179 | 179 | |
180 | - /** |
|
181 | - * Whether the URL is a regular URL, not one of the |
|
182 | - * other types like a phone number or email address. |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
180 | + /** |
|
181 | + * Whether the URL is a regular URL, not one of the |
|
182 | + * other types like a phone number or email address. |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | 186 | public function isURL() : bool |
187 | 187 | { |
188 | 188 | $host = $this->getHost(); |
@@ -194,20 +194,20 @@ discard block |
||
194 | 194 | return $this->parser->isValid(); |
195 | 195 | } |
196 | 196 | |
197 | - /** |
|
198 | - * Retrieves the host name, or an empty string if none is present. |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
197 | + /** |
|
198 | + * Retrieves the host name, or an empty string if none is present. |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | 202 | public function getHost() : string |
203 | 203 | { |
204 | 204 | return $this->getInfoKey('host'); |
205 | 205 | } |
206 | 206 | |
207 | - /** |
|
208 | - * Retrieves the path, or an empty string if none is present. |
|
209 | - * @return string |
|
210 | - */ |
|
207 | + /** |
|
208 | + * Retrieves the path, or an empty string if none is present. |
|
209 | + * @return string |
|
210 | + */ |
|
211 | 211 | public function getPath() : string |
212 | 212 | { |
213 | 213 | return $this->getInfoKey('path'); |
@@ -223,10 +223,10 @@ discard block |
||
223 | 223 | return $this->getInfoKey('scheme'); |
224 | 224 | } |
225 | 225 | |
226 | - /** |
|
227 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
228 | - * @return int |
|
229 | - */ |
|
226 | + /** |
|
227 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
228 | + * @return int |
|
229 | + */ |
|
230 | 230 | public function getPort() : int |
231 | 231 | { |
232 | 232 | $port = $this->getInfoKey('port'); |
@@ -238,13 +238,13 @@ discard block |
||
238 | 238 | return -1; |
239 | 239 | } |
240 | 240 | |
241 | - /** |
|
242 | - * Retrieves the raw query string, or an empty string if none is present. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - * |
|
246 | - * @see URLInfo::getParams() |
|
247 | - */ |
|
241 | + /** |
|
242 | + * Retrieves the raw query string, or an empty string if none is present. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + * |
|
246 | + * @see URLInfo::getParams() |
|
247 | + */ |
|
248 | 248 | public function getQuery() : string |
249 | 249 | { |
250 | 250 | return $this->getInfoKey('query'); |
@@ -260,20 +260,20 @@ discard block |
||
260 | 260 | return $this->getInfoKey('pass'); |
261 | 261 | } |
262 | 262 | |
263 | - /** |
|
264 | - * Whether the URL contains a port number. |
|
265 | - * @return bool |
|
266 | - */ |
|
263 | + /** |
|
264 | + * Whether the URL contains a port number. |
|
265 | + * @return bool |
|
266 | + */ |
|
267 | 267 | public function hasPort() : bool |
268 | 268 | { |
269 | 269 | return $this->getPort() !== -1; |
270 | 270 | } |
271 | 271 | |
272 | - /** |
|
273 | - * Alias for the hasParams() method. |
|
274 | - * @return bool |
|
275 | - * @see URLInfo::hasParams() |
|
276 | - */ |
|
272 | + /** |
|
273 | + * Alias for the hasParams() method. |
|
274 | + * @return bool |
|
275 | + * @see URLInfo::hasParams() |
|
276 | + */ |
|
277 | 277 | public function hasQuery() : bool |
278 | 278 | { |
279 | 279 | return $this->hasParams(); |
@@ -318,23 +318,23 @@ discard block |
||
318 | 318 | return ''; |
319 | 319 | } |
320 | 320 | |
321 | - /** |
|
322 | - * Retrieves a normalized URL: this ensures that all parameters |
|
323 | - * in the URL are always in the same order. |
|
324 | - * |
|
325 | - * @return string |
|
326 | - */ |
|
321 | + /** |
|
322 | + * Retrieves a normalized URL: this ensures that all parameters |
|
323 | + * in the URL are always in the same order. |
|
324 | + * |
|
325 | + * @return string |
|
326 | + */ |
|
327 | 327 | public function getNormalized() : string |
328 | 328 | { |
329 | 329 | return $this->normalize(true); |
330 | 330 | } |
331 | 331 | |
332 | - /** |
|
333 | - * Like getNormalized(), but if a username and password are present |
|
334 | - * in the URL, returns the URL without them. |
|
335 | - * |
|
336 | - * @return string |
|
337 | - */ |
|
332 | + /** |
|
333 | + * Like getNormalized(), but if a username and password are present |
|
334 | + * in the URL, returns the URL without them. |
|
335 | + * |
|
336 | + * @return string |
|
337 | + */ |
|
338 | 338 | public function getNormalizedWithoutAuth() : string |
339 | 339 | { |
340 | 340 | return $this->normalize(false); |
@@ -355,25 +355,25 @@ discard block |
||
355 | 355 | return $this->normalizer->normalize(); |
356 | 356 | } |
357 | 357 | |
358 | - /** |
|
359 | - * Creates a hash of the URL, which can be used for comparisons. |
|
360 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
361 | - * the same links with a different parameter order will have the |
|
362 | - * same hash. |
|
363 | - * |
|
364 | - * @return string |
|
365 | - */ |
|
358 | + /** |
|
359 | + * Creates a hash of the URL, which can be used for comparisons. |
|
360 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
361 | + * the same links with a different parameter order will have the |
|
362 | + * same hash. |
|
363 | + * |
|
364 | + * @return string |
|
365 | + */ |
|
366 | 366 | public function getHash() |
367 | 367 | { |
368 | 368 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
369 | 369 | } |
370 | 370 | |
371 | - /** |
|
372 | - * Highlights the URL using HTML tags with specific highlighting |
|
373 | - * class names. |
|
374 | - * |
|
375 | - * @return string Will return an empty string if the URL is not valid. |
|
376 | - */ |
|
371 | + /** |
|
372 | + * Highlights the URL using HTML tags with specific highlighting |
|
373 | + * class names. |
|
374 | + * |
|
375 | + * @return string Will return an empty string if the URL is not valid. |
|
376 | + */ |
|
377 | 377 | public function getHighlighted() : string |
378 | 378 | { |
379 | 379 | if(!$this->isValid()) { |
@@ -407,15 +407,15 @@ discard block |
||
407 | 407 | return count($params); |
408 | 408 | } |
409 | 409 | |
410 | - /** |
|
411 | - * Retrieves all parameters specified in the url, |
|
412 | - * if any, as an associative array. |
|
413 | - * |
|
414 | - * NOTE: Ignores parameters that have been added |
|
415 | - * to the excluded parameters list. |
|
416 | - * |
|
417 | - * @return array |
|
418 | - */ |
|
410 | + /** |
|
411 | + * Retrieves all parameters specified in the url, |
|
412 | + * if any, as an associative array. |
|
413 | + * |
|
414 | + * NOTE: Ignores parameters that have been added |
|
415 | + * to the excluded parameters list. |
|
416 | + * |
|
417 | + * @return array |
|
418 | + */ |
|
419 | 419 | public function getParams() : array |
420 | 420 | { |
421 | 421 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -433,22 +433,22 @@ discard block |
||
433 | 433 | return $keep; |
434 | 434 | } |
435 | 435 | |
436 | - /** |
|
437 | - * Retrieves the names of all parameters present in the URL, if any. |
|
438 | - * @return string[] |
|
439 | - */ |
|
436 | + /** |
|
437 | + * Retrieves the names of all parameters present in the URL, if any. |
|
438 | + * @return string[] |
|
439 | + */ |
|
440 | 440 | public function getParamNames() : array |
441 | 441 | { |
442 | 442 | $params = $this->getParams(); |
443 | 443 | return array_keys($params); |
444 | 444 | } |
445 | 445 | |
446 | - /** |
|
447 | - * Retrieves a specific parameter value from the URL. |
|
448 | - * |
|
449 | - * @param string $name |
|
450 | - * @return string The parameter value, or an empty string if it does not exist. |
|
451 | - */ |
|
446 | + /** |
|
447 | + * Retrieves a specific parameter value from the URL. |
|
448 | + * |
|
449 | + * @param string $name |
|
450 | + * @return string The parameter value, or an empty string if it does not exist. |
|
451 | + */ |
|
452 | 452 | public function getParam(string $name) : string |
453 | 453 | { |
454 | 454 | if(isset($this->info['params'][$name])) { |
@@ -458,16 +458,16 @@ discard block |
||
458 | 458 | return ''; |
459 | 459 | } |
460 | 460 | |
461 | - /** |
|
462 | - * Excludes an URL parameter entirely if present: |
|
463 | - * the parser will act as if the parameter was not |
|
464 | - * even present in the source URL, effectively |
|
465 | - * stripping it. |
|
466 | - * |
|
467 | - * @param string $name |
|
468 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
469 | - * @return URLInfo |
|
470 | - */ |
|
461 | + /** |
|
462 | + * Excludes an URL parameter entirely if present: |
|
463 | + * the parser will act as if the parameter was not |
|
464 | + * even present in the source URL, effectively |
|
465 | + * stripping it. |
|
466 | + * |
|
467 | + * @param string $name |
|
468 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
469 | + * @return URLInfo |
|
470 | + */ |
|
471 | 471 | public function excludeParam(string $name, string $reason='') : URLInfo |
472 | 472 | { |
473 | 473 | if(!isset($this->excludedParams[$name])) |
@@ -520,25 +520,25 @@ discard block |
||
520 | 520 | return self::$typeLabels[$this->getType()]; |
521 | 521 | } |
522 | 522 | |
523 | - /** |
|
524 | - * Whether excluded parameters should be highlighted in |
|
525 | - * a different color in the URL when using the |
|
526 | - * {@link URLInfo::getHighlighted()} method. |
|
527 | - * |
|
528 | - * @param bool $highlight |
|
529 | - * @return URLInfo |
|
530 | - */ |
|
523 | + /** |
|
524 | + * Whether excluded parameters should be highlighted in |
|
525 | + * a different color in the URL when using the |
|
526 | + * {@link URLInfo::getHighlighted()} method. |
|
527 | + * |
|
528 | + * @param bool $highlight |
|
529 | + * @return URLInfo |
|
530 | + */ |
|
531 | 531 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
532 | 532 | { |
533 | 533 | $this->highlightExcluded = $highlight; |
534 | 534 | return $this; |
535 | 535 | } |
536 | 536 | |
537 | - /** |
|
538 | - * Returns an array with all relevant URL information. |
|
539 | - * |
|
540 | - * @return array |
|
541 | - */ |
|
537 | + /** |
|
538 | + * Returns an array with all relevant URL information. |
|
539 | + * |
|
540 | + * @return array |
|
541 | + */ |
|
542 | 542 | public function toArray() : array |
543 | 543 | { |
544 | 544 | return array( |
@@ -582,24 +582,24 @@ discard block |
||
582 | 582 | return $this; |
583 | 583 | } |
584 | 584 | |
585 | - /** |
|
586 | - * Whether the parameter exclusion mode is enabled: |
|
587 | - * In this case, if any parameters have been added to the |
|
588 | - * exclusion list, all relevant methods will exclude these. |
|
589 | - * |
|
590 | - * @return bool |
|
591 | - */ |
|
585 | + /** |
|
586 | + * Whether the parameter exclusion mode is enabled: |
|
587 | + * In this case, if any parameters have been added to the |
|
588 | + * exclusion list, all relevant methods will exclude these. |
|
589 | + * |
|
590 | + * @return bool |
|
591 | + */ |
|
592 | 592 | public function isParamExclusionEnabled() : bool |
593 | 593 | { |
594 | 594 | return $this->paramExclusion; |
595 | 595 | } |
596 | 596 | |
597 | - /** |
|
598 | - * Checks whether the link contains any parameters that |
|
599 | - * are on the list of excluded parameters. |
|
600 | - * |
|
601 | - * @return bool |
|
602 | - */ |
|
597 | + /** |
|
598 | + * Checks whether the link contains any parameters that |
|
599 | + * are on the list of excluded parameters. |
|
600 | + * |
|
601 | + * @return bool |
|
602 | + */ |
|
603 | 603 | public function containsExcludedParams() : bool |
604 | 604 | { |
605 | 605 | if(empty($this->excludedParams)) { |
@@ -667,16 +667,16 @@ discard block |
||
667 | 667 | return $this->highlightExcluded; |
668 | 668 | } |
669 | 669 | |
670 | - /** |
|
671 | - * Checks if the URL exists, i.e. can be connected to. Will return |
|
672 | - * true if the returned HTTP status code is `200` or `302`. |
|
673 | - * |
|
674 | - * NOTE: If the target URL requires HTTP authentication, the username |
|
675 | - * and password should be integrated into the URL. |
|
676 | - * |
|
677 | - * @return bool |
|
678 | - * @throws BaseException |
|
679 | - */ |
|
670 | + /** |
|
671 | + * Checks if the URL exists, i.e. can be connected to. Will return |
|
672 | + * true if the returned HTTP status code is `200` or `302`. |
|
673 | + * |
|
674 | + * NOTE: If the target URL requires HTTP authentication, the username |
|
675 | + * and password should be integrated into the URL. |
|
676 | + * |
|
677 | + * @return bool |
|
678 | + * @throws BaseException |
|
679 | + */ |
|
680 | 680 | public function tryConnect(bool $verifySSL=true) : bool |
681 | 681 | { |
682 | 682 | return $this->createConnectionTester() |
@@ -684,26 +684,26 @@ discard block |
||
684 | 684 | ->canConnect(); |
685 | 685 | } |
686 | 686 | |
687 | - /** |
|
688 | - * Creates the connection tester instance that is used |
|
689 | - * to check if a URL can be connected to, and which is |
|
690 | - * used in the {@see URLInfo::tryConnect()} method. It |
|
691 | - * allows more settings to be used. |
|
692 | - * |
|
693 | - * @return URLInfo_ConnectionTester |
|
694 | - */ |
|
687 | + /** |
|
688 | + * Creates the connection tester instance that is used |
|
689 | + * to check if a URL can be connected to, and which is |
|
690 | + * used in the {@see URLInfo::tryConnect()} method. It |
|
691 | + * allows more settings to be used. |
|
692 | + * |
|
693 | + * @return URLInfo_ConnectionTester |
|
694 | + */ |
|
695 | 695 | public function createConnectionTester() : URLInfo_ConnectionTester |
696 | 696 | { |
697 | 697 | return new URLInfo_ConnectionTester($this); |
698 | 698 | } |
699 | 699 | |
700 | - /** |
|
701 | - * Adds/overwrites an URL parameter. |
|
702 | - * |
|
703 | - * @param string $name |
|
704 | - * @param string $val |
|
705 | - * @return URLInfo |
|
706 | - */ |
|
700 | + /** |
|
701 | + * Adds/overwrites an URL parameter. |
|
702 | + * |
|
703 | + * @param string $name |
|
704 | + * @param string $val |
|
705 | + * @return URLInfo |
|
706 | + */ |
|
707 | 707 | public function setParam(string $name, string $val) : URLInfo |
708 | 708 | { |
709 | 709 | $this->info['params'][$name] = $val; |
@@ -711,13 +711,13 @@ discard block |
||
711 | 711 | return $this; |
712 | 712 | } |
713 | 713 | |
714 | - /** |
|
715 | - * Removes an URL parameter. Has no effect if the |
|
716 | - * parameter is not present to begin with. |
|
717 | - * |
|
718 | - * @param string $param |
|
719 | - * @return URLInfo |
|
720 | - */ |
|
714 | + /** |
|
715 | + * Removes an URL parameter. Has no effect if the |
|
716 | + * parameter is not present to begin with. |
|
717 | + * |
|
718 | + * @param string $param |
|
719 | + * @return URLInfo |
|
720 | + */ |
|
721 | 721 | public function removeParam(string $param) : URLInfo |
722 | 722 | { |
723 | 723 | if(isset($this->info['params'][$param])) |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | |
43 | 43 | public const REGEX_MD5 = '/^[a-f0-9]{32}$/i'; |
44 | 44 | |
45 | - /** |
|
46 | - * @var string |
|
47 | - * @see https://en.wikipedia.org/wiki/Email_address#Local-part |
|
48 | - */ |
|
45 | + /** |
|
46 | + * @var string |
|
47 | + * @see https://en.wikipedia.org/wiki/Email_address#Local-part |
|
48 | + */ |
|
49 | 49 | public const REGEX_EMAIL = '/[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i'; |
50 | 50 | |
51 | 51 | public const REGEX_PHONE = '/\A[+0-9][0-9 +\-()]+\z/m'; |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public const REGEX_IS_HTML = '%<{0,1}[a-z\/][\s\S]*>|<[a-z\/][\s\S]*>{0,1}%i'; |
99 | 99 | |
100 | - /** |
|
101 | - * Hexadecimal color codes. Allows the following formats: |
|
102 | - * |
|
103 | - * FFFFFF |
|
104 | - * FFF |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
100 | + /** |
|
101 | + * Hexadecimal color codes. Allows the following formats: |
|
102 | + * |
|
103 | + * FFFFFF |
|
104 | + * FFF |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | 108 | public const REGEX_HEX_COLOR_CODE = '/\A(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\z/iU'; |
109 | 109 | |
110 | 110 | /** |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | |
38 | 38 | public const ERROR_INVALID_SERIALIZED_DATA = 56301; |
39 | 39 | |
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | 43 | protected $string; |
44 | 44 | |
45 | - /** |
|
46 | - * @var mixed |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var mixed |
|
47 | + */ |
|
48 | 48 | protected $value; |
49 | 49 | |
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | 53 | protected $type; |
54 | 54 | |
55 | 55 | /** |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | return new VariableInfo(null, $serialized); |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * Parses a previously serialized data set to restore the |
|
111 | - * variable information from it. |
|
112 | - * |
|
113 | - * @param array $serialized |
|
114 | - * @throws BaseException |
|
115 | - * |
|
116 | - * @see VariableInfo::ERROR_INVALID_SERIALIZED_DATA |
|
117 | - */ |
|
109 | + /** |
|
110 | + * Parses a previously serialized data set to restore the |
|
111 | + * variable information from it. |
|
112 | + * |
|
113 | + * @param array $serialized |
|
114 | + * @throws BaseException |
|
115 | + * |
|
116 | + * @see VariableInfo::ERROR_INVALID_SERIALIZED_DATA |
|
117 | + */ |
|
118 | 118 | protected function parseSerialized(array $serialized) : void |
119 | 119 | { |
120 | 120 | if(!isset($serialized['string']) || !isset($serialized['type']) || !isset($serialized['options'])) |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | return $this->value; |
157 | 157 | } |
158 | 158 | |
159 | - /** |
|
160 | - * The variable type - this is the same string that |
|
161 | - * is returned by the PHP function `gettype`. |
|
162 | - * |
|
163 | - * @return string |
|
164 | - */ |
|
159 | + /** |
|
160 | + * The variable type - this is the same string that |
|
161 | + * is returned by the PHP function `gettype`. |
|
162 | + * |
|
163 | + * @return string |
|
164 | + */ |
|
165 | 165 | public function getType() : string |
166 | 166 | { |
167 | 167 | return $this->type; |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | ); |
176 | 176 | } |
177 | 177 | |
178 | - /** |
|
179 | - * Whether to prepend the variable type before the value, |
|
180 | - * like the var_dump function. Example: <code>string "Some text"</code>. |
|
181 | - * |
|
182 | - * @param bool $enable |
|
183 | - * @return VariableInfo |
|
184 | - */ |
|
178 | + /** |
|
179 | + * Whether to prepend the variable type before the value, |
|
180 | + * like the var_dump function. Example: <code>string "Some text"</code>. |
|
181 | + * |
|
182 | + * @param bool $enable |
|
183 | + * @return VariableInfo |
|
184 | + */ |
|
185 | 185 | public function enableType(bool $enable=true) : VariableInfo |
186 | 186 | { |
187 | 187 | return $this->setOption('prepend-type', $enable); |
@@ -22,9 +22,9 @@ |
||
22 | 22 | { |
23 | 23 | public const ERROR_INVALID_CALLBACK = 62101; |
24 | 24 | |
25 | - /** |
|
26 | - * @var callable |
|
27 | - */ |
|
25 | + /** |
|
26 | + * @var callable |
|
27 | + */ |
|
28 | 28 | private $callback; |
29 | 29 | |
30 | 30 | public function __construct($callback) |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected $classes = array(); |
40 | 40 | |
41 | - /** |
|
42 | - * The namespace detected in the file, if any. |
|
43 | - * @var string |
|
44 | - */ |
|
41 | + /** |
|
42 | + * The namespace detected in the file, if any. |
|
43 | + * @var string |
|
44 | + */ |
|
45 | 45 | protected $namespace = ''; |
46 | 46 | |
47 | - /** |
|
48 | - * @param string $path The path to the PHP file to parse. |
|
49 | - * @throws FileHelper_Exception |
|
50 | - * @see FileHelper::findPHPClasses() |
|
51 | - */ |
|
47 | + /** |
|
48 | + * @param string $path The path to the PHP file to parse. |
|
49 | + * @throws FileHelper_Exception |
|
50 | + * @see FileHelper::findPHPClasses() |
|
51 | + */ |
|
52 | 52 | public function __construct(string $path) |
53 | 53 | { |
54 | 54 | $this->path = realpath($path); |
@@ -68,58 +68,58 @@ discard block |
||
68 | 68 | $this->parseFile(); |
69 | 69 | } |
70 | 70 | |
71 | - /** |
|
72 | - * The name of the namespace of the classes in the file, if any. |
|
73 | - * @return string |
|
74 | - */ |
|
71 | + /** |
|
72 | + * The name of the namespace of the classes in the file, if any. |
|
73 | + * @return string |
|
74 | + */ |
|
75 | 75 | public function getNamespace() : string |
76 | 76 | { |
77 | 77 | return $this->namespace; |
78 | 78 | } |
79 | 79 | |
80 | - /** |
|
81 | - * Whether the file contains a namespace. |
|
82 | - * @return bool |
|
83 | - */ |
|
80 | + /** |
|
81 | + * Whether the file contains a namespace. |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | 84 | public function hasNamespace() : bool |
85 | 85 | { |
86 | 86 | return !empty($this->namespace); |
87 | 87 | } |
88 | 88 | |
89 | - /** |
|
90 | - * The absolute path to the file. |
|
91 | - * @return string |
|
92 | - */ |
|
89 | + /** |
|
90 | + * The absolute path to the file. |
|
91 | + * @return string |
|
92 | + */ |
|
93 | 93 | public function getPath() : string |
94 | 94 | { |
95 | 95 | return $this->path; |
96 | 96 | } |
97 | 97 | |
98 | - /** |
|
99 | - * Whether any classes were found in the file. |
|
100 | - * @return bool |
|
101 | - */ |
|
98 | + /** |
|
99 | + * Whether any classes were found in the file. |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | 102 | public function hasClasses() : bool |
103 | 103 | { |
104 | 104 | return !empty($this->classes); |
105 | 105 | } |
106 | 106 | |
107 | - /** |
|
108 | - * The names of the classes that were found in the file (with namespace if any). |
|
109 | - * @return string[] |
|
110 | - */ |
|
107 | + /** |
|
108 | + * The names of the classes that were found in the file (with namespace if any). |
|
109 | + * @return string[] |
|
110 | + */ |
|
111 | 111 | public function getClassNames() : array |
112 | 112 | { |
113 | 113 | return array_keys($this->classes); |
114 | 114 | } |
115 | 115 | |
116 | - /** |
|
117 | - * Retrieves all classes that were detected in the file, |
|
118 | - * which can be used to retrieve more information about |
|
119 | - * them. |
|
120 | - * |
|
121 | - * @return FileHelper_PHPClassInfo_Class[] |
|
122 | - */ |
|
116 | + /** |
|
117 | + * Retrieves all classes that were detected in the file, |
|
118 | + * which can be used to retrieve more information about |
|
119 | + * them. |
|
120 | + * |
|
121 | + * @return FileHelper_PHPClassInfo_Class[] |
|
122 | + */ |
|
123 | 123 | public function getClasses() : array |
124 | 124 | { |
125 | 125 | return array_values($this->classes); |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - /** |
|
169 | - * Strips all whitespace from the string, replacing it with |
|
170 | - * regular spaces (newlines, tabs, etc.). |
|
171 | - * |
|
172 | - * @param string $string |
|
173 | - * @return string |
|
174 | - */ |
|
168 | + /** |
|
169 | + * Strips all whitespace from the string, replacing it with |
|
170 | + * regular spaces (newlines, tabs, etc.). |
|
171 | + * |
|
172 | + * @param string $string |
|
173 | + * @return string |
|
174 | + */ |
|
175 | 175 | protected function stripWhitespace(string $string) : string |
176 | 176 | { |
177 | 177 | return preg_replace('/[\s]/', ' ', $string); |
@@ -37,23 +37,23 @@ discard block |
||
37 | 37 | public const OPTION_PATHMODE = 'pathmode'; |
38 | 38 | |
39 | 39 | /** |
40 | - * @var string |
|
41 | - */ |
|
40 | + * @var string |
|
41 | + */ |
|
42 | 42 | protected $path; |
43 | 43 | |
44 | - /** |
|
45 | - * @var string[] |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var string[] |
|
46 | + */ |
|
47 | 47 | protected $found; |
48 | 48 | |
49 | - /** |
|
50 | - * The path must exist when the class is instantiated: its |
|
51 | - * real path will be determined to work with. |
|
52 | - * |
|
53 | - * @param string $path The absolute path to the target folder. |
|
54 | - * @throws FileHelper_Exception |
|
55 | - * @see FileHelper_FileFinder::ERROR_PATH_DOES_NOT_EXIST |
|
56 | - */ |
|
49 | + /** |
|
50 | + * The path must exist when the class is instantiated: its |
|
51 | + * real path will be determined to work with. |
|
52 | + * |
|
53 | + * @param string $path The absolute path to the target folder. |
|
54 | + * @throws FileHelper_Exception |
|
55 | + * @see FileHelper_FileFinder::ERROR_PATH_DOES_NOT_EXIST |
|
56 | + */ |
|
57 | 57 | public function __construct(string $path) |
58 | 58 | { |
59 | 59 | $real = realpath($path); |
@@ -85,66 +85,66 @@ discard block |
||
85 | 85 | ); |
86 | 86 | } |
87 | 87 | |
88 | - /** |
|
89 | - * Enables extension stripping, to return file names without extension. |
|
90 | - * |
|
91 | - * @return FileHelper_FileFinder |
|
92 | - */ |
|
88 | + /** |
|
89 | + * Enables extension stripping, to return file names without extension. |
|
90 | + * |
|
91 | + * @return FileHelper_FileFinder |
|
92 | + */ |
|
93 | 93 | public function stripExtensions() : FileHelper_FileFinder |
94 | 94 | { |
95 | 95 | return $this->setOption('strip-extensions', true); |
96 | 96 | } |
97 | 97 | |
98 | - /** |
|
99 | - * Enables recursing into subfolders. |
|
100 | - * |
|
101 | - * @return FileHelper_FileFinder |
|
102 | - */ |
|
98 | + /** |
|
99 | + * Enables recursing into subfolders. |
|
100 | + * |
|
101 | + * @return FileHelper_FileFinder |
|
102 | + */ |
|
103 | 103 | public function makeRecursive() : FileHelper_FileFinder |
104 | 104 | { |
105 | 105 | return $this->setOption('recursive', true); |
106 | 106 | } |
107 | 107 | |
108 | - /** |
|
109 | - * Retrieves all extensions that were added to |
|
110 | - * the include list. |
|
111 | - * |
|
112 | - * @return string[] |
|
113 | - */ |
|
108 | + /** |
|
109 | + * Retrieves all extensions that were added to |
|
110 | + * the include list. |
|
111 | + * |
|
112 | + * @return string[] |
|
113 | + */ |
|
114 | 114 | public function getIncludeExtensions() : array |
115 | 115 | { |
116 | 116 | return $this->getArrayOption(self::OPTION_INCLUDE_EXTENSIONS); |
117 | 117 | } |
118 | 118 | |
119 | - /** |
|
120 | - * Includes a single extension in the file search: only |
|
121 | - * files with this extension will be used in the results. |
|
122 | - * |
|
123 | - * NOTE: Included extensions take precedence before excluded |
|
124 | - * extensions. If any excluded extensions are specified, they |
|
125 | - * will be ignored. |
|
126 | - * |
|
127 | - * @param string $extension Extension name, without dot (`php` for example). |
|
128 | - * @return FileHelper_FileFinder |
|
129 | - * @see FileHelper_FileFinder::includeExtensions() |
|
130 | - */ |
|
119 | + /** |
|
120 | + * Includes a single extension in the file search: only |
|
121 | + * files with this extension will be used in the results. |
|
122 | + * |
|
123 | + * NOTE: Included extensions take precedence before excluded |
|
124 | + * extensions. If any excluded extensions are specified, they |
|
125 | + * will be ignored. |
|
126 | + * |
|
127 | + * @param string $extension Extension name, without dot (`php` for example). |
|
128 | + * @return FileHelper_FileFinder |
|
129 | + * @see FileHelper_FileFinder::includeExtensions() |
|
130 | + */ |
|
131 | 131 | public function includeExtension(string $extension) : FileHelper_FileFinder |
132 | 132 | { |
133 | 133 | return $this->includeExtensions(array($extension)); |
134 | 134 | } |
135 | 135 | |
136 | - /** |
|
137 | - * Includes several extensions in the file search: only |
|
138 | - * files with these extensions wil be used in the results. |
|
139 | - * |
|
140 | - * NOTE: Included extensions take precedence before excluded |
|
141 | - * extensions. If any excluded extensions are specified, they |
|
142 | - * will be ignored. |
|
143 | - * |
|
144 | - * @param string[] $extensions Extension names, without dot (`php` for example). |
|
145 | - * @return FileHelper_FileFinder |
|
146 | - * @see FileHelper_FileFinder::includeExtension() |
|
147 | - */ |
|
136 | + /** |
|
137 | + * Includes several extensions in the file search: only |
|
138 | + * files with these extensions wil be used in the results. |
|
139 | + * |
|
140 | + * NOTE: Included extensions take precedence before excluded |
|
141 | + * extensions. If any excluded extensions are specified, they |
|
142 | + * will be ignored. |
|
143 | + * |
|
144 | + * @param string[] $extensions Extension names, without dot (`php` for example). |
|
145 | + * @return FileHelper_FileFinder |
|
146 | + * @see FileHelper_FileFinder::includeExtension() |
|
147 | + */ |
|
148 | 148 | public function includeExtensions(array $extensions) : FileHelper_FileFinder |
149 | 149 | { |
150 | 150 | $items = $this->getIncludeExtensions(); |
@@ -155,37 +155,37 @@ discard block |
||
155 | 155 | return $this; |
156 | 156 | } |
157 | 157 | |
158 | - /** |
|
159 | - * Retrieves a list of all extensions currently set as |
|
160 | - * excluded from the search. |
|
161 | - * |
|
162 | - * @return string[] |
|
163 | - */ |
|
158 | + /** |
|
159 | + * Retrieves a list of all extensions currently set as |
|
160 | + * excluded from the search. |
|
161 | + * |
|
162 | + * @return string[] |
|
163 | + */ |
|
164 | 164 | public function getExcludeExtensions() : array |
165 | 165 | { |
166 | 166 | return $this->getArrayOption(self::OPTION_EXCLUDE_EXTENSIONS); |
167 | 167 | } |
168 | 168 | |
169 | - /** |
|
170 | - * Excludes a single extension from the search. |
|
171 | - * |
|
172 | - * @param string $extension Extension name, without dot (`php` for example). |
|
173 | - * @return FileHelper_FileFinder |
|
174 | - * @see FileHelper_FileFinder::excludeExtensions() |
|
175 | - */ |
|
169 | + /** |
|
170 | + * Excludes a single extension from the search. |
|
171 | + * |
|
172 | + * @param string $extension Extension name, without dot (`php` for example). |
|
173 | + * @return FileHelper_FileFinder |
|
174 | + * @see FileHelper_FileFinder::excludeExtensions() |
|
175 | + */ |
|
176 | 176 | public function excludeExtension(string $extension) : FileHelper_FileFinder |
177 | 177 | { |
178 | 178 | return $this->excludeExtensions(array($extension)); |
179 | 179 | } |
180 | 180 | |
181 | - /** |
|
182 | - * Add several extensions to the list of extensions to |
|
183 | - * exclude from the file search. |
|
184 | - * |
|
185 | - * @param string[] $extensions Extension names, without dot (`php` for example). |
|
186 | - * @return FileHelper_FileFinder |
|
187 | - * @see FileHelper_FileFinder::excludeExtension() |
|
188 | - */ |
|
181 | + /** |
|
182 | + * Add several extensions to the list of extensions to |
|
183 | + * exclude from the file search. |
|
184 | + * |
|
185 | + * @param string[] $extensions Extension names, without dot (`php` for example). |
|
186 | + * @return FileHelper_FileFinder |
|
187 | + * @see FileHelper_FileFinder::excludeExtension() |
|
188 | + */ |
|
189 | 189 | public function excludeExtensions(array $extensions) : FileHelper_FileFinder |
190 | 190 | { |
191 | 191 | $items = $this->getExcludeExtensions(); |
@@ -196,52 +196,52 @@ discard block |
||
196 | 196 | return $this; |
197 | 197 | } |
198 | 198 | |
199 | - /** |
|
200 | - * In this mode, the entire path to the file will be stripped, |
|
201 | - * leaving only the file name in the files list. |
|
202 | - * |
|
203 | - * @return FileHelper_FileFinder |
|
204 | - */ |
|
199 | + /** |
|
200 | + * In this mode, the entire path to the file will be stripped, |
|
201 | + * leaving only the file name in the files list. |
|
202 | + * |
|
203 | + * @return FileHelper_FileFinder |
|
204 | + */ |
|
205 | 205 | public function setPathmodeStrip() : FileHelper_FileFinder |
206 | 206 | { |
207 | 207 | return $this->setPathmode(self::PATH_MODE_STRIP); |
208 | 208 | } |
209 | 209 | |
210 | - /** |
|
211 | - * In this mode, only the path relative to the source folder |
|
212 | - * will be included in the files list. |
|
213 | - * |
|
214 | - * @return FileHelper_FileFinder |
|
215 | - */ |
|
210 | + /** |
|
211 | + * In this mode, only the path relative to the source folder |
|
212 | + * will be included in the files list. |
|
213 | + * |
|
214 | + * @return FileHelper_FileFinder |
|
215 | + */ |
|
216 | 216 | public function setPathmodeRelative() : FileHelper_FileFinder |
217 | 217 | { |
218 | 218 | return $this->setPathmode(self::PATH_MODE_RELATIVE); |
219 | 219 | } |
220 | 220 | |
221 | - /** |
|
222 | - * In this mode, the full, absolute paths to the files will |
|
223 | - * be included in the files list. |
|
224 | - * |
|
225 | - * @return FileHelper_FileFinder |
|
226 | - */ |
|
221 | + /** |
|
222 | + * In this mode, the full, absolute paths to the files will |
|
223 | + * be included in the files list. |
|
224 | + * |
|
225 | + * @return FileHelper_FileFinder |
|
226 | + */ |
|
227 | 227 | public function setPathmodeAbsolute() : FileHelper_FileFinder |
228 | 228 | { |
229 | 229 | return $this->setPathmode(self::PATH_MODE_ABSOLUTE); |
230 | 230 | } |
231 | 231 | |
232 | - /** |
|
233 | - * This sets a character or string to replace the slashes |
|
234 | - * in the paths with. |
|
235 | - * |
|
236 | - * This is used for example in the `getPHPClassNames()` |
|
237 | - * method, to return files from subfolders as class names |
|
238 | - * using the "_" character: |
|
239 | - * |
|
240 | - * Subfolder/To/File.php => Subfolder_To_File.php |
|
241 | - * |
|
242 | - * @param string $character |
|
243 | - * @return FileHelper_FileFinder |
|
244 | - */ |
|
232 | + /** |
|
233 | + * This sets a character or string to replace the slashes |
|
234 | + * in the paths with. |
|
235 | + * |
|
236 | + * This is used for example in the `getPHPClassNames()` |
|
237 | + * method, to return files from subfolders as class names |
|
238 | + * using the "_" character: |
|
239 | + * |
|
240 | + * Subfolder/To/File.php => Subfolder_To_File.php |
|
241 | + * |
|
242 | + * @param string $character |
|
243 | + * @return FileHelper_FileFinder |
|
244 | + */ |
|
245 | 245 | public function setSlashReplacement(string $character) : FileHelper_FileFinder |
246 | 246 | { |
247 | 247 | return $this->setOption('slash-replacement', $character); |
@@ -264,12 +264,12 @@ discard block |
||
264 | 264 | return $this->setOption(self::OPTION_PATHMODE, $mode); |
265 | 265 | } |
266 | 266 | |
267 | - /** |
|
268 | - * Retrieves a list of all matching file names/paths, |
|
269 | - * depending on the selected options. |
|
270 | - * |
|
271 | - * @return string[] |
|
272 | - */ |
|
267 | + /** |
|
268 | + * Retrieves a list of all matching file names/paths, |
|
269 | + * depending on the selected options. |
|
270 | + * |
|
271 | + * @return string[] |
|
272 | + */ |
|
273 | 273 | public function getAll() : array |
274 | 274 | { |
275 | 275 | $this->find($this->path, true); |
@@ -277,24 +277,24 @@ discard block |
||
277 | 277 | return $this->found; |
278 | 278 | } |
279 | 279 | |
280 | - /** |
|
281 | - * Retrieves only PHP files. Can be combined with other |
|
282 | - * options like enabling recursion into subfolders. |
|
283 | - * |
|
284 | - * @return string[] |
|
285 | - */ |
|
280 | + /** |
|
281 | + * Retrieves only PHP files. Can be combined with other |
|
282 | + * options like enabling recursion into subfolders. |
|
283 | + * |
|
284 | + * @return string[] |
|
285 | + */ |
|
286 | 286 | public function getPHPFiles() : array |
287 | 287 | { |
288 | 288 | $this->includeExtensions(array('php')); |
289 | 289 | return $this->getAll(); |
290 | 290 | } |
291 | 291 | |
292 | - /** |
|
293 | - * Generates PHP class names from file paths: it replaces |
|
294 | - * slashes with underscores, and removes file extensions. |
|
295 | - * |
|
296 | - * @return string[] An array of PHP file names without extension. |
|
297 | - */ |
|
292 | + /** |
|
293 | + * Generates PHP class names from file paths: it replaces |
|
294 | + * slashes with underscores, and removes file extensions. |
|
295 | + * |
|
296 | + * @return string[] An array of PHP file names without extension. |
|
297 | + */ |
|
298 | 298 | public function getPHPClassNames() : array |
299 | 299 | { |
300 | 300 | $this->includeExtensions(array('php')); |
@@ -365,13 +365,13 @@ discard block |
||
365 | 365 | return $path; |
366 | 366 | } |
367 | 367 | |
368 | - /** |
|
369 | - * Checks whether the specified extension is allowed |
|
370 | - * with the current settings. |
|
371 | - * |
|
372 | - * @param string $extension |
|
373 | - * @return bool |
|
374 | - */ |
|
368 | + /** |
|
369 | + * Checks whether the specified extension is allowed |
|
370 | + * with the current settings. |
|
371 | + * |
|
372 | + * @param string $extension |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | 375 | protected function filterExclusion(string $extension) : bool |
376 | 376 | { |
377 | 377 | $include = $this->getOption(self::OPTION_INCLUDE_EXTENSIONS); |
@@ -393,12 +393,12 @@ discard block |
||
393 | 393 | return true; |
394 | 394 | } |
395 | 395 | |
396 | - /** |
|
397 | - * Adjusts the path according to the selected path mode. |
|
398 | - * |
|
399 | - * @param string $path |
|
400 | - * @return string |
|
401 | - */ |
|
396 | + /** |
|
397 | + * Adjusts the path according to the selected path mode. |
|
398 | + * |
|
399 | + * @param string $path |
|
400 | + * @return string |
|
401 | + */ |
|
402 | 402 | protected function filterPath(string $path) : string |
403 | 403 | { |
404 | 404 | switch($this->getStringOption(self::OPTION_PATHMODE)) |
@@ -22,44 +22,44 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class FileHelper_PHPClassInfo_Class |
24 | 24 | { |
25 | - /** |
|
26 | - * @var FileHelper_PHPClassInfo |
|
27 | - */ |
|
25 | + /** |
|
26 | + * @var FileHelper_PHPClassInfo |
|
27 | + */ |
|
28 | 28 | protected $info; |
29 | 29 | |
30 | - /** |
|
31 | - * @var bool |
|
32 | - */ |
|
30 | + /** |
|
31 | + * @var bool |
|
32 | + */ |
|
33 | 33 | protected $abstract = false; |
34 | 34 | |
35 | - /** |
|
36 | - * @var bool |
|
37 | - */ |
|
35 | + /** |
|
36 | + * @var bool |
|
37 | + */ |
|
38 | 38 | protected $final = false; |
39 | 39 | |
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | 43 | protected $extends = ''; |
44 | 44 | |
45 | - /** |
|
46 | - * @var string[] |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var string[] |
|
47 | + */ |
|
48 | 48 | protected $implements = array(); |
49 | 49 | |
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | 53 | protected $name; |
54 | 54 | |
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | 58 | protected $declaration; |
59 | 59 | |
60 | - /** |
|
61 | - * @var string |
|
62 | - */ |
|
60 | + /** |
|
61 | + * @var string |
|
62 | + */ |
|
63 | 63 | protected $keyword; |
64 | 64 | |
65 | 65 | /** |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | private $type; |
69 | 69 | |
70 | 70 | /** |
71 | - * @param FileHelper_PHPClassInfo $info The class info instance. |
|
72 | - * @param string $declaration The full class declaration, e.g. "class SomeName extends SomeOtherClass". |
|
73 | - * @param string $keyword The class keyword, if any, i.e. "abstract" or "final". |
|
74 | - */ |
|
71 | + * @param FileHelper_PHPClassInfo $info The class info instance. |
|
72 | + * @param string $declaration The full class declaration, e.g. "class SomeName extends SomeOtherClass". |
|
73 | + * @param string $keyword The class keyword, if any, i.e. "abstract" or "final". |
|
74 | + */ |
|
75 | 75 | public function __construct(FileHelper_PHPClassInfo $info, string $declaration, string $keyword, string $type) |
76 | 76 | { |
77 | 77 | $this->info = $info; |
@@ -82,31 +82,31 @@ discard block |
||
82 | 82 | $this->analyzeCode(); |
83 | 83 | } |
84 | 84 | |
85 | - /** |
|
86 | - * Check if this class is a subclass of the specified |
|
87 | - * class name. |
|
88 | - * |
|
89 | - * @param string $className |
|
90 | - * @return bool |
|
91 | - */ |
|
85 | + /** |
|
86 | + * Check if this class is a subclass of the specified |
|
87 | + * class name. |
|
88 | + * |
|
89 | + * @param string $className |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | 92 | public function isSublassOf(string $className) : bool |
93 | 93 | { |
94 | 94 | return is_subclass_of($this->getNameNS(), $className); |
95 | 95 | } |
96 | 96 | |
97 | - /** |
|
98 | - * The class name without namespace. |
|
99 | - * @return string |
|
100 | - */ |
|
97 | + /** |
|
98 | + * The class name without namespace. |
|
99 | + * @return string |
|
100 | + */ |
|
101 | 101 | public function getName() : string |
102 | 102 | { |
103 | 103 | return $this->name; |
104 | 104 | } |
105 | 105 | |
106 | - /** |
|
107 | - * The absolute class name with namespace (if any). |
|
108 | - * @return string |
|
109 | - */ |
|
106 | + /** |
|
107 | + * The absolute class name with namespace (if any). |
|
108 | + * @return string |
|
109 | + */ |
|
110 | 110 | public function getNameNS() : string |
111 | 111 | { |
112 | 112 | $name = $this->getName(); |
@@ -118,48 +118,48 @@ discard block |
||
118 | 118 | return $name; |
119 | 119 | } |
120 | 120 | |
121 | - /** |
|
122 | - * Whether it is an abstract class. |
|
123 | - * @return bool |
|
124 | - */ |
|
121 | + /** |
|
122 | + * Whether it is an abstract class. |
|
123 | + * @return bool |
|
124 | + */ |
|
125 | 125 | public function isAbstract() : bool |
126 | 126 | { |
127 | 127 | return $this->abstract; |
128 | 128 | } |
129 | 129 | |
130 | - /** |
|
131 | - * Whether it is a final class. |
|
132 | - * @return bool |
|
133 | - */ |
|
130 | + /** |
|
131 | + * Whether it is a final class. |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | 134 | public function isFinal() : bool |
135 | 135 | { |
136 | 136 | return $this->final; |
137 | 137 | } |
138 | 138 | |
139 | - /** |
|
140 | - * The name of the class that this class extends (with namespace, if specified). |
|
141 | - * @return string |
|
142 | - */ |
|
139 | + /** |
|
140 | + * The name of the class that this class extends (with namespace, if specified). |
|
141 | + * @return string |
|
142 | + */ |
|
143 | 143 | public function getExtends() : string |
144 | 144 | { |
145 | 145 | return $this->extends; |
146 | 146 | } |
147 | 147 | |
148 | - /** |
|
149 | - * A list of interfaces the class implements, if any. |
|
150 | - * @return string[] |
|
151 | - */ |
|
148 | + /** |
|
149 | + * A list of interfaces the class implements, if any. |
|
150 | + * @return string[] |
|
151 | + */ |
|
152 | 152 | public function getImplements() : array |
153 | 153 | { |
154 | 154 | return $this->implements; |
155 | 155 | } |
156 | 156 | |
157 | - /** |
|
158 | - * The class declaration string, with normalized spaces and sorted interface names. |
|
159 | - * NOTE: does not include the keyword "abstract" or "final". |
|
160 | - * |
|
161 | - * @return string |
|
162 | - */ |
|
157 | + /** |
|
158 | + * The class declaration string, with normalized spaces and sorted interface names. |
|
159 | + * NOTE: does not include the keyword "abstract" or "final". |
|
160 | + * |
|
161 | + * @return string |
|
162 | + */ |
|
163 | 163 | public function getDeclaration() : string |
164 | 164 | { |
165 | 165 | $parts = array(); |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | return implode(' ', $parts); |
180 | 180 | } |
181 | 181 | |
182 | - /** |
|
183 | - * The keyword before "class", e.g. "abstract". |
|
184 | - * @return string |
|
185 | - */ |
|
182 | + /** |
|
183 | + * The keyword before "class", e.g. "abstract". |
|
184 | + * @return string |
|
185 | + */ |
|
186 | 186 | public function getKeyword() : string |
187 | 187 | { |
188 | 188 | return $this->keyword; |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | { |
38 | 38 | public const ERROR_CALLABLE_THREW_ERROR = 99601; |
39 | 39 | |
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | 43 | protected $separator = ' '; |
44 | 44 | |
45 | - /** |
|
46 | - * @var string[] |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var string[] |
|
47 | + */ |
|
48 | 48 | protected $strings = array(); |
49 | 49 | |
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | 53 | protected $mode = 'html'; |
54 | 54 | |
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | 58 | protected $noSpace = '§!§'; |
59 | 59 | |
60 | 60 | public function __construct() |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | |
63 | 63 | } |
64 | 64 | |
65 | - /** |
|
66 | - * Adds a subject as a string. Is ignored if empty. |
|
67 | - * |
|
68 | - * @param string|number|Interface_Stringable|NULL $string |
|
69 | - * @return $this |
|
70 | - */ |
|
65 | + /** |
|
66 | + * Adds a subject as a string. Is ignored if empty. |
|
67 | + * |
|
68 | + * @param string|number|Interface_Stringable|NULL $string |
|
69 | + * @return $this |
|
70 | + */ |
|
71 | 71 | public function add($string) : StringBuilder |
72 | 72 | { |
73 | 73 | $string = (string)$string; |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | return $this; |
81 | 81 | } |
82 | 82 | |
83 | - /** |
|
84 | - * Adds a string without appending an automatic space. |
|
85 | - * |
|
86 | - * @param string|number|Interface_Stringable|NULL $string |
|
87 | - * @return $this |
|
88 | - */ |
|
83 | + /** |
|
84 | + * Adds a string without appending an automatic space. |
|
85 | + * |
|
86 | + * @param string|number|Interface_Stringable|NULL $string |
|
87 | + * @return $this |
|
88 | + */ |
|
89 | 89 | public function nospace($string) : StringBuilder |
90 | 90 | { |
91 | 91 | $flattened = (string)$string; |
@@ -98,46 +98,46 @@ discard block |
||
98 | 98 | return $this; |
99 | 99 | } |
100 | 100 | |
101 | - /** |
|
102 | - * Adds raw HTML code. Does not add an automatic space. |
|
103 | - * |
|
104 | - * @param string|number|Interface_Stringable $html |
|
105 | - * @return $this |
|
106 | - */ |
|
101 | + /** |
|
102 | + * Adds raw HTML code. Does not add an automatic space. |
|
103 | + * |
|
104 | + * @param string|number|Interface_Stringable $html |
|
105 | + * @return $this |
|
106 | + */ |
|
107 | 107 | public function html($html) : StringBuilder |
108 | 108 | { |
109 | 109 | return $this->nospace($html); |
110 | 110 | } |
111 | 111 | |
112 | - /** |
|
113 | - * Adds an unordered list with the specified items. |
|
114 | - * |
|
115 | - * @param array<int,string|number|Interface_Stringable> $items |
|
116 | - * @return $this |
|
117 | - */ |
|
112 | + /** |
|
113 | + * Adds an unordered list with the specified items. |
|
114 | + * |
|
115 | + * @param array<int,string|number|Interface_Stringable> $items |
|
116 | + * @return $this |
|
117 | + */ |
|
118 | 118 | public function ul(array $items) : StringBuilder |
119 | 119 | { |
120 | 120 | return $this->list('ul', $items); |
121 | 121 | } |
122 | 122 | |
123 | - /** |
|
124 | - * Adds an ordered list with the specified items. |
|
125 | - * |
|
126 | - * @param array<int,string|number|Interface_Stringable> $items |
|
127 | - * @return $this |
|
128 | - */ |
|
123 | + /** |
|
124 | + * Adds an ordered list with the specified items. |
|
125 | + * |
|
126 | + * @param array<int,string|number|Interface_Stringable> $items |
|
127 | + * @return $this |
|
128 | + */ |
|
129 | 129 | public function ol(array $items) : StringBuilder |
130 | 130 | { |
131 | 131 | return $this->list('ol', $items); |
132 | 132 | } |
133 | 133 | |
134 | - /** |
|
135 | - * Creates a list tag with the items list. |
|
136 | - * |
|
137 | - * @param string $type The list type, `ol` or `ul`. |
|
138 | - * @param array<int,string|number|Interface_Stringable> $items |
|
139 | - * @return $this |
|
140 | - */ |
|
134 | + /** |
|
135 | + * Creates a list tag with the items list. |
|
136 | + * |
|
137 | + * @param string $type The list type, `ol` or `ul`. |
|
138 | + * @param array<int,string|number|Interface_Stringable> $items |
|
139 | + * @return $this |
|
140 | + */ |
|
141 | 141 | protected function list(string $type, array $items) : StringBuilder |
142 | 142 | { |
143 | 143 | return $this->html(sprintf( |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | )); |
148 | 148 | } |
149 | 149 | |
150 | - /** |
|
151 | - * Add a translated string. |
|
152 | - * |
|
153 | - * @param string $format The native string to translate. |
|
154 | - * @param array<int,mixed> $arguments The variables to inject into the translated string, if any. |
|
155 | - * @return $this |
|
156 | - */ |
|
150 | + /** |
|
151 | + * Add a translated string. |
|
152 | + * |
|
153 | + * @param string $format The native string to translate. |
|
154 | + * @param array<int,mixed> $arguments The variables to inject into the translated string, if any. |
|
155 | + * @return $this |
|
156 | + */ |
|
157 | 157 | public function t(string $format, ...$arguments) : StringBuilder |
158 | 158 | { |
159 | 159 | if(!class_exists('\AppLocalize\Localization')) |
@@ -206,36 +206,36 @@ discard block |
||
206 | 206 | return $this->add(ConvertHelper::duration2string($since)); |
207 | 207 | } |
208 | 208 | |
209 | - /** |
|
210 | - * Adds HTML double quotes around the string. |
|
211 | - * |
|
212 | - * @param string|number|Interface_Stringable $string |
|
213 | - * @return $this |
|
214 | - */ |
|
209 | + /** |
|
210 | + * Adds HTML double quotes around the string. |
|
211 | + * |
|
212 | + * @param string|number|Interface_Stringable $string |
|
213 | + * @return $this |
|
214 | + */ |
|
215 | 215 | public function quote($string) : StringBuilder |
216 | 216 | { |
217 | 217 | return $this->sf('"%s"', (string)$string); |
218 | 218 | } |
219 | 219 | |
220 | - /** |
|
221 | - * Adds a text that is meant as a reference to a UI element, |
|
222 | - * like a menu item, button, etc. |
|
223 | - * |
|
224 | - * @param string|number|Interface_Stringable $string |
|
225 | - * @return $this |
|
226 | - */ |
|
220 | + /** |
|
221 | + * Adds a text that is meant as a reference to a UI element, |
|
222 | + * like a menu item, button, etc. |
|
223 | + * |
|
224 | + * @param string|number|Interface_Stringable $string |
|
225 | + * @return $this |
|
226 | + */ |
|
227 | 227 | public function reference($string) : StringBuilder |
228 | 228 | { |
229 | 229 | return $this->sf('"%s"', $string); |
230 | 230 | } |
231 | 231 | |
232 | - /** |
|
233 | - * Add a string using the `sprintf` method. |
|
234 | - * |
|
235 | - * @param string $format The format string |
|
236 | - * @param string|number|Interface_Stringable ...$arguments The variables to inject |
|
237 | - * @return $this |
|
238 | - */ |
|
232 | + /** |
|
233 | + * Add a string using the `sprintf` method. |
|
234 | + * |
|
235 | + * @param string $format The format string |
|
236 | + * @param string|number|Interface_Stringable ...$arguments The variables to inject |
|
237 | + * @return $this |
|
238 | + */ |
|
239 | 239 | public function sf(string $format, ...$arguments) : StringBuilder |
240 | 240 | { |
241 | 241 | array_unshift($arguments, $format); |
@@ -243,12 +243,12 @@ discard block |
||
243 | 243 | return $this->add(sprintf(...$arguments)); |
244 | 244 | } |
245 | 245 | |
246 | - /** |
|
247 | - * Adds a bold string. |
|
248 | - * |
|
249 | - * @param string|number|Interface_Stringable $string |
|
250 | - * @return $this |
|
251 | - */ |
|
246 | + /** |
|
247 | + * Adds a bold string. |
|
248 | + * |
|
249 | + * @param string|number|Interface_Stringable $string |
|
250 | + * @return $this |
|
251 | + */ |
|
252 | 252 | public function bold($string) : StringBuilder |
253 | 253 | { |
254 | 254 | return $this->sf( |
@@ -257,15 +257,15 @@ discard block |
||
257 | 257 | ); |
258 | 258 | } |
259 | 259 | |
260 | - /** |
|
261 | - * Adds an HTML `<br>` tag. |
|
262 | - * |
|
263 | - * Note: for adding a newline character instead, |
|
264 | - * use {@see StringBuilder::eol()}. |
|
265 | - * |
|
266 | - * @return $this |
|
267 | - * @see StringBuilder::eol() |
|
268 | - */ |
|
260 | + /** |
|
261 | + * Adds an HTML `<br>` tag. |
|
262 | + * |
|
263 | + * Note: for adding a newline character instead, |
|
264 | + * use {@see StringBuilder::eol()}. |
|
265 | + * |
|
266 | + * @return $this |
|
267 | + * @see StringBuilder::eol() |
|
268 | + */ |
|
269 | 269 | public function nl() : StringBuilder |
270 | 270 | { |
271 | 271 | return $this->html('<br>'); |
@@ -282,42 +282,42 @@ discard block |
||
282 | 282 | return $this->nospace(PHP_EOL); |
283 | 283 | } |
284 | 284 | |
285 | - /** |
|
286 | - * Adds the current time, in the format <code>H:i:s</code>. |
|
287 | - * |
|
288 | - * @return $this |
|
289 | - */ |
|
285 | + /** |
|
286 | + * Adds the current time, in the format <code>H:i:s</code>. |
|
287 | + * |
|
288 | + * @return $this |
|
289 | + */ |
|
290 | 290 | public function time() : StringBuilder |
291 | 291 | { |
292 | 292 | return $this->add(date('H:i:s')); |
293 | 293 | } |
294 | 294 | |
295 | - /** |
|
296 | - * Adds the "Note:" text. |
|
297 | - * |
|
298 | - * @return $this |
|
299 | - */ |
|
295 | + /** |
|
296 | + * Adds the "Note:" text. |
|
297 | + * |
|
298 | + * @return $this |
|
299 | + */ |
|
300 | 300 | public function note() : StringBuilder |
301 | 301 | { |
302 | 302 | return $this->t('Note:'); |
303 | 303 | } |
304 | 304 | |
305 | - /** |
|
306 | - * Like {@see StringBuilder::note()}, but as bold text. |
|
307 | - * |
|
308 | - * @return $this |
|
309 | - */ |
|
305 | + /** |
|
306 | + * Like {@see StringBuilder::note()}, but as bold text. |
|
307 | + * |
|
308 | + * @return $this |
|
309 | + */ |
|
310 | 310 | public function noteBold() : StringBuilder |
311 | 311 | { |
312 | 312 | return $this->bold(sb()->note()); |
313 | 313 | } |
314 | 314 | |
315 | - /** |
|
316 | - * Adds the "Hint:" text. |
|
317 | - * |
|
318 | - * @return $this |
|
319 | - * @see StringBuilder::hintBold() |
|
320 | - */ |
|
315 | + /** |
|
316 | + * Adds the "Hint:" text. |
|
317 | + * |
|
318 | + * @return $this |
|
319 | + * @see StringBuilder::hintBold() |
|
320 | + */ |
|
321 | 321 | public function hint() : StringBuilder |
322 | 322 | { |
323 | 323 | return $this->t('Hint:'); |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | return $this->bold(sb()->hint()); |
334 | 334 | } |
335 | 335 | |
336 | - /** |
|
337 | - * Adds two linebreaks. |
|
338 | - * |
|
339 | - * @param StringBuilder_Interface|string|NULL $content |
|
340 | - * @return $this |
|
341 | - */ |
|
336 | + /** |
|
337 | + * Adds two linebreaks. |
|
338 | + * |
|
339 | + * @param StringBuilder_Interface|string|NULL $content |
|
340 | + * @return $this |
|
341 | + */ |
|
342 | 342 | public function para($content=null) : StringBuilder |
343 | 343 | { |
344 | 344 | if($content !== null) { |
@@ -390,12 +390,12 @@ discard block |
||
390 | 390 | return $this->html(HTMLTag::create('a')->renderClose()); |
391 | 391 | } |
392 | 392 | |
393 | - /** |
|
394 | - * Wraps the string in a `code` tag. |
|
395 | - * |
|
396 | - * @param string|number|Interface_Stringable $string |
|
397 | - * @return $this |
|
398 | - */ |
|
393 | + /** |
|
394 | + * Wraps the string in a `code` tag. |
|
395 | + * |
|
396 | + * @param string|number|Interface_Stringable $string |
|
397 | + * @return $this |
|
398 | + */ |
|
399 | 399 | public function code($string) : StringBuilder |
400 | 400 | { |
401 | 401 | return $this->sf( |
@@ -404,24 +404,24 @@ discard block |
||
404 | 404 | ); |
405 | 405 | } |
406 | 406 | |
407 | - /** |
|
408 | - * Wraps the string in a `pre` tag. |
|
409 | - * |
|
410 | - * @param string|number|Interface_Stringable $string |
|
411 | - * @return $this |
|
412 | - */ |
|
407 | + /** |
|
408 | + * Wraps the string in a `pre` tag. |
|
409 | + * |
|
410 | + * @param string|number|Interface_Stringable $string |
|
411 | + * @return $this |
|
412 | + */ |
|
413 | 413 | public function pre($string) : StringBuilder |
414 | 414 | { |
415 | 415 | return $this->sf('<pre>%s</pre>', (string)$string); |
416 | 416 | } |
417 | 417 | |
418 | - /** |
|
419 | - * Wraps the text in a `span` tag with the specified classes. |
|
420 | - * |
|
421 | - * @param string|number|Interface_Stringable $string |
|
422 | - * @param string|string[] $classes |
|
423 | - * @return $this |
|
424 | - */ |
|
418 | + /** |
|
419 | + * Wraps the text in a `span` tag with the specified classes. |
|
420 | + * |
|
421 | + * @param string|number|Interface_Stringable $string |
|
422 | + * @param string|string[] $classes |
|
423 | + * @return $this |
|
424 | + */ |
|
425 | 425 | public function spanned($string, $classes) : StringBuilder |
426 | 426 | { |
427 | 427 | if(!is_array($classes)) |
@@ -50,53 +50,53 @@ discard block |
||
50 | 50 | public const COLORFORMAT_HEX = 2; |
51 | 51 | |
52 | 52 | /** |
53 | - * @var string |
|
54 | - */ |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $file; |
56 | 56 | |
57 | - /** |
|
58 | - * @var ImageHelper_Size |
|
59 | - */ |
|
57 | + /** |
|
58 | + * @var ImageHelper_Size |
|
59 | + */ |
|
60 | 60 | protected $info; |
61 | 61 | |
62 | - /** |
|
63 | - * @var string |
|
64 | - */ |
|
62 | + /** |
|
63 | + * @var string |
|
64 | + */ |
|
65 | 65 | protected $type; |
66 | 66 | |
67 | - /** |
|
68 | - * @var resource|NULL |
|
69 | - */ |
|
67 | + /** |
|
68 | + * @var resource|NULL |
|
69 | + */ |
|
70 | 70 | protected $newImage; |
71 | 71 | |
72 | - /** |
|
73 | - * @var resource |
|
74 | - */ |
|
72 | + /** |
|
73 | + * @var resource |
|
74 | + */ |
|
75 | 75 | protected $sourceImage; |
76 | 76 | |
77 | - /** |
|
78 | - * @var int |
|
79 | - */ |
|
77 | + /** |
|
78 | + * @var int |
|
79 | + */ |
|
80 | 80 | protected $width; |
81 | 81 | |
82 | - /** |
|
83 | - * @var int |
|
84 | - */ |
|
82 | + /** |
|
83 | + * @var int |
|
84 | + */ |
|
85 | 85 | protected $height; |
86 | 86 | |
87 | - /** |
|
88 | - * @var int |
|
89 | - */ |
|
87 | + /** |
|
88 | + * @var int |
|
89 | + */ |
|
90 | 90 | protected $newWidth = 0; |
91 | 91 | |
92 | - /** |
|
93 | - * @var int |
|
94 | - */ |
|
92 | + /** |
|
93 | + * @var int |
|
94 | + */ |
|
95 | 95 | protected $newHeight = 0; |
96 | 96 | |
97 | - /** |
|
98 | - * @var int |
|
99 | - */ |
|
97 | + /** |
|
98 | + * @var int |
|
99 | + */ |
|
100 | 100 | protected $quality = 85; |
101 | 101 | |
102 | 102 | /** |
@@ -201,17 +201,17 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - /** |
|
205 | - * Factory method: creates a new helper with a blank image. |
|
206 | - * |
|
207 | - * @param integer $width |
|
208 | - * @param integer $height |
|
209 | - * @param string $type The target file type when saving |
|
210 | - * @return ImageHelper |
|
211 | - * @throws ImageHelper_Exception |
|
212 | - * |
|
213 | - * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
214 | - */ |
|
204 | + /** |
|
205 | + * Factory method: creates a new helper with a blank image. |
|
206 | + * |
|
207 | + * @param integer $width |
|
208 | + * @param integer $height |
|
209 | + * @param string $type The target file type when saving |
|
210 | + * @return ImageHelper |
|
211 | + * @throws ImageHelper_Exception |
|
212 | + * |
|
213 | + * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
214 | + */ |
|
215 | 215 | public static function createNew($width, $height, $type='png') |
216 | 216 | { |
217 | 217 | $img = imagecreatetruecolor($width, $height); |
@@ -226,18 +226,18 @@ discard block |
||
226 | 226 | ); |
227 | 227 | } |
228 | 228 | |
229 | - /** |
|
230 | - * Factory method: creates an image helper from an |
|
231 | - * existing image resource. |
|
232 | - * |
|
233 | - * Note: while the resource is type independent, the |
|
234 | - * type parameter is required for some methods, as well |
|
235 | - * as to be able to save the image. |
|
236 | - * |
|
237 | - * @param resource $resource |
|
238 | - * @param string $type The target image type, e.g. "jpeg", "png", etc. |
|
239 | - * @return ImageHelper |
|
240 | - */ |
|
229 | + /** |
|
230 | + * Factory method: creates an image helper from an |
|
231 | + * existing image resource. |
|
232 | + * |
|
233 | + * Note: while the resource is type independent, the |
|
234 | + * type parameter is required for some methods, as well |
|
235 | + * as to be able to save the image. |
|
236 | + * |
|
237 | + * @param resource $resource |
|
238 | + * @param string $type The target image type, e.g. "jpeg", "png", etc. |
|
239 | + * @return ImageHelper |
|
240 | + */ |
|
241 | 241 | public static function createFromResource($resource, ?string $type=null) |
242 | 242 | { |
243 | 243 | self::requireResource($resource); |
@@ -245,29 +245,29 @@ discard block |
||
245 | 245 | return new ImageHelper(null, $resource, $type); |
246 | 246 | } |
247 | 247 | |
248 | - /** |
|
249 | - * Factory method: creates an image helper from an |
|
250 | - * image file on disk. |
|
251 | - * |
|
252 | - * @param string $file |
|
253 | - * @return ImageHelper |
|
254 | - */ |
|
248 | + /** |
|
249 | + * Factory method: creates an image helper from an |
|
250 | + * image file on disk. |
|
251 | + * |
|
252 | + * @param string $file |
|
253 | + * @return ImageHelper |
|
254 | + */ |
|
255 | 255 | public static function createFromFile(string $file) : ImageHelper |
256 | 256 | { |
257 | 257 | return new ImageHelper($file); |
258 | 258 | } |
259 | 259 | |
260 | - /** |
|
261 | - * Sets a global image helper configuration value. Available |
|
262 | - * configuration settings are: |
|
263 | - * |
|
264 | - * <ul> |
|
265 | - * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether totry and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
266 | - * </ul> |
|
267 | - * |
|
268 | - * @param string $name |
|
269 | - * @param mixed $value |
|
270 | - */ |
|
260 | + /** |
|
261 | + * Sets a global image helper configuration value. Available |
|
262 | + * configuration settings are: |
|
263 | + * |
|
264 | + * <ul> |
|
265 | + * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether totry and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
266 | + * </ul> |
|
267 | + * |
|
268 | + * @param string $name |
|
269 | + * @param mixed $value |
|
270 | + */ |
|
271 | 271 | public static function setConfig($name, $value) |
272 | 272 | { |
273 | 273 | if(isset(self::$config[$name])) { |
@@ -275,22 +275,22 @@ discard block |
||
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | - /** |
|
279 | - * Shorthand for setting the automatic memory adjustment |
|
280 | - * global configuration setting. |
|
281 | - * |
|
282 | - * @param bool $enabled |
|
283 | - */ |
|
278 | + /** |
|
279 | + * Shorthand for setting the automatic memory adjustment |
|
280 | + * global configuration setting. |
|
281 | + * |
|
282 | + * @param bool $enabled |
|
283 | + */ |
|
284 | 284 | public static function setAutoMemoryAdjustment($enabled=true) |
285 | 285 | { |
286 | 286 | self::setConfig('auto-memory-adjustment', $enabled); |
287 | 287 | } |
288 | 288 | |
289 | - /** |
|
290 | - * Duplicates an image resource. |
|
291 | - * @param resource $img |
|
292 | - * @return resource |
|
293 | - */ |
|
289 | + /** |
|
290 | + * Duplicates an image resource. |
|
291 | + * @param resource $img |
|
292 | + * @return resource |
|
293 | + */ |
|
294 | 294 | protected function duplicateImage($img) |
295 | 295 | { |
296 | 296 | self::requireResource($img); |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | return $duplicate; |
303 | 303 | } |
304 | 304 | |
305 | - /** |
|
306 | - * Duplicates the current state of the image into a new |
|
307 | - * image helper instance. |
|
308 | - * |
|
309 | - * @return ImageHelper |
|
310 | - */ |
|
305 | + /** |
|
306 | + * Duplicates the current state of the image into a new |
|
307 | + * image helper instance. |
|
308 | + * |
|
309 | + * @return ImageHelper |
|
310 | + */ |
|
311 | 311 | public function duplicate() |
312 | 312 | { |
313 | 313 | return ImageHelper::createFromResource($this->duplicateImage($this->newImage)); |
@@ -495,13 +495,13 @@ discard block |
||
495 | 495 | )); |
496 | 496 | } |
497 | 497 | |
498 | - /** |
|
499 | - * Resamples the image to a new width, maintaining |
|
500 | - * aspect ratio. |
|
501 | - * |
|
502 | - * @param int $width |
|
503 | - * @return ImageHelper |
|
504 | - */ |
|
498 | + /** |
|
499 | + * Resamples the image to a new width, maintaining |
|
500 | + * aspect ratio. |
|
501 | + * |
|
502 | + * @param int $width |
|
503 | + * @return ImageHelper |
|
504 | + */ |
|
505 | 505 | public function resampleByWidth(int $width) : ImageHelper |
506 | 506 | { |
507 | 507 | $size = $this->getSizeByWidth($width); |
@@ -511,12 +511,12 @@ discard block |
||
511 | 511 | return $this; |
512 | 512 | } |
513 | 513 | |
514 | - /** |
|
515 | - * Resamples the image by height, and creates a new image file on disk. |
|
516 | - * |
|
517 | - * @param int $height |
|
518 | - * @return ImageHelper |
|
519 | - */ |
|
514 | + /** |
|
515 | + * Resamples the image by height, and creates a new image file on disk. |
|
516 | + * |
|
517 | + * @param int $height |
|
518 | + * @return ImageHelper |
|
519 | + */ |
|
520 | 520 | public function resampleByHeight($height) : ImageHelper |
521 | 521 | { |
522 | 522 | $size = $this->getSizeByHeight($height); |
@@ -524,13 +524,13 @@ discard block |
||
524 | 524 | return $this->resampleImage($size->getWidth(), $size->getHeight()); |
525 | 525 | } |
526 | 526 | |
527 | - /** |
|
528 | - * Resamples the image without keeping the aspect ratio. |
|
529 | - * |
|
530 | - * @param int $width |
|
531 | - * @param int $height |
|
532 | - * @return ImageHelper |
|
533 | - */ |
|
527 | + /** |
|
528 | + * Resamples the image without keeping the aspect ratio. |
|
529 | + * |
|
530 | + * @param int $width |
|
531 | + * @param int $height |
|
532 | + * @return ImageHelper |
|
533 | + */ |
|
534 | 534 | public function resample(?int $width = null, ?int $height = null) : ImageHelper |
535 | 535 | { |
536 | 536 | if($this->isVector()) { |
@@ -595,12 +595,12 @@ discard block |
||
595 | 595 | |
596 | 596 | protected $alpha = false; |
597 | 597 | |
598 | - /** |
|
599 | - * Configures the specified image resource to make it alpha compatible. |
|
600 | - * |
|
601 | - * @param resource $canvas |
|
602 | - * @param bool $fill Whether to fill the whole canvas with the transparency |
|
603 | - */ |
|
598 | + /** |
|
599 | + * Configures the specified image resource to make it alpha compatible. |
|
600 | + * |
|
601 | + * @param resource $canvas |
|
602 | + * @param bool $fill Whether to fill the whole canvas with the transparency |
|
603 | + */ |
|
604 | 604 | public static function addAlphaSupport($canvas, $fill=true) |
605 | 605 | { |
606 | 606 | self::requireResource($canvas); |
@@ -715,12 +715,12 @@ discard block |
||
715 | 715 | $this->quality = $quality * 1; |
716 | 716 | } |
717 | 717 | |
718 | - /** |
|
719 | - * Attempts to adjust the memory to the required size |
|
720 | - * to work with the current image. |
|
721 | - * |
|
722 | - * @return boolean |
|
723 | - */ |
|
718 | + /** |
|
719 | + * Attempts to adjust the memory to the required size |
|
720 | + * to work with the current image. |
|
721 | + * |
|
722 | + * @return boolean |
|
723 | + */ |
|
724 | 724 | protected function adjustMemory() : bool |
725 | 725 | { |
726 | 726 | if(!self::$config['auto-memory-adjustment']) { |
@@ -760,27 +760,27 @@ discard block |
||
760 | 760 | return false; |
761 | 761 | } |
762 | 762 | |
763 | - /** |
|
764 | - * Stretches the image to the specified dimensions. |
|
765 | - * |
|
766 | - * @param int $width |
|
767 | - * @param int $height |
|
768 | - * @return ImageHelper |
|
769 | - */ |
|
763 | + /** |
|
764 | + * Stretches the image to the specified dimensions. |
|
765 | + * |
|
766 | + * @param int $width |
|
767 | + * @param int $height |
|
768 | + * @return ImageHelper |
|
769 | + */ |
|
770 | 770 | public function stretch(int $width, int $height) : ImageHelper |
771 | 771 | { |
772 | 772 | return $this->resampleImage($width, $height); |
773 | 773 | } |
774 | 774 | |
775 | - /** |
|
776 | - * Creates a new image from the current image, |
|
777 | - * resampling it to the new size. |
|
778 | - * |
|
779 | - * @param int $newWidth |
|
780 | - * @param int $newHeight |
|
781 | - * @throws ImageHelper_Exception |
|
782 | - * @return ImageHelper |
|
783 | - */ |
|
775 | + /** |
|
776 | + * Creates a new image from the current image, |
|
777 | + * resampling it to the new size. |
|
778 | + * |
|
779 | + * @param int $newWidth |
|
780 | + * @param int $newHeight |
|
781 | + * @throws ImageHelper_Exception |
|
782 | + * @return ImageHelper |
|
783 | + */ |
|
784 | 784 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
785 | 785 | { |
786 | 786 | if($this->isVector()) { |
@@ -849,17 +849,17 @@ discard block |
||
849 | 849 | return array_unique($types); |
850 | 850 | } |
851 | 851 | |
852 | - /** |
|
853 | - * Displays an existing image resource. |
|
854 | - * |
|
855 | - * @param resource $resource |
|
856 | - * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
857 | - * @param int $quality The quality to use for the image. This is 0-9 (0=no compression, 9=max) for PNG, and 0-100 (0=lowest, 100=highest quality) for JPG |
|
858 | - * |
|
859 | - * @throws ImageHelper_Exception |
|
860 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
861 | - * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
862 | - */ |
|
852 | + /** |
|
853 | + * Displays an existing image resource. |
|
854 | + * |
|
855 | + * @param resource $resource |
|
856 | + * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
857 | + * @param int $quality The quality to use for the image. This is 0-9 (0=no compression, 9=max) for PNG, and 0-100 (0=lowest, 100=highest quality) for JPG |
|
858 | + * |
|
859 | + * @throws ImageHelper_Exception |
|
860 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
861 | + * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
862 | + */ |
|
863 | 863 | public static function displayImageStream($resource, string $imageType, int $quality=-1) : void |
864 | 864 | { |
865 | 865 | self::requireResource($resource); |
@@ -942,11 +942,11 @@ discard block |
||
942 | 942 | readfile($imageFile); |
943 | 943 | } |
944 | 944 | |
945 | - /** |
|
946 | - * Displays the current image. |
|
947 | - * |
|
948 | - * NOTE: You must call `exit()` manually after this. |
|
949 | - */ |
|
945 | + /** |
|
946 | + * Displays the current image. |
|
947 | + * |
|
948 | + * NOTE: You must call `exit()` manually after this. |
|
949 | + */ |
|
950 | 950 | public function display() : void |
951 | 951 | { |
952 | 952 | $this->displayImageStream( |
@@ -970,16 +970,16 @@ discard block |
||
970 | 970 | return $this->trimImage($this->newImage, $color); |
971 | 971 | } |
972 | 972 | |
973 | - /** |
|
974 | - * Retrieves a color definition by its index. |
|
975 | - * |
|
976 | - * @param resource $img A valid image resource. |
|
977 | - * @param int $colorIndex The color index, as returned by `imagecolorat` for example. |
|
978 | - * @return array<string,int> An array with red, green, blue and alpha keys. |
|
979 | - * |
|
980 | - * @throws ImageHelper_Exception |
|
981 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
982 | - */ |
|
973 | + /** |
|
974 | + * Retrieves a color definition by its index. |
|
975 | + * |
|
976 | + * @param resource $img A valid image resource. |
|
977 | + * @param int $colorIndex The color index, as returned by `imagecolorat` for example. |
|
978 | + * @return array<string,int> An array with red, green, blue and alpha keys. |
|
979 | + * |
|
980 | + * @throws ImageHelper_Exception |
|
981 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
982 | + */ |
|
983 | 983 | public function getIndexedColors($img, int $colorIndex) : array |
984 | 984 | { |
985 | 985 | self::requireResource($img); |
@@ -999,18 +999,18 @@ discard block |
||
999 | 999 | ); |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - /** |
|
1003 | - * Trims the specified image resource by removing the specified color. |
|
1004 | - * Also works with transparency. |
|
1005 | - * |
|
1006 | - * @param resource $img |
|
1007 | - * @param array|NULL $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used. |
|
1008 | - * @return ImageHelper |
|
1009 | - * |
|
1010 | - * @throws ImageHelper_Exception |
|
1011 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1012 | - * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS |
|
1013 | - */ |
|
1002 | + /** |
|
1003 | + * Trims the specified image resource by removing the specified color. |
|
1004 | + * Also works with transparency. |
|
1005 | + * |
|
1006 | + * @param resource $img |
|
1007 | + * @param array|NULL $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used. |
|
1008 | + * @return ImageHelper |
|
1009 | + * |
|
1010 | + * @throws ImageHelper_Exception |
|
1011 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1012 | + * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS |
|
1013 | + */ |
|
1014 | 1014 | protected function trimImage($img, ?array $color=null) : ImageHelper |
1015 | 1015 | { |
1016 | 1016 | if($this->isVector()) { |
@@ -1118,14 +1118,14 @@ discard block |
||
1118 | 1118 | return $this; |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - /** |
|
1122 | - * Requires the subject to be a resource. |
|
1123 | - * |
|
1124 | - * @param resource|mixed $subject |
|
1125 | - * |
|
1126 | - * @throws ImageHelper_Exception |
|
1127 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1128 | - */ |
|
1121 | + /** |
|
1122 | + * Requires the subject to be a resource. |
|
1123 | + * |
|
1124 | + * @param resource|mixed $subject |
|
1125 | + * |
|
1126 | + * @throws ImageHelper_Exception |
|
1127 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1128 | + */ |
|
1129 | 1129 | protected static function requireResource($subject) : void |
1130 | 1130 | { |
1131 | 1131 | if(is_resource($subject)) { |
@@ -1142,14 +1142,14 @@ discard block |
||
1142 | 1142 | ); |
1143 | 1143 | } |
1144 | 1144 | |
1145 | - /** |
|
1146 | - * Creates a new image resource, with transparent background. |
|
1147 | - * |
|
1148 | - * @param int $width |
|
1149 | - * @param int $height |
|
1150 | - * @throws ImageHelper_Exception |
|
1151 | - * @return resource |
|
1152 | - */ |
|
1145 | + /** |
|
1146 | + * Creates a new image resource, with transparent background. |
|
1147 | + * |
|
1148 | + * @param int $width |
|
1149 | + * @param int $height |
|
1150 | + * @throws ImageHelper_Exception |
|
1151 | + * @return resource |
|
1152 | + */ |
|
1153 | 1153 | protected function createNewImage(int $width, int $height) |
1154 | 1154 | { |
1155 | 1155 | $img = imagecreatetruecolor($width, $height); |
@@ -1168,54 +1168,54 @@ discard block |
||
1168 | 1168 | return $img; |
1169 | 1169 | } |
1170 | 1170 | |
1171 | - /** |
|
1172 | - * Whether the two specified colors are the same. |
|
1173 | - * |
|
1174 | - * @param array<string,int> $a |
|
1175 | - * @param array<string,int> $b |
|
1176 | - * @return boolean |
|
1177 | - */ |
|
1178 | - protected function colorsMatch(array $a, array $b) : bool |
|
1179 | - { |
|
1180 | - $parts = array('red', 'green', 'blue'); |
|
1181 | - foreach($parts as $part) { |
|
1182 | - if($a[$part] != $b[$part]) { |
|
1183 | - return false; |
|
1184 | - } |
|
1185 | - } |
|
1171 | + /** |
|
1172 | + * Whether the two specified colors are the same. |
|
1173 | + * |
|
1174 | + * @param array<string,int> $a |
|
1175 | + * @param array<string,int> $b |
|
1176 | + * @return boolean |
|
1177 | + */ |
|
1178 | + protected function colorsMatch(array $a, array $b) : bool |
|
1179 | + { |
|
1180 | + $parts = array('red', 'green', 'blue'); |
|
1181 | + foreach($parts as $part) { |
|
1182 | + if($a[$part] != $b[$part]) { |
|
1183 | + return false; |
|
1184 | + } |
|
1185 | + } |
|
1186 | 1186 | |
1187 | - return true; |
|
1188 | - } |
|
1187 | + return true; |
|
1188 | + } |
|
1189 | 1189 | |
1190 | - public function fillWhite($x=0, $y=0) |
|
1191 | - { |
|
1192 | - $this->addRGBColor('white', 255, 255, 255); |
|
1190 | + public function fillWhite($x=0, $y=0) |
|
1191 | + { |
|
1192 | + $this->addRGBColor('white', 255, 255, 255); |
|
1193 | 1193 | return $this->fill('white', $x, $y); |
1194 | - } |
|
1194 | + } |
|
1195 | 1195 | |
1196 | - public function fillTransparent() : ImageHelper |
|
1197 | - { |
|
1196 | + public function fillTransparent() : ImageHelper |
|
1197 | + { |
|
1198 | 1198 | $this->enableAlpha(); |
1199 | 1199 | |
1200 | - self::fillImageTransparent($this->newImage); |
|
1200 | + self::fillImageTransparent($this->newImage); |
|
1201 | 1201 | |
1202 | - return $this; |
|
1203 | - } |
|
1202 | + return $this; |
|
1203 | + } |
|
1204 | 1204 | |
1205 | - public static function fillImageTransparent($resource) |
|
1206 | - { |
|
1207 | - self::requireResource($resource); |
|
1205 | + public static function fillImageTransparent($resource) |
|
1206 | + { |
|
1207 | + self::requireResource($resource); |
|
1208 | 1208 | |
1209 | - $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
1210 | - imagecolortransparent ($resource, $transparent); |
|
1211 | - imagefill($resource, 0, 0, $transparent); |
|
1212 | - } |
|
1209 | + $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
1210 | + imagecolortransparent ($resource, $transparent); |
|
1211 | + imagefill($resource, 0, 0, $transparent); |
|
1212 | + } |
|
1213 | 1213 | |
1214 | - public function fill($colorName, $x=0, $y=0) |
|
1215 | - { |
|
1216 | - imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
1217 | - return $this; |
|
1218 | - } |
|
1214 | + public function fill($colorName, $x=0, $y=0) |
|
1215 | + { |
|
1216 | + imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
1217 | + return $this; |
|
1218 | + } |
|
1219 | 1219 | |
1220 | 1220 | protected $colors = array(); |
1221 | 1221 | |
@@ -1236,9 +1236,9 @@ discard block |
||
1236 | 1236 | return $this; |
1237 | 1237 | } |
1238 | 1238 | |
1239 | - /** |
|
1240 | - * @return resource |
|
1241 | - */ |
|
1239 | + /** |
|
1240 | + * @return resource |
|
1241 | + */ |
|
1242 | 1242 | public function getImage() |
1243 | 1243 | { |
1244 | 1244 | return $this->newImage; |
@@ -1256,26 +1256,26 @@ discard block |
||
1256 | 1256 | return $this; |
1257 | 1257 | } |
1258 | 1258 | |
1259 | - /** |
|
1260 | - * Retrieves the size of the image. |
|
1261 | - * |
|
1262 | - * @return ImageHelper_Size |
|
1263 | - * @throws ImageHelper_Exception |
|
1264 | - * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1265 | - */ |
|
1266 | - public function getSize() : ImageHelper_Size |
|
1259 | + /** |
|
1260 | + * Retrieves the size of the image. |
|
1261 | + * |
|
1262 | + * @return ImageHelper_Size |
|
1263 | + * @throws ImageHelper_Exception |
|
1264 | + * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1265 | + */ |
|
1266 | + public function getSize() : ImageHelper_Size |
|
1267 | 1267 | { |
1268 | - return self::getImageSize($this->newImage); |
|
1268 | + return self::getImageSize($this->newImage); |
|
1269 | 1269 | } |
1270 | 1270 | |
1271 | 1271 | protected $TTFFile; |
1272 | 1272 | |
1273 | - /** |
|
1274 | - * Sets the TTF font file to use for text operations. |
|
1275 | - * |
|
1276 | - * @param string $filePath |
|
1277 | - * @return ImageHelper |
|
1278 | - */ |
|
1273 | + /** |
|
1274 | + * Sets the TTF font file to use for text operations. |
|
1275 | + * |
|
1276 | + * @param string $filePath |
|
1277 | + * @return ImageHelper |
|
1278 | + */ |
|
1279 | 1279 | public function setFontTTF($filePath) |
1280 | 1280 | { |
1281 | 1281 | $this->TTFFile = $filePath; |
@@ -1347,63 +1347,63 @@ discard block |
||
1347 | 1347 | return; |
1348 | 1348 | } |
1349 | 1349 | |
1350 | - throw new ImageHelper_Exception( |
|
1350 | + throw new ImageHelper_Exception( |
|
1351 | 1351 | 'No true type font specified', |
1352 | 1352 | 'This functionality requires a TTF font file to be specified with the [setFontTTF] method.', |
1353 | 1353 | self::ERROR_NO_TRUE_TYPE_FONT_SET |
1354 | 1354 | ); |
1355 | 1355 | } |
1356 | 1356 | |
1357 | - /** |
|
1358 | - * Retrieves the size of an image file on disk, or |
|
1359 | - * an existing image resource. |
|
1360 | - * |
|
1361 | - * <pre> |
|
1362 | - * array( |
|
1363 | - * 0: (width), |
|
1364 | - * 1: (height), |
|
1365 | - * "channels": the amount of channels |
|
1366 | - * "bits": bits per channel |
|
1357 | + /** |
|
1358 | + * Retrieves the size of an image file on disk, or |
|
1359 | + * an existing image resource. |
|
1360 | + * |
|
1361 | + * <pre> |
|
1362 | + * array( |
|
1363 | + * 0: (width), |
|
1364 | + * 1: (height), |
|
1365 | + * "channels": the amount of channels |
|
1366 | + * "bits": bits per channel |
|
1367 | 1367 | * ) |
1368 | - * </pre> |
|
1369 | - * |
|
1370 | - * @param string|resource $pathOrResource |
|
1371 | - * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize |
|
1372 | - * @see ImageHelper_Size |
|
1373 | - * @throws ImageHelper_Exception |
|
1374 | - * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1375 | - * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE |
|
1376 | - * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1377 | - * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
|
1378 | - */ |
|
1379 | - public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
1380 | - { |
|
1381 | - if(is_resource($pathOrResource)) |
|
1382 | - { |
|
1383 | - return new ImageHelper_Size(array( |
|
1384 | - 'width' => imagesx($pathOrResource), |
|
1385 | - 'height' => imagesy($pathOrResource), |
|
1386 | - 'channels' => 1, |
|
1387 | - 'bits' => 8 |
|
1388 | - )); |
|
1389 | - } |
|
1368 | + * </pre> |
|
1369 | + * |
|
1370 | + * @param string|resource $pathOrResource |
|
1371 | + * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize |
|
1372 | + * @see ImageHelper_Size |
|
1373 | + * @throws ImageHelper_Exception |
|
1374 | + * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1375 | + * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE |
|
1376 | + * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1377 | + * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
|
1378 | + */ |
|
1379 | + public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
1380 | + { |
|
1381 | + if(is_resource($pathOrResource)) |
|
1382 | + { |
|
1383 | + return new ImageHelper_Size(array( |
|
1384 | + 'width' => imagesx($pathOrResource), |
|
1385 | + 'height' => imagesy($pathOrResource), |
|
1386 | + 'channels' => 1, |
|
1387 | + 'bits' => 8 |
|
1388 | + )); |
|
1389 | + } |
|
1390 | 1390 | |
1391 | - $type = self::getFileImageType($pathOrResource); |
|
1391 | + $type = self::getFileImageType($pathOrResource); |
|
1392 | 1392 | |
1393 | - $info = false; |
|
1394 | - $method = 'getImageSize_'.$type; |
|
1395 | - if(method_exists(__CLASS__, $method)) |
|
1396 | - { |
|
1397 | - $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
|
1398 | - } |
|
1399 | - else |
|
1400 | - { |
|
1401 | - $info = getimagesize($pathOrResource); |
|
1402 | - } |
|
1393 | + $info = false; |
|
1394 | + $method = 'getImageSize_'.$type; |
|
1395 | + if(method_exists(__CLASS__, $method)) |
|
1396 | + { |
|
1397 | + $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
|
1398 | + } |
|
1399 | + else |
|
1400 | + { |
|
1401 | + $info = getimagesize($pathOrResource); |
|
1402 | + } |
|
1403 | 1403 | |
1404 | - if($info !== false) { |
|
1405 | - return new ImageHelper_Size($info); |
|
1406 | - } |
|
1404 | + if($info !== false) { |
|
1405 | + return new ImageHelper_Size($info); |
|
1406 | + } |
|
1407 | 1407 | |
1408 | 1408 | throw new ImageHelper_Exception( |
1409 | 1409 | 'Error opening image file', |
@@ -1413,98 +1413,98 @@ discard block |
||
1413 | 1413 | ), |
1414 | 1414 | self::ERROR_CANNOT_GET_IMAGE_SIZE |
1415 | 1415 | ); |
1416 | - } |
|
1416 | + } |
|
1417 | 1417 | |
1418 | - /** |
|
1419 | - * @param string $imagePath |
|
1420 | - * @throws ImageHelper_Exception |
|
1421 | - * @return array |
|
1422 | - * |
|
1423 | - * @todo This should return a ImageHelper_Size instance. |
|
1424 | - */ |
|
1425 | - protected static function getImageSize_svg(string $imagePath) : array |
|
1426 | - { |
|
1427 | - $xml = XMLHelper::createSimplexml(); |
|
1428 | - $xml->loadFile($imagePath); |
|
1418 | + /** |
|
1419 | + * @param string $imagePath |
|
1420 | + * @throws ImageHelper_Exception |
|
1421 | + * @return array |
|
1422 | + * |
|
1423 | + * @todo This should return a ImageHelper_Size instance. |
|
1424 | + */ |
|
1425 | + protected static function getImageSize_svg(string $imagePath) : array |
|
1426 | + { |
|
1427 | + $xml = XMLHelper::createSimplexml(); |
|
1428 | + $xml->loadFile($imagePath); |
|
1429 | 1429 | |
1430 | - if($xml->hasErrors()) { |
|
1431 | - throw new ImageHelper_Exception( |
|
1432 | - 'Error opening SVG image', |
|
1433 | - sprintf( |
|
1434 | - 'The XML content of the image [%s] could not be parsed.', |
|
1435 | - $imagePath |
|
1430 | + if($xml->hasErrors()) { |
|
1431 | + throw new ImageHelper_Exception( |
|
1432 | + 'Error opening SVG image', |
|
1433 | + sprintf( |
|
1434 | + 'The XML content of the image [%s] could not be parsed.', |
|
1435 | + $imagePath |
|
1436 | 1436 | ), |
1437 | - self::ERROR_CANNOT_READ_SVG_IMAGE |
|
1437 | + self::ERROR_CANNOT_READ_SVG_IMAGE |
|
1438 | 1438 | ); |
1439 | - } |
|
1439 | + } |
|
1440 | 1440 | |
1441 | - $data = $xml->toArray(); |
|
1442 | - $xml->dispose(); |
|
1443 | - unset($xml); |
|
1441 | + $data = $xml->toArray(); |
|
1442 | + $xml->dispose(); |
|
1443 | + unset($xml); |
|
1444 | 1444 | |
1445 | - if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1446 | - throw new ImageHelper_Exception( |
|
1447 | - 'SVG Image is corrupted', |
|
1448 | - sprintf( |
|
1449 | - 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
1450 | - $imagePath |
|
1445 | + if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1446 | + throw new ImageHelper_Exception( |
|
1447 | + 'SVG Image is corrupted', |
|
1448 | + sprintf( |
|
1449 | + 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
1450 | + $imagePath |
|
1451 | 1451 | ), |
1452 | - self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1452 | + self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1453 | 1453 | ); |
1454 | - } |
|
1454 | + } |
|
1455 | 1455 | |
1456 | - $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
1457 | - $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
1456 | + $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
1457 | + $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
1458 | 1458 | |
1459 | - $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
1460 | - $size = explode(',', $viewBox); |
|
1459 | + $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
1460 | + $size = explode(',', $viewBox); |
|
1461 | 1461 | |
1462 | - if(count($size) != 4) |
|
1463 | - { |
|
1464 | - throw new ImageHelper_Exception( |
|
1465 | - 'SVG image has an invalid viewBox attribute', |
|
1466 | - sprintf( |
|
1467 | - 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
1468 | - $viewBox, |
|
1469 | - $imagePath |
|
1462 | + if(count($size) != 4) |
|
1463 | + { |
|
1464 | + throw new ImageHelper_Exception( |
|
1465 | + 'SVG image has an invalid viewBox attribute', |
|
1466 | + sprintf( |
|
1467 | + 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
1468 | + $viewBox, |
|
1469 | + $imagePath |
|
1470 | 1470 | ), |
1471 | - self::ERROR_SVG_VIEWBOX_INVALID |
|
1471 | + self::ERROR_SVG_VIEWBOX_INVALID |
|
1472 | 1472 | ); |
1473 | - } |
|
1473 | + } |
|
1474 | 1474 | |
1475 | - $boxWidth = $size[2]; |
|
1476 | - $boxHeight = $size[3]; |
|
1475 | + $boxWidth = $size[2]; |
|
1476 | + $boxHeight = $size[3]; |
|
1477 | 1477 | |
1478 | - // calculate the x and y units of the document: |
|
1479 | - // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
1480 | - // |
|
1481 | - // The viewbox combined with the width and heigt of the svg |
|
1482 | - // allow calculating how many pixels are in one unit of the |
|
1483 | - // width and height of the document. |
|
1478 | + // calculate the x and y units of the document: |
|
1479 | + // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
1480 | + // |
|
1481 | + // The viewbox combined with the width and heigt of the svg |
|
1482 | + // allow calculating how many pixels are in one unit of the |
|
1483 | + // width and height of the document. |
|
1484 | 1484 | // |
1485 | - $xUnits = $svgWidth / $boxWidth; |
|
1486 | - $yUnits = $svgHeight / $boxHeight; |
|
1485 | + $xUnits = $svgWidth / $boxWidth; |
|
1486 | + $yUnits = $svgHeight / $boxHeight; |
|
1487 | 1487 | |
1488 | - $pxWidth = $xUnits * $svgWidth; |
|
1489 | - $pxHeight = $yUnits * $svgHeight; |
|
1488 | + $pxWidth = $xUnits * $svgWidth; |
|
1489 | + $pxHeight = $yUnits * $svgHeight; |
|
1490 | 1490 | |
1491 | - return array( |
|
1492 | - $pxWidth, |
|
1493 | - $pxHeight, |
|
1494 | - 'bits' => 8 |
|
1495 | - ); |
|
1496 | - } |
|
1491 | + return array( |
|
1492 | + $pxWidth, |
|
1493 | + $pxHeight, |
|
1494 | + 'bits' => 8 |
|
1495 | + ); |
|
1496 | + } |
|
1497 | 1497 | |
1498 | - /** |
|
1499 | - * Crops the image to the specified width and height, optionally |
|
1500 | - * specifying the origin position to crop from. |
|
1501 | - * |
|
1502 | - * @param integer $width |
|
1503 | - * @param integer $height |
|
1504 | - * @param integer $x |
|
1505 | - * @param integer $y |
|
1506 | - * @return ImageHelper |
|
1507 | - */ |
|
1498 | + /** |
|
1499 | + * Crops the image to the specified width and height, optionally |
|
1500 | + * specifying the origin position to crop from. |
|
1501 | + * |
|
1502 | + * @param integer $width |
|
1503 | + * @param integer $height |
|
1504 | + * @param integer $x |
|
1505 | + * @param integer $y |
|
1506 | + * @return ImageHelper |
|
1507 | + */ |
|
1508 | 1508 | public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper |
1509 | 1509 | { |
1510 | 1510 | $new = $this->createNewImage($width, $height); |
@@ -1526,22 +1526,22 @@ discard block |
||
1526 | 1526 | return $this->newHeight; |
1527 | 1527 | } |
1528 | 1528 | |
1529 | - /** |
|
1530 | - * Calculates the average color value used in |
|
1531 | - * the image. Returns an associative array |
|
1532 | - * with the red, green, blue and alpha components, |
|
1533 | - * or a HEX color string depending on the selected |
|
1534 | - * format. |
|
1535 | - * |
|
1536 | - * NOTE: Use the calcAverageColorXXX methods for |
|
1537 | - * strict return types. |
|
1538 | - * |
|
1539 | - * @param int $format The format in which to return the color value. |
|
1540 | - * @return array|string |
|
1541 | - * |
|
1542 | - * @see ImageHelper::calcAverageColorRGB() |
|
1543 | - * @see ImageHelper::calcAverageColorHEX() |
|
1544 | - */ |
|
1529 | + /** |
|
1530 | + * Calculates the average color value used in |
|
1531 | + * the image. Returns an associative array |
|
1532 | + * with the red, green, blue and alpha components, |
|
1533 | + * or a HEX color string depending on the selected |
|
1534 | + * format. |
|
1535 | + * |
|
1536 | + * NOTE: Use the calcAverageColorXXX methods for |
|
1537 | + * strict return types. |
|
1538 | + * |
|
1539 | + * @param int $format The format in which to return the color value. |
|
1540 | + * @return array|string |
|
1541 | + * |
|
1542 | + * @see ImageHelper::calcAverageColorRGB() |
|
1543 | + * @see ImageHelper::calcAverageColorHEX() |
|
1544 | + */ |
|
1545 | 1545 | public function calcAverageColor(int $format=self::COLORFORMAT_RGB) |
1546 | 1546 | { |
1547 | 1547 | $image = $this->duplicate(); |
@@ -1550,35 +1550,35 @@ discard block |
||
1550 | 1550 | return $image->getColorAt(0, 0, $format); |
1551 | 1551 | } |
1552 | 1552 | |
1553 | - /** |
|
1554 | - * Calculates the image's average color value, and |
|
1555 | - * returns an associative array with red, green, |
|
1556 | - * blue and alpha keys. |
|
1557 | - * |
|
1558 | - * @throws ImageHelper_Exception |
|
1559 | - * @return array |
|
1560 | - */ |
|
1553 | + /** |
|
1554 | + * Calculates the image's average color value, and |
|
1555 | + * returns an associative array with red, green, |
|
1556 | + * blue and alpha keys. |
|
1557 | + * |
|
1558 | + * @throws ImageHelper_Exception |
|
1559 | + * @return array |
|
1560 | + */ |
|
1561 | 1561 | public function calcAverageColorRGB() : array |
1562 | 1562 | { |
1563 | - $result = $this->calcAverageColor(self::COLORFORMAT_RGB); |
|
1564 | - if(is_array($result)) { |
|
1565 | - return $result; |
|
1566 | - } |
|
1563 | + $result = $this->calcAverageColor(self::COLORFORMAT_RGB); |
|
1564 | + if(is_array($result)) { |
|
1565 | + return $result; |
|
1566 | + } |
|
1567 | 1567 | |
1568 | - throw new ImageHelper_Exception( |
|
1569 | - 'Unexpected color value', |
|
1570 | - sprintf('Expected an array, got [%s].', gettype($result)), |
|
1571 | - self::ERROR_UNEXPECTED_COLOR_VALUE |
|
1572 | - ); |
|
1568 | + throw new ImageHelper_Exception( |
|
1569 | + 'Unexpected color value', |
|
1570 | + sprintf('Expected an array, got [%s].', gettype($result)), |
|
1571 | + self::ERROR_UNEXPECTED_COLOR_VALUE |
|
1572 | + ); |
|
1573 | 1573 | } |
1574 | 1574 | |
1575 | - /** |
|
1576 | - * Calculates the image's average color value, and |
|
1577 | - * returns a hex color string (without the #). |
|
1578 | - * |
|
1579 | - * @throws ImageHelper_Exception |
|
1580 | - * @return string |
|
1581 | - */ |
|
1575 | + /** |
|
1576 | + * Calculates the image's average color value, and |
|
1577 | + * returns a hex color string (without the #). |
|
1578 | + * |
|
1579 | + * @throws ImageHelper_Exception |
|
1580 | + * @return string |
|
1581 | + */ |
|
1582 | 1582 | public function calcAverageColorHex() : string |
1583 | 1583 | { |
1584 | 1584 | $result = $this->calcAverageColor(self::COLORFORMAT_HEX); |
@@ -1645,12 +1645,12 @@ discard block |
||
1645 | 1645 | return $rgb; |
1646 | 1646 | } |
1647 | 1647 | |
1648 | - /** |
|
1649 | - * Converts an RGB value to its luminance equivalent. |
|
1650 | - * |
|
1651 | - * @param array<string,int> $rgb |
|
1652 | - * @return integer Integer, from 0 to 255 (0=black, 255=white) |
|
1653 | - */ |
|
1648 | + /** |
|
1649 | + * Converts an RGB value to its luminance equivalent. |
|
1650 | + * |
|
1651 | + * @param array<string,int> $rgb |
|
1652 | + * @return integer Integer, from 0 to 255 (0=black, 255=white) |
|
1653 | + */ |
|
1654 | 1654 | public static function rgb2luma(array $rgb) : int |
1655 | 1655 | { |
1656 | 1656 | return (int)floor((($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6); |
@@ -1670,15 +1670,15 @@ discard block |
||
1670 | 1670 | return $luma * 100 / 255; |
1671 | 1671 | } |
1672 | 1672 | |
1673 | - /** |
|
1674 | - * Retrieves an md5 hash of the source image file. |
|
1675 | - * |
|
1676 | - * NOTE: Only works when the helper has been created |
|
1677 | - * from a file. Otherwise, an exception is thrown. |
|
1678 | - * |
|
1679 | - * @return string |
|
1680 | - * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
1681 | - */ |
|
1673 | + /** |
|
1674 | + * Retrieves an md5 hash of the source image file. |
|
1675 | + * |
|
1676 | + * NOTE: Only works when the helper has been created |
|
1677 | + * from a file. Otherwise, an exception is thrown. |
|
1678 | + * |
|
1679 | + * @return string |
|
1680 | + * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
1681 | + */ |
|
1682 | 1682 | public function getHash() : string |
1683 | 1683 | { |
1684 | 1684 | if($this->newImage === null) |