@@ -38,27 +38,27 @@ discard block |
||
| 38 | 38 | public const JS_REGEX_JSON = 'json'; |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * @var array<string,string> |
|
| 42 | - */ |
|
| 41 | + * @var array<string,string> |
|
| 42 | + */ |
|
| 43 | 43 | protected static array $variableCache = array(); |
| 44 | 44 | protected static int $elementCounter = 0; |
| 45 | 45 | protected static string $idPrefix = 'E'; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Builds a javascript statement. The first parameter is the |
|
| 49 | - * javascript function to call, any additional parameters are |
|
| 50 | - * used as arguments for the javascript function call. Variable |
|
| 51 | - * types are automagically converted to the javascript equivalents. |
|
| 52 | - * |
|
| 53 | - * Examples: |
|
| 54 | - * |
|
| 55 | - * // add an alert(); statement: |
|
| 56 | - * JSHelper::buildStatement('alert'); |
|
| 57 | - * |
|
| 58 | - * // add an alert('Alert text'); statement |
|
| 59 | - * JSHelper::buildStatement('alert', 'Alert text'); |
|
| 60 | - * |
|
| 61 | - */ |
|
| 47 | + /** |
|
| 48 | + * Builds a javascript statement. The first parameter is the |
|
| 49 | + * javascript function to call, any additional parameters are |
|
| 50 | + * used as arguments for the javascript function call. Variable |
|
| 51 | + * types are automagically converted to the javascript equivalents. |
|
| 52 | + * |
|
| 53 | + * Examples: |
|
| 54 | + * |
|
| 55 | + * // add an alert(); statement: |
|
| 56 | + * JSHelper::buildStatement('alert'); |
|
| 57 | + * |
|
| 58 | + * // add an alert('Alert text'); statement |
|
| 59 | + * JSHelper::buildStatement('alert', 'Alert text'); |
|
| 60 | + * |
|
| 61 | + */ |
|
| 62 | 62 | public static function buildStatement() : string |
| 63 | 63 | { |
| 64 | 64 | $args = func_get_args(); |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | return call_user_func_array(array(self::class, 'buildStatementQuoteStyle'), $args); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Like {@link JSHelper::buildStatement()}, but using single quotes |
|
| 71 | - * to make it possible to use the statement in an HTML tag attribute. |
|
| 72 | - * |
|
| 73 | - * @return string |
|
| 74 | - * @see JSHelper::buildStatement() |
|
| 75 | - */ |
|
| 69 | + /** |
|
| 70 | + * Like {@link JSHelper::buildStatement()}, but using single quotes |
|
| 71 | + * to make it possible to use the statement in an HTML tag attribute. |
|
| 72 | + * |
|
| 73 | + * @return string |
|
| 74 | + * @see JSHelper::buildStatement() |
|
| 75 | + */ |
|
| 76 | 76 | public static function buildStatementAttribute() : string |
| 77 | 77 | { |
| 78 | 78 | $args = func_get_args(); |
@@ -225,13 +225,13 @@ discard block |
||
| 225 | 225 | return self::phpVariable2JS($variable, self::QUOTE_STYLE_SINGLE); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Generates a dynamic element ID to be used with dynamically generated |
|
| 230 | - * HTML code to tie in with clientside javascript when compact but unique |
|
| 231 | - * IDs are needed in a request. |
|
| 232 | - * |
|
| 233 | - * @return string |
|
| 234 | - */ |
|
| 228 | + /** |
|
| 229 | + * Generates a dynamic element ID to be used with dynamically generated |
|
| 230 | + * HTML code to tie in with clientside javascript when compact but unique |
|
| 231 | + * IDs are needed in a request. |
|
| 232 | + * |
|
| 233 | + * @return string |
|
| 234 | + */ |
|
| 235 | 235 | public static function nextElementID() : string |
| 236 | 236 | { |
| 237 | 237 | self::$elementCounter++; |
@@ -239,33 +239,33 @@ discard block |
||
| 239 | 239 | return self::$idPrefix . self::$elementCounter; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Retrieves the ID prefix currently used. |
|
| 244 | - * |
|
| 245 | - * @return string |
|
| 246 | - */ |
|
| 242 | + /** |
|
| 243 | + * Retrieves the ID prefix currently used. |
|
| 244 | + * |
|
| 245 | + * @return string |
|
| 246 | + */ |
|
| 247 | 247 | public static function getIDPrefix() : string |
| 248 | 248 | { |
| 249 | 249 | return self::$idPrefix; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Retrieves the value of the internal elements counter. |
|
| 254 | - * |
|
| 255 | - * @return integer |
|
| 256 | - */ |
|
| 252 | + /** |
|
| 253 | + * Retrieves the value of the internal elements counter. |
|
| 254 | + * |
|
| 255 | + * @return integer |
|
| 256 | + */ |
|
| 257 | 257 | public static function getElementCounter() : int |
| 258 | 258 | { |
| 259 | 259 | return self::$elementCounter; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * Sets the prefix that is added in front of all IDs |
|
| 264 | - * retrieved using the {@link nextElementID()} method. |
|
| 265 | - * |
|
| 266 | - * @param string $prefix |
|
| 267 | - * @see JSHelper::nextElementID() |
|
| 268 | - */ |
|
| 262 | + /** |
|
| 263 | + * Sets the prefix that is added in front of all IDs |
|
| 264 | + * retrieved using the {@link nextElementID()} method. |
|
| 265 | + * |
|
| 266 | + * @param string $prefix |
|
| 267 | + * @see JSHelper::nextElementID() |
|
| 268 | + */ |
|
| 269 | 269 | public static function setIDPrefix(string $prefix) : void |
| 270 | 270 | { |
| 271 | 271 | self::$idPrefix = $prefix; |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | 'WriteThreshold' => 100 |
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | 46 | protected $file; |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var ZipArchive|NULL |
|
| 50 | - */ |
|
| 48 | + /** |
|
| 49 | + * @var ZipArchive|NULL |
|
| 50 | + */ |
|
| 51 | 51 | protected $zip; |
| 52 | 52 | |
| 53 | 53 | protected bool $open = false; |
@@ -57,35 +57,35 @@ discard block |
||
| 57 | 57 | $this->file = $targetFile; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Sets an option, among the available options: |
|
| 62 | - * |
|
| 63 | - * <ul> |
|
| 64 | - * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
| 65 | - * </ul> |
|
| 66 | - * |
|
| 67 | - * @param string $name |
|
| 68 | - * @param mixed $value |
|
| 69 | - * @return ZIPHelper |
|
| 70 | - */ |
|
| 60 | + /** |
|
| 61 | + * Sets an option, among the available options: |
|
| 62 | + * |
|
| 63 | + * <ul> |
|
| 64 | + * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
| 65 | + * </ul> |
|
| 66 | + * |
|
| 67 | + * @param string $name |
|
| 68 | + * @param mixed $value |
|
| 69 | + * @return ZIPHelper |
|
| 70 | + */ |
|
| 71 | 71 | public function setOption(string $name, $value) : ZIPHelper |
| 72 | 72 | { |
| 73 | 73 | $this->options[$name] = $value; |
| 74 | 74 | return $this; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Adds a file to the zip. By default, the file is stored |
|
| 79 | - * with the same name in the root of the zip. Use the optional |
|
| 80 | - * parameter to change the location in the zip. |
|
| 81 | - * |
|
| 82 | - * @param string $filePath |
|
| 83 | - * @param string|null $zipPath If no path is specified, file will be added with the same name in the ZIP's root. |
|
| 84 | - * @throws ZIPHelper_Exception |
|
| 85 | - * @return bool |
|
| 86 | - * |
|
| 87 | - * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
|
| 88 | - */ |
|
| 77 | + /** |
|
| 78 | + * Adds a file to the zip. By default, the file is stored |
|
| 79 | + * with the same name in the root of the zip. Use the optional |
|
| 80 | + * parameter to change the location in the zip. |
|
| 81 | + * |
|
| 82 | + * @param string $filePath |
|
| 83 | + * @param string|null $zipPath If no path is specified, file will be added with the same name in the ZIP's root. |
|
| 84 | + * @throws ZIPHelper_Exception |
|
| 85 | + * @return bool |
|
| 86 | + * |
|
| 87 | + * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
|
| 88 | + */ |
|
| 89 | 89 | public function addFile(string $filePath, ?string $zipPath=null) : bool |
| 90 | 90 | { |
| 91 | 91 | $this->open(); |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | protected bool $isValid = false; |
| 43 | 43 | protected bool $encodeUTF = false; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var array{code:int,message:string}|NULL |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var array{code:int,message:string}|NULL |
|
| 47 | + */ |
|
| 48 | 48 | protected ?array $error = null; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Stores a list of all unicode characters in the URL |
|
| 52 | - * that have been filtered out before parsing it with |
|
| 53 | - * parse_url. |
|
| 54 | - * |
|
| 55 | - * @var array<string,string> |
|
| 56 | - */ |
|
| 50 | + /** |
|
| 51 | + * Stores a list of all unicode characters in the URL |
|
| 52 | + * that have been filtered out before parsing it with |
|
| 53 | + * parse_url. |
|
| 54 | + * |
|
| 55 | + * @var array<string,string> |
|
| 56 | + */ |
|
| 57 | 57 | protected array $unicodeChars = array(); |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | - * |
|
| 82 | - * @param string $url The target URL. |
|
| 83 | - * @param bool $encodeUTF Whether to URL encode any plain text unicode characters. |
|
| 84 | - */ |
|
| 81 | + * |
|
| 82 | + * @param string $url The target URL. |
|
| 83 | + * @param bool $encodeUTF Whether to URL encode any plain text unicode characters. |
|
| 84 | + */ |
|
| 85 | 85 | public function __construct(string $url, bool $encodeUTF) |
| 86 | 86 | { |
| 87 | 87 | $this->url = $url; |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | $this->validate(); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Retrieves the array as parsed by PHP's parse_url, |
|
| 97 | - * filtered and adjusted as necessary. |
|
| 98 | - * |
|
| 99 | - * @return array<string,mixed> |
|
| 100 | - */ |
|
| 95 | + /** |
|
| 96 | + * Retrieves the array as parsed by PHP's parse_url, |
|
| 97 | + * filtered and adjusted as necessary. |
|
| 98 | + * |
|
| 99 | + * @return array<string,mixed> |
|
| 100 | + */ |
|
| 101 | 101 | public function getInfo() : array |
| 102 | 102 | { |
| 103 | 103 | return $this->info; |
@@ -153,11 +153,11 @@ discard block |
||
| 153 | 153 | $this->url = implode(':', $parts); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Finds any non-url encoded unicode characters in |
|
| 158 | - * the URL, and encodes them before the URL is |
|
| 159 | - * passed to parse_url. |
|
| 160 | - */ |
|
| 156 | + /** |
|
| 157 | + * Finds any non-url encoded unicode characters in |
|
| 158 | + * the URL, and encodes them before the URL is |
|
| 159 | + * passed to parse_url. |
|
| 160 | + */ |
|
| 161 | 161 | protected function filterUnicodeChars() : void |
| 162 | 162 | { |
| 163 | 163 | $chars = ConvertHelper::string2array($this->url); |
@@ -228,23 +228,23 @@ discard block |
||
| 228 | 228 | $this->isValid = true; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - /** |
|
| 232 | - * Goes through all information in the parse_url result |
|
| 233 | - * array, and attempts to fix any user errors in formatting |
|
| 234 | - * that can be recovered from, mostly regarding stray spaces. |
|
| 235 | - */ |
|
| 231 | + /** |
|
| 232 | + * Goes through all information in the parse_url result |
|
| 233 | + * array, and attempts to fix any user errors in formatting |
|
| 234 | + * that can be recovered from, mostly regarding stray spaces. |
|
| 235 | + */ |
|
| 236 | 236 | protected function filterParsed() : void |
| 237 | 237 | { |
| 238 | 238 | $this->info = (new ParsedInfoFilter($this->url, $this->info))->filter(); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Recursively goes through the array, and converts all previously |
|
| 243 | - * URL encoded characters with their unicode character counterparts. |
|
| 244 | - * |
|
| 245 | - * @param array<string,mixed> $subject |
|
| 246 | - * @return array<string,mixed> |
|
| 247 | - */ |
|
| 241 | + /** |
|
| 242 | + * Recursively goes through the array, and converts all previously |
|
| 243 | + * URL encoded characters with their unicode character counterparts. |
|
| 244 | + * |
|
| 245 | + * @param array<string,mixed> $subject |
|
| 246 | + * @return array<string,mixed> |
|
| 247 | + */ |
|
| 248 | 248 | protected function restoreUnicodeChars(array $subject) : array |
| 249 | 249 | { |
| 250 | 250 | $result = array(); |
@@ -268,13 +268,13 @@ discard block |
||
| 268 | 268 | return $result; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Replaces all URL encoded unicode characters |
|
| 273 | - * in the string with the unicode character. |
|
| 274 | - * |
|
| 275 | - * @param string $string |
|
| 276 | - * @return string |
|
| 277 | - */ |
|
| 271 | + /** |
|
| 272 | + * Replaces all URL encoded unicode characters |
|
| 273 | + * in the string with the unicode character. |
|
| 274 | + * |
|
| 275 | + * @param string $string |
|
| 276 | + * @return string |
|
| 277 | + */ |
|
| 278 | 278 | protected function restoreUnicodeChar(string $string) : string |
| 279 | 279 | { |
| 280 | 280 | if(strpos($string, '%') !== false) |
@@ -295,32 +295,32 @@ discard block |
||
| 295 | 295 | ); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Checks whether the URL that was parsed is valid. |
|
| 300 | - * @return bool |
|
| 301 | - */ |
|
| 298 | + /** |
|
| 299 | + * Checks whether the URL that was parsed is valid. |
|
| 300 | + * @return bool |
|
| 301 | + */ |
|
| 302 | 302 | public function isValid() : bool |
| 303 | 303 | { |
| 304 | 304 | return $this->isValid; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * If the validation failed, retrieves the validation |
|
| 309 | - * error message. |
|
| 310 | - * |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 307 | + /** |
|
| 308 | + * If the validation failed, retrieves the validation |
|
| 309 | + * error message. |
|
| 310 | + * |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | 313 | public function getErrorMessage() : string |
| 314 | 314 | { |
| 315 | 315 | return $this->error['message'] ?? ''; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * If the validation failed, retrieves the validation |
|
| 320 | - * error code. |
|
| 321 | - * |
|
| 322 | - * @return int |
|
| 323 | - */ |
|
| 318 | + /** |
|
| 319 | + * If the validation failed, retrieves the validation |
|
| 320 | + * error code. |
|
| 321 | + * |
|
| 322 | + * @return int |
|
| 323 | + */ |
|
| 324 | 324 | public function getErrorCode() : int |
| 325 | 325 | { |
| 326 | 326 | return $this->error['code'] ?? -1; |
@@ -44,42 +44,42 @@ discard block |
||
| 44 | 44 | public const TYPE_URL = 'url'; |
| 45 | 45 | public const TYPE_NONE = 'none'; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * The original URL that was passed to the constructor. |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 47 | + /** |
|
| 48 | + * The original URL that was passed to the constructor. |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | 51 | protected string $rawURL; |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @var array<string,mixed> |
|
| 55 | - */ |
|
| 53 | + /** |
|
| 54 | + * @var array<string,mixed> |
|
| 55 | + */ |
|
| 56 | 56 | protected array $info; |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @var string[] |
|
| 60 | - */ |
|
| 58 | + /** |
|
| 59 | + * @var string[] |
|
| 60 | + */ |
|
| 61 | 61 | protected array $excludedParams = array(); |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var bool |
|
| 65 | - * @see URLInfo::setParamExclusion() |
|
| 66 | - */ |
|
| 63 | + /** |
|
| 64 | + * @var bool |
|
| 65 | + * @see URLInfo::setParamExclusion() |
|
| 66 | + */ |
|
| 67 | 67 | protected bool $paramExclusion = false; |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var array<string,string>|NULL |
|
| 71 | - * @see URLInfo::getTypeLabel() |
|
| 72 | - */ |
|
| 69 | + /** |
|
| 70 | + * @var array<string,string>|NULL |
|
| 71 | + * @see URLInfo::getTypeLabel() |
|
| 72 | + */ |
|
| 73 | 73 | protected static ?array $typeLabels = null; |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var bool |
|
| 77 | - */ |
|
| 75 | + /** |
|
| 76 | + * @var bool |
|
| 77 | + */ |
|
| 78 | 78 | protected bool $highlightExcluded = false; |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @var string[] |
|
| 82 | - */ |
|
| 80 | + /** |
|
| 81 | + * @var string[] |
|
| 82 | + */ |
|
| 83 | 83 | protected array $infoKeys = array( |
| 84 | 84 | 'scheme', |
| 85 | 85 | 'host', |
@@ -91,24 +91,24 @@ discard block |
||
| 91 | 91 | 'fragment' |
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @var string |
|
| 96 | - */ |
|
| 94 | + /** |
|
| 95 | + * @var string |
|
| 96 | + */ |
|
| 97 | 97 | protected string $url; |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @var URIParser |
|
| 101 | - */ |
|
| 99 | + /** |
|
| 100 | + * @var URIParser |
|
| 101 | + */ |
|
| 102 | 102 | protected URIParser $parser; |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @var URINormalizer|NULL |
|
| 106 | - */ |
|
| 104 | + /** |
|
| 105 | + * @var URINormalizer|NULL |
|
| 106 | + */ |
|
| 107 | 107 | protected ?URINormalizer $normalizer = null; |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @var bool |
|
| 111 | - */ |
|
| 109 | + /** |
|
| 110 | + * @var bool |
|
| 111 | + */ |
|
| 112 | 112 | protected bool $encodeUTFChars = false; |
| 113 | 113 | |
| 114 | 114 | public function __construct(string $url) |
@@ -130,14 +130,14 @@ discard block |
||
| 130 | 130 | return $this->parser; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Whether to URL encode any non-encoded UTF8 characters in the URL. |
|
| 135 | - * Default is to leave them as-is for better readability, since |
|
| 136 | - * browsers handle this well. |
|
| 137 | - * |
|
| 138 | - * @param bool $enabled |
|
| 139 | - * @return URLInfo |
|
| 140 | - */ |
|
| 133 | + /** |
|
| 134 | + * Whether to URL encode any non-encoded UTF8 characters in the URL. |
|
| 135 | + * Default is to leave them as-is for better readability, since |
|
| 136 | + * browsers handle this well. |
|
| 137 | + * |
|
| 138 | + * @param bool $enabled |
|
| 139 | + * @return URLInfo |
|
| 140 | + */ |
|
| 141 | 141 | public function setUTFEncoding(bool $enabled=true) : URLInfo |
| 142 | 142 | { |
| 143 | 143 | if($this->encodeUTFChars !== $enabled) |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | return $this->encodeUTFChars; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Filters a URL: removes control characters and the |
|
| 159 | - * like to have a clean URL to work with. |
|
| 160 | - * |
|
| 161 | - * @param string $url |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 157 | + /** |
|
| 158 | + * Filters a URL: removes control characters and the |
|
| 159 | + * like to have a clean URL to work with. |
|
| 160 | + * |
|
| 161 | + * @param string $url |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | 164 | public static function filterURL(string $url) : string |
| 165 | 165 | { |
| 166 | 166 | return URIFilter::filter($url); |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | return $this->info['type'] === self::TYPE_PHONE; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * Whether the URL is a regular URL, not one of the |
|
| 195 | - * other types like a phone number or email address. |
|
| 196 | - * |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 193 | + /** |
|
| 194 | + * Whether the URL is a regular URL, not one of the |
|
| 195 | + * other types like a phone number or email address. |
|
| 196 | + * |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | 199 | public function isURL() : bool |
| 200 | 200 | { |
| 201 | 201 | $host = $this->getHost(); |
@@ -207,20 +207,20 @@ discard block |
||
| 207 | 207 | return $this->parser->isValid(); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Retrieves the host name, or an empty string if none is present. |
|
| 212 | - * |
|
| 213 | - * @return string |
|
| 214 | - */ |
|
| 210 | + /** |
|
| 211 | + * Retrieves the host name, or an empty string if none is present. |
|
| 212 | + * |
|
| 213 | + * @return string |
|
| 214 | + */ |
|
| 215 | 215 | public function getHost() : string |
| 216 | 216 | { |
| 217 | 217 | return $this->getInfoKey('host'); |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Retrieves the path, or an empty string if none is present. |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 220 | + /** |
|
| 221 | + * Retrieves the path, or an empty string if none is present. |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | 224 | public function getPath() : string |
| 225 | 225 | { |
| 226 | 226 | return $this->getInfoKey('path'); |
@@ -236,10 +236,10 @@ discard block |
||
| 236 | 236 | return $this->getInfoKey('scheme'); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Retrieves the port specified in the URL, or -1 if none is present. |
|
| 241 | - * @return int |
|
| 242 | - */ |
|
| 239 | + /** |
|
| 240 | + * Retrieves the port specified in the URL, or -1 if none is present. |
|
| 241 | + * @return int |
|
| 242 | + */ |
|
| 243 | 243 | public function getPort() : int |
| 244 | 244 | { |
| 245 | 245 | $port = $this->getInfoKey('port'); |
@@ -251,13 +251,13 @@ discard block |
||
| 251 | 251 | return -1; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Retrieves the raw query string, or an empty string if none is present. |
|
| 256 | - * |
|
| 257 | - * @return string |
|
| 258 | - * |
|
| 259 | - * @see URLInfo::getParams() |
|
| 260 | - */ |
|
| 254 | + /** |
|
| 255 | + * Retrieves the raw query string, or an empty string if none is present. |
|
| 256 | + * |
|
| 257 | + * @return string |
|
| 258 | + * |
|
| 259 | + * @see URLInfo::getParams() |
|
| 260 | + */ |
|
| 261 | 261 | public function getQuery() : string |
| 262 | 262 | { |
| 263 | 263 | return $this->getInfoKey('query'); |
@@ -273,20 +273,20 @@ discard block |
||
| 273 | 273 | return $this->getInfoKey('pass'); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * Whether the URL contains a port number. |
|
| 278 | - * @return bool |
|
| 279 | - */ |
|
| 276 | + /** |
|
| 277 | + * Whether the URL contains a port number. |
|
| 278 | + * @return bool |
|
| 279 | + */ |
|
| 280 | 280 | public function hasPort() : bool |
| 281 | 281 | { |
| 282 | 282 | return $this->getPort() !== -1; |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * Alias for the hasParams() method. |
|
| 287 | - * @return bool |
|
| 288 | - * @see URLInfo::hasParams() |
|
| 289 | - */ |
|
| 285 | + /** |
|
| 286 | + * Alias for the hasParams() method. |
|
| 287 | + * @return bool |
|
| 288 | + * @see URLInfo::hasParams() |
|
| 289 | + */ |
|
| 290 | 290 | public function hasQuery() : bool |
| 291 | 291 | { |
| 292 | 292 | return $this->hasParams(); |
@@ -331,23 +331,23 @@ discard block |
||
| 331 | 331 | return ''; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * Retrieves a normalized URL: this ensures that all parameters |
|
| 336 | - * in the URL are always in the same order. |
|
| 337 | - * |
|
| 338 | - * @return string |
|
| 339 | - */ |
|
| 334 | + /** |
|
| 335 | + * Retrieves a normalized URL: this ensures that all parameters |
|
| 336 | + * in the URL are always in the same order. |
|
| 337 | + * |
|
| 338 | + * @return string |
|
| 339 | + */ |
|
| 340 | 340 | public function getNormalized() : string |
| 341 | 341 | { |
| 342 | 342 | return $this->normalize(); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - /** |
|
| 346 | - * Like getNormalized(), but if a username and password are present |
|
| 347 | - * in the URL, returns the URL without them. |
|
| 348 | - * |
|
| 349 | - * @return string |
|
| 350 | - */ |
|
| 345 | + /** |
|
| 346 | + * Like getNormalized(), but if a username and password are present |
|
| 347 | + * in the URL, returns the URL without them. |
|
| 348 | + * |
|
| 349 | + * @return string |
|
| 350 | + */ |
|
| 351 | 351 | public function getNormalizedWithoutAuth() : string |
| 352 | 352 | { |
| 353 | 353 | return $this->normalize(false); |
@@ -368,25 +368,25 @@ discard block |
||
| 368 | 368 | return $this->normalizer->normalize(); |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - /** |
|
| 372 | - * Creates a hash of the URL, which can be used for comparisons. |
|
| 373 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
| 374 | - * the same links with a different parameter order will have the |
|
| 375 | - * same hash. |
|
| 376 | - * |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 371 | + /** |
|
| 372 | + * Creates a hash of the URL, which can be used for comparisons. |
|
| 373 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
| 374 | + * the same links with a different parameter order will have the |
|
| 375 | + * same hash. |
|
| 376 | + * |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | 379 | public function getHash() : string |
| 380 | 380 | { |
| 381 | 381 | return ConvertHelper::string2shortHash($this->getNormalized()); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - /** |
|
| 385 | - * Highlights the URL using HTML tags with specific highlighting |
|
| 386 | - * class names. |
|
| 387 | - * |
|
| 388 | - * @return string Will return an empty string if the URL is not valid. |
|
| 389 | - */ |
|
| 384 | + /** |
|
| 385 | + * Highlights the URL using HTML tags with specific highlighting |
|
| 386 | + * class names. |
|
| 387 | + * |
|
| 388 | + * @return string Will return an empty string if the URL is not valid. |
|
| 389 | + */ |
|
| 390 | 390 | public function getHighlighted() : string |
| 391 | 391 | { |
| 392 | 392 | if(!$this->isValid()) { |
@@ -418,15 +418,15 @@ discard block |
||
| 418 | 418 | return count($params); |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * Retrieves all parameters specified in the url, |
|
| 423 | - * if any, as an associative array. |
|
| 424 | - * |
|
| 425 | - * NOTE: Ignores parameters that have been added |
|
| 426 | - * to the excluded parameters list. |
|
| 427 | - * |
|
| 428 | - * @return array<string,string> |
|
| 429 | - */ |
|
| 421 | + /** |
|
| 422 | + * Retrieves all parameters specified in the url, |
|
| 423 | + * if any, as an associative array. |
|
| 424 | + * |
|
| 425 | + * NOTE: Ignores parameters that have been added |
|
| 426 | + * to the excluded parameters list. |
|
| 427 | + * |
|
| 428 | + * @return array<string,string> |
|
| 429 | + */ |
|
| 430 | 430 | public function getParams() : array |
| 431 | 431 | { |
| 432 | 432 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -444,37 +444,37 @@ discard block |
||
| 444 | 444 | return $keep; |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - /** |
|
| 448 | - * Retrieves the names of all parameters present in the URL, if any. |
|
| 449 | - * @return string[] |
|
| 450 | - */ |
|
| 447 | + /** |
|
| 448 | + * Retrieves the names of all parameters present in the URL, if any. |
|
| 449 | + * @return string[] |
|
| 450 | + */ |
|
| 451 | 451 | public function getParamNames() : array |
| 452 | 452 | { |
| 453 | 453 | $params = $this->getParams(); |
| 454 | 454 | return array_keys($params); |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - /** |
|
| 458 | - * Retrieves a specific parameter value from the URL. |
|
| 459 | - * |
|
| 460 | - * @param string $name |
|
| 461 | - * @return string The parameter value, or an empty string if it does not exist. |
|
| 462 | - */ |
|
| 457 | + /** |
|
| 458 | + * Retrieves a specific parameter value from the URL. |
|
| 459 | + * |
|
| 460 | + * @param string $name |
|
| 461 | + * @return string The parameter value, or an empty string if it does not exist. |
|
| 462 | + */ |
|
| 463 | 463 | public function getParam(string $name) : string |
| 464 | 464 | { |
| 465 | 465 | return $this->info['params'][$name] ?? ''; |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - /** |
|
| 469 | - * Excludes a URL parameter entirely if present: |
|
| 470 | - * the parser will act as if the parameter was not |
|
| 471 | - * even present in the source URL, effectively |
|
| 472 | - * stripping it. |
|
| 473 | - * |
|
| 474 | - * @param string $name |
|
| 475 | - * @param string $reason A human-readable explanation why this is excluded - used when highlighting links. |
|
| 476 | - * @return URLInfo |
|
| 477 | - */ |
|
| 468 | + /** |
|
| 469 | + * Excludes a URL parameter entirely if present: |
|
| 470 | + * the parser will act as if the parameter was not |
|
| 471 | + * even present in the source URL, effectively |
|
| 472 | + * stripping it. |
|
| 473 | + * |
|
| 474 | + * @param string $name |
|
| 475 | + * @param string $reason A human-readable explanation why this is excluded - used when highlighting links. |
|
| 476 | + * @return URLInfo |
|
| 477 | + */ |
|
| 478 | 478 | public function excludeParam(string $name, string $reason='') : URLInfo |
| 479 | 479 | { |
| 480 | 480 | if(!isset($this->excludedParams[$name])) |
@@ -529,14 +529,14 @@ discard block |
||
| 529 | 529 | return self::$typeLabels[$this->getType()]; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - /** |
|
| 533 | - * Whether excluded parameters should be highlighted in |
|
| 534 | - * a different color in the URL when using the |
|
| 535 | - * {@link URLInfo::getHighlighted()} method. |
|
| 536 | - * |
|
| 537 | - * @param bool $highlight |
|
| 538 | - * @return URLInfo |
|
| 539 | - */ |
|
| 532 | + /** |
|
| 533 | + * Whether excluded parameters should be highlighted in |
|
| 534 | + * a different color in the URL when using the |
|
| 535 | + * {@link URLInfo::getHighlighted()} method. |
|
| 536 | + * |
|
| 537 | + * @param bool $highlight |
|
| 538 | + * @return URLInfo |
|
| 539 | + */ |
|
| 540 | 540 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
| 541 | 541 | { |
| 542 | 542 | $this->highlightExcluded = $highlight; |
@@ -592,24 +592,24 @@ discard block |
||
| 592 | 592 | return $this; |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | - /** |
|
| 596 | - * Whether the parameter exclusion mode is enabled: |
|
| 597 | - * In this case, if any parameters have been added to the |
|
| 598 | - * exclusion list, all relevant methods will exclude these. |
|
| 599 | - * |
|
| 600 | - * @return bool |
|
| 601 | - */ |
|
| 595 | + /** |
|
| 596 | + * Whether the parameter exclusion mode is enabled: |
|
| 597 | + * In this case, if any parameters have been added to the |
|
| 598 | + * exclusion list, all relevant methods will exclude these. |
|
| 599 | + * |
|
| 600 | + * @return bool |
|
| 601 | + */ |
|
| 602 | 602 | public function isParamExclusionEnabled() : bool |
| 603 | 603 | { |
| 604 | 604 | return $this->paramExclusion; |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | - /** |
|
| 608 | - * Checks whether the link contains any parameters that |
|
| 609 | - * are on the list of excluded parameters. |
|
| 610 | - * |
|
| 611 | - * @return bool |
|
| 612 | - */ |
|
| 607 | + /** |
|
| 608 | + * Checks whether the link contains any parameters that |
|
| 609 | + * are on the list of excluded parameters. |
|
| 610 | + * |
|
| 611 | + * @return bool |
|
| 612 | + */ |
|
| 613 | 613 | public function containsExcludedParams() : bool |
| 614 | 614 | { |
| 615 | 615 | if(empty($this->excludedParams)) { |
@@ -697,26 +697,26 @@ discard block |
||
| 697 | 697 | ->canConnect(); |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - /** |
|
| 701 | - * Creates the connection tester instance that is used |
|
| 702 | - * to check if a URL can be connected to, and which is |
|
| 703 | - * used in the {@see URLInfo::tryConnect()} method. It |
|
| 704 | - * allows more settings to be used. |
|
| 705 | - * |
|
| 706 | - * @return URIConnectionTester |
|
| 707 | - */ |
|
| 700 | + /** |
|
| 701 | + * Creates the connection tester instance that is used |
|
| 702 | + * to check if a URL can be connected to, and which is |
|
| 703 | + * used in the {@see URLInfo::tryConnect()} method. It |
|
| 704 | + * allows more settings to be used. |
|
| 705 | + * |
|
| 706 | + * @return URIConnectionTester |
|
| 707 | + */ |
|
| 708 | 708 | public function createConnectionTester() : URIConnectionTester |
| 709 | 709 | { |
| 710 | 710 | return new URIConnectionTester($this); |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - /** |
|
| 714 | - * Adds/overwrites a URL parameter. |
|
| 715 | - * |
|
| 716 | - * @param string $name |
|
| 717 | - * @param string $val |
|
| 718 | - * @return URLInfo |
|
| 719 | - */ |
|
| 713 | + /** |
|
| 714 | + * Adds/overwrites a URL parameter. |
|
| 715 | + * |
|
| 716 | + * @param string $name |
|
| 717 | + * @param string $val |
|
| 718 | + * @return URLInfo |
|
| 719 | + */ |
|
| 720 | 720 | public function setParam(string $name, string $val) : URLInfo |
| 721 | 721 | { |
| 722 | 722 | $this->info['params'][$name] = $val; |
@@ -724,13 +724,13 @@ discard block |
||
| 724 | 724 | return $this; |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - /** |
|
| 728 | - * Removes a URL parameter. Has no effect if the |
|
| 729 | - * parameter is not present to begin with. |
|
| 730 | - * |
|
| 731 | - * @param string $param |
|
| 732 | - * @return URLInfo |
|
| 733 | - */ |
|
| 727 | + /** |
|
| 728 | + * Removes a URL parameter. Has no effect if the |
|
| 729 | + * parameter is not present to begin with. |
|
| 730 | + * |
|
| 731 | + * @param string $param |
|
| 732 | + * @return URLInfo |
|
| 733 | + */ |
|
| 734 | 734 | public function removeParam(string $param) : URLInfo |
| 735 | 735 | { |
| 736 | 736 | if(isset($this->info['params'][$param])) |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | protected array $colors = array(); |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | - * @var resource|NULL |
|
| 77 | - */ |
|
| 76 | + * @var resource|NULL |
|
| 77 | + */ |
|
| 78 | 78 | protected $newImage; |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @var resource |
|
| 82 | - */ |
|
| 80 | + /** |
|
| 81 | + * @var resource |
|
| 82 | + */ |
|
| 83 | 83 | protected $sourceImage; |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * Factory method: creates a new helper with a blank image. |
|
| 193 | - * |
|
| 194 | - * @param integer $width |
|
| 195 | - * @param integer $height |
|
| 196 | - * @param string $type The target file type when saving |
|
| 197 | - * @return ImageHelper |
|
| 198 | - * @throws ImageHelper_Exception |
|
| 199 | - * |
|
| 200 | - * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
| 201 | - */ |
|
| 191 | + /** |
|
| 192 | + * Factory method: creates a new helper with a blank image. |
|
| 193 | + * |
|
| 194 | + * @param integer $width |
|
| 195 | + * @param integer $height |
|
| 196 | + * @param string $type The target file type when saving |
|
| 197 | + * @return ImageHelper |
|
| 198 | + * @throws ImageHelper_Exception |
|
| 199 | + * |
|
| 200 | + * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
| 201 | + */ |
|
| 202 | 202 | public static function createNew(int $width, int $height, string $type='png') : self |
| 203 | 203 | { |
| 204 | 204 | $img = imagecreatetruecolor($width, $height); |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | return new ImageHelper($file, null, self::getFileImageType($file)); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Sets a global image helper configuration value. Available |
|
| 254 | - * configuration settings are: |
|
| 255 | - * |
|
| 256 | - * <ul> |
|
| 257 | - * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether to try and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
| 258 | - * </ul> |
|
| 259 | - * |
|
| 260 | - * @param string $name |
|
| 261 | - * @param mixed|NULL $value |
|
| 262 | - */ |
|
| 252 | + /** |
|
| 253 | + * Sets a global image helper configuration value. Available |
|
| 254 | + * configuration settings are: |
|
| 255 | + * |
|
| 256 | + * <ul> |
|
| 257 | + * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether to try and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
| 258 | + * </ul> |
|
| 259 | + * |
|
| 260 | + * @param string $name |
|
| 261 | + * @param mixed|NULL $value |
|
| 262 | + */ |
|
| 263 | 263 | public static function setConfig(string $name, $value) : void |
| 264 | 264 | { |
| 265 | 265 | if(isset(self::$config[$name])) { |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Shorthand for setting the automatic memory adjustment |
|
| 272 | - * global configuration setting. |
|
| 273 | - * |
|
| 274 | - * @param bool $enabled |
|
| 275 | - * @return void |
|
| 276 | - */ |
|
| 270 | + /** |
|
| 271 | + * Shorthand for setting the automatic memory adjustment |
|
| 272 | + * global configuration setting. |
|
| 273 | + * |
|
| 274 | + * @param bool $enabled |
|
| 275 | + * @return void |
|
| 276 | + */ |
|
| 277 | 277 | public static function setAutoMemoryAdjustment(bool $enabled=true) : void |
| 278 | 278 | { |
| 279 | 279 | self::setConfig('auto-memory-adjustment', $enabled); |
@@ -747,12 +747,12 @@ discard block |
||
| 747 | 747 | return $this; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - /** |
|
| 751 | - * Attempts to adjust the memory to the required size |
|
| 752 | - * to work with the current image. |
|
| 753 | - * |
|
| 754 | - * @return boolean |
|
| 755 | - */ |
|
| 750 | + /** |
|
| 751 | + * Attempts to adjust the memory to the required size |
|
| 752 | + * to work with the current image. |
|
| 753 | + * |
|
| 754 | + * @return boolean |
|
| 755 | + */ |
|
| 756 | 756 | protected function adjustMemory() : bool |
| 757 | 757 | { |
| 758 | 758 | if(!self::$config['auto-memory-adjustment']) { |
@@ -805,15 +805,15 @@ discard block |
||
| 805 | 805 | return $this->resampleImage($width, $height); |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - /** |
|
| 809 | - * Creates a new image from the current image, |
|
| 810 | - * resampling it to the new size. |
|
| 811 | - * |
|
| 812 | - * @param int $newWidth |
|
| 813 | - * @param int $newHeight |
|
| 814 | - * @throws ImageHelper_Exception |
|
| 815 | - * @return ImageHelper |
|
| 816 | - */ |
|
| 808 | + /** |
|
| 809 | + * Creates a new image from the current image, |
|
| 810 | + * resampling it to the new size. |
|
| 811 | + * |
|
| 812 | + * @param int $newWidth |
|
| 813 | + * @param int $newHeight |
|
| 814 | + * @throws ImageHelper_Exception |
|
| 815 | + * @return ImageHelper |
|
| 816 | + */ |
|
| 817 | 817 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
| 818 | 818 | { |
| 819 | 819 | if($this->isVector()) { |
@@ -885,17 +885,17 @@ discard block |
||
| 885 | 885 | return array_unique($types); |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - /** |
|
| 889 | - * Displays an existing image resource. |
|
| 890 | - * |
|
| 891 | - * @param resource $resource |
|
| 892 | - * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
| 893 | - * @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 |
|
| 894 | - * |
|
| 895 | - * @throws ImageHelper_Exception |
|
| 896 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
| 897 | - * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
| 898 | - */ |
|
| 888 | + /** |
|
| 889 | + * Displays an existing image resource. |
|
| 890 | + * |
|
| 891 | + * @param resource $resource |
|
| 892 | + * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
| 893 | + * @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 |
|
| 894 | + * |
|
| 895 | + * @throws ImageHelper_Exception |
|
| 896 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
| 897 | + * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
| 898 | + */ |
|
| 899 | 899 | public static function displayImageStream($resource, string $imageType, int $quality=-1) : void |
| 900 | 900 | { |
| 901 | 901 | self::requireResource($resource); |
@@ -979,11 +979,11 @@ discard block |
||
| 979 | 979 | readfile($imageFile); |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - /** |
|
| 983 | - * Displays the current image. |
|
| 984 | - * |
|
| 985 | - * NOTE: You must call `exit()` manually after this. |
|
| 986 | - */ |
|
| 982 | + /** |
|
| 983 | + * Displays the current image. |
|
| 984 | + * |
|
| 985 | + * NOTE: You must call `exit()` manually after this. |
|
| 986 | + */ |
|
| 987 | 987 | public function display() : void |
| 988 | 988 | { |
| 989 | 989 | self::displayImageStream( |
@@ -1097,14 +1097,14 @@ discard block |
||
| 1097 | 1097 | return $this; |
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | - /** |
|
| 1101 | - * Requires the subject to be a resource. |
|
| 1102 | - * |
|
| 1103 | - * @param resource|GdImage|mixed $subject |
|
| 1104 | - * |
|
| 1105 | - * @throws ImageHelper_Exception |
|
| 1106 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
| 1107 | - */ |
|
| 1100 | + /** |
|
| 1101 | + * Requires the subject to be a resource. |
|
| 1102 | + * |
|
| 1103 | + * @param resource|GdImage|mixed $subject |
|
| 1104 | + * |
|
| 1105 | + * @throws ImageHelper_Exception |
|
| 1106 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
| 1107 | + */ |
|
| 1108 | 1108 | public static function requireResource($subject) : void |
| 1109 | 1109 | { |
| 1110 | 1110 | if(is_resource($subject) && imagesx($subject)) { |
@@ -1125,14 +1125,14 @@ discard block |
||
| 1125 | 1125 | ); |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | - /** |
|
| 1129 | - * Creates a new image resource, with transparent background. |
|
| 1130 | - * |
|
| 1131 | - * @param int $width |
|
| 1132 | - * @param int $height |
|
| 1133 | - * @throws ImageHelper_Exception |
|
| 1134 | - * @return resource |
|
| 1135 | - */ |
|
| 1128 | + /** |
|
| 1129 | + * Creates a new image resource, with transparent background. |
|
| 1130 | + * |
|
| 1131 | + * @param int $width |
|
| 1132 | + * @param int $height |
|
| 1133 | + * @throws ImageHelper_Exception |
|
| 1134 | + * @return resource |
|
| 1135 | + */ |
|
| 1136 | 1136 | public function createNewImage(int $width, int $height) |
| 1137 | 1137 | { |
| 1138 | 1138 | $img = imagecreatetruecolor($width, $height); |
@@ -1156,38 +1156,38 @@ discard block |
||
| 1156 | 1156 | * @param int $y |
| 1157 | 1157 | * @return $this |
| 1158 | 1158 | */ |
| 1159 | - public function fillWhite(int $x=0, int $y=0) : self |
|
| 1160 | - { |
|
| 1161 | - $this->addRGBColor('white', 255, 255, 255); |
|
| 1159 | + public function fillWhite(int $x=0, int $y=0) : self |
|
| 1160 | + { |
|
| 1161 | + $this->addRGBColor('white', 255, 255, 255); |
|
| 1162 | 1162 | return $this->fill('white', $x, $y); |
| 1163 | - } |
|
| 1163 | + } |
|
| 1164 | 1164 | |
| 1165 | 1165 | /** |
| 1166 | 1166 | * @return $this |
| 1167 | 1167 | * @throws ImageHelper_Exception |
| 1168 | 1168 | */ |
| 1169 | - public function fillTransparent() : self |
|
| 1170 | - { |
|
| 1169 | + public function fillTransparent() : self |
|
| 1170 | + { |
|
| 1171 | 1171 | $this->enableAlpha(); |
| 1172 | 1172 | |
| 1173 | - self::fillImageTransparent($this->newImage); |
|
| 1173 | + self::fillImageTransparent($this->newImage); |
|
| 1174 | 1174 | |
| 1175 | - return $this; |
|
| 1176 | - } |
|
| 1175 | + return $this; |
|
| 1176 | + } |
|
| 1177 | 1177 | |
| 1178 | 1178 | /** |
| 1179 | 1179 | * @param resource $resource |
| 1180 | 1180 | * @return void |
| 1181 | 1181 | * @throws ImageHelper_Exception |
| 1182 | 1182 | */ |
| 1183 | - public static function fillImageTransparent($resource) : void |
|
| 1184 | - { |
|
| 1185 | - self::requireResource($resource); |
|
| 1183 | + public static function fillImageTransparent($resource) : void |
|
| 1184 | + { |
|
| 1185 | + self::requireResource($resource); |
|
| 1186 | 1186 | |
| 1187 | - $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
| 1188 | - imagecolortransparent ($resource, $transparent); |
|
| 1189 | - imagefill($resource, 0, 0, $transparent); |
|
| 1190 | - } |
|
| 1187 | + $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
| 1188 | + imagecolortransparent ($resource, $transparent); |
|
| 1189 | + imagefill($resource, 0, 0, $transparent); |
|
| 1190 | + } |
|
| 1191 | 1191 | |
| 1192 | 1192 | /** |
| 1193 | 1193 | * @param string $colorName |
@@ -1195,11 +1195,11 @@ discard block |
||
| 1195 | 1195 | * @param int $y |
| 1196 | 1196 | * @return $this |
| 1197 | 1197 | */ |
| 1198 | - public function fill(string $colorName, int $x=0, int $y=0) : self |
|
| 1199 | - { |
|
| 1200 | - imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
| 1201 | - return $this; |
|
| 1202 | - } |
|
| 1198 | + public function fill(string $colorName, int $x=0, int $y=0) : self |
|
| 1199 | + { |
|
| 1200 | + imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
| 1201 | + return $this; |
|
| 1202 | + } |
|
| 1203 | 1203 | |
| 1204 | 1204 | /** |
| 1205 | 1205 | * @param string $name |
@@ -1243,9 +1243,9 @@ discard block |
||
| 1243 | 1243 | return $this; |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | - /** |
|
| 1247 | - * @return resource |
|
| 1248 | - */ |
|
| 1246 | + /** |
|
| 1247 | + * @return resource |
|
| 1248 | + */ |
|
| 1249 | 1249 | public function getImage() |
| 1250 | 1250 | { |
| 1251 | 1251 | return $this->newImage; |
@@ -1293,17 +1293,17 @@ discard block |
||
| 1293 | 1293 | * |
| 1294 | 1294 | * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
| 1295 | 1295 | */ |
| 1296 | - public function getSize() : ImageHelper_Size |
|
| 1296 | + public function getSize() : ImageHelper_Size |
|
| 1297 | 1297 | { |
| 1298 | - return self::getImageSize($this->newImage); |
|
| 1298 | + return self::getImageSize($this->newImage); |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | - /** |
|
| 1302 | - * Sets the TTF font file to use for text operations. |
|
| 1303 | - * |
|
| 1304 | - * @param string $filePath |
|
| 1305 | - * @return $this |
|
| 1306 | - */ |
|
| 1301 | + /** |
|
| 1302 | + * Sets the TTF font file to use for text operations. |
|
| 1303 | + * |
|
| 1304 | + * @param string $filePath |
|
| 1305 | + * @return $this |
|
| 1306 | + */ |
|
| 1307 | 1307 | public function setFontTTF(string $filePath) : self |
| 1308 | 1308 | { |
| 1309 | 1309 | $this->TTFFile = $filePath; |
@@ -1381,7 +1381,7 @@ discard block |
||
| 1381 | 1381 | return; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - throw new ImageHelper_Exception( |
|
| 1384 | + throw new ImageHelper_Exception( |
|
| 1385 | 1385 | 'No true type font specified', |
| 1386 | 1386 | 'This functionality requires a TTF font file to be specified with the [setFontTTF] method.', |
| 1387 | 1387 | self::ERROR_NO_TRUE_TYPE_FONT_SET |
@@ -1404,37 +1404,37 @@ discard block |
||
| 1404 | 1404 | * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
| 1405 | 1405 | * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
| 1406 | 1406 | */ |
| 1407 | - public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
| 1408 | - { |
|
| 1409 | - if(is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
| 1410 | - { |
|
| 1411 | - return new ImageHelper_Size(array( |
|
| 1412 | - 'width' => imagesx($pathOrResource), |
|
| 1413 | - 'height' => imagesy($pathOrResource), |
|
| 1414 | - 'channels' => 1, |
|
| 1415 | - 'bits' => 8 |
|
| 1416 | - )); |
|
| 1417 | - } |
|
| 1407 | + public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
| 1408 | + { |
|
| 1409 | + if(is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
| 1410 | + { |
|
| 1411 | + return new ImageHelper_Size(array( |
|
| 1412 | + 'width' => imagesx($pathOrResource), |
|
| 1413 | + 'height' => imagesy($pathOrResource), |
|
| 1414 | + 'channels' => 1, |
|
| 1415 | + 'bits' => 8 |
|
| 1416 | + )); |
|
| 1417 | + } |
|
| 1418 | 1418 | |
| 1419 | - $type = self::getFileImageType($pathOrResource); |
|
| 1419 | + $type = self::getFileImageType($pathOrResource); |
|
| 1420 | 1420 | |
| 1421 | 1421 | $sizeMethods = array( |
| 1422 | 1422 | 'svg' => array(self::class, 'getImageSize_svg') |
| 1423 | 1423 | ); |
| 1424 | 1424 | |
| 1425 | - if(isset($sizeMethods[$type])) |
|
| 1426 | - { |
|
| 1427 | - return ClassHelper::requireObjectInstanceOf( |
|
| 1425 | + if(isset($sizeMethods[$type])) |
|
| 1426 | + { |
|
| 1427 | + return ClassHelper::requireObjectInstanceOf( |
|
| 1428 | 1428 | ImageHelper_Size::class, |
| 1429 | 1429 | $sizeMethods[$type]($pathOrResource) |
| 1430 | 1430 | ); |
| 1431 | - } |
|
| 1431 | + } |
|
| 1432 | 1432 | |
| 1433 | - $info = getimagesize($pathOrResource); |
|
| 1433 | + $info = getimagesize($pathOrResource); |
|
| 1434 | 1434 | |
| 1435 | - if($info !== false) { |
|
| 1436 | - return new ImageHelper_Size($info); |
|
| 1437 | - } |
|
| 1435 | + if($info !== false) { |
|
| 1436 | + return new ImageHelper_Size($info); |
|
| 1437 | + } |
|
| 1438 | 1438 | |
| 1439 | 1439 | throw new ImageHelper_Exception( |
| 1440 | 1440 | 'Error opening image file', |
@@ -1444,7 +1444,7 @@ discard block |
||
| 1444 | 1444 | ), |
| 1445 | 1445 | self::ERROR_CANNOT_GET_IMAGE_SIZE |
| 1446 | 1446 | ); |
| 1447 | - } |
|
| 1447 | + } |
|
| 1448 | 1448 | |
| 1449 | 1449 | /** |
| 1450 | 1450 | * @param string $imagePath |
@@ -1454,78 +1454,78 @@ discard block |
||
| 1454 | 1454 | * @throws XMLHelper_Exception |
| 1455 | 1455 | * @throws JsonException |
| 1456 | 1456 | */ |
| 1457 | - protected static function getImageSize_svg(string $imagePath) : ImageHelper_Size |
|
| 1458 | - { |
|
| 1459 | - $xml = XMLHelper::createSimplexml(); |
|
| 1460 | - $xml->loadFile($imagePath); |
|
| 1457 | + protected static function getImageSize_svg(string $imagePath) : ImageHelper_Size |
|
| 1458 | + { |
|
| 1459 | + $xml = XMLHelper::createSimplexml(); |
|
| 1460 | + $xml->loadFile($imagePath); |
|
| 1461 | 1461 | |
| 1462 | - if($xml->hasErrors()) { |
|
| 1463 | - throw new ImageHelper_Exception( |
|
| 1464 | - 'Error opening SVG image', |
|
| 1465 | - sprintf( |
|
| 1466 | - 'The XML content of the image [%s] could not be parsed.', |
|
| 1467 | - $imagePath |
|
| 1462 | + if($xml->hasErrors()) { |
|
| 1463 | + throw new ImageHelper_Exception( |
|
| 1464 | + 'Error opening SVG image', |
|
| 1465 | + sprintf( |
|
| 1466 | + 'The XML content of the image [%s] could not be parsed.', |
|
| 1467 | + $imagePath |
|
| 1468 | 1468 | ), |
| 1469 | - self::ERROR_CANNOT_READ_SVG_IMAGE |
|
| 1469 | + self::ERROR_CANNOT_READ_SVG_IMAGE |
|
| 1470 | 1470 | ); |
| 1471 | - } |
|
| 1471 | + } |
|
| 1472 | 1472 | |
| 1473 | - $data = $xml->toArray(); |
|
| 1474 | - $xml->dispose(); |
|
| 1475 | - unset($xml); |
|
| 1473 | + $data = $xml->toArray(); |
|
| 1474 | + $xml->dispose(); |
|
| 1475 | + unset($xml); |
|
| 1476 | 1476 | |
| 1477 | - if(!isset($data['@attributes']['viewBox'])) { |
|
| 1478 | - throw new ImageHelper_Exception( |
|
| 1479 | - 'SVG Image is corrupted', |
|
| 1480 | - sprintf( |
|
| 1481 | - 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
| 1482 | - $imagePath |
|
| 1477 | + if(!isset($data['@attributes']['viewBox'])) { |
|
| 1478 | + throw new ImageHelper_Exception( |
|
| 1479 | + 'SVG Image is corrupted', |
|
| 1480 | + sprintf( |
|
| 1481 | + 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
| 1482 | + $imagePath |
|
| 1483 | 1483 | ), |
| 1484 | - self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
| 1484 | + self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
| 1485 | 1485 | ); |
| 1486 | - } |
|
| 1486 | + } |
|
| 1487 | 1487 | |
| 1488 | - $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
| 1489 | - $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
| 1488 | + $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
| 1489 | + $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
| 1490 | 1490 | |
| 1491 | - $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
| 1492 | - $size = explode(',', $viewBox); |
|
| 1491 | + $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
| 1492 | + $size = explode(',', $viewBox); |
|
| 1493 | 1493 | |
| 1494 | - if(count($size) !== 4) |
|
| 1495 | - { |
|
| 1496 | - throw new ImageHelper_Exception( |
|
| 1497 | - 'SVG image has an invalid viewBox attribute', |
|
| 1498 | - sprintf( |
|
| 1499 | - 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
| 1500 | - $viewBox, |
|
| 1501 | - $imagePath |
|
| 1494 | + if(count($size) !== 4) |
|
| 1495 | + { |
|
| 1496 | + throw new ImageHelper_Exception( |
|
| 1497 | + 'SVG image has an invalid viewBox attribute', |
|
| 1498 | + sprintf( |
|
| 1499 | + 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
| 1500 | + $viewBox, |
|
| 1501 | + $imagePath |
|
| 1502 | 1502 | ), |
| 1503 | - self::ERROR_SVG_VIEWBOX_INVALID |
|
| 1503 | + self::ERROR_SVG_VIEWBOX_INVALID |
|
| 1504 | 1504 | ); |
| 1505 | - } |
|
| 1505 | + } |
|
| 1506 | 1506 | |
| 1507 | - $boxWidth = (float)$size[2]; |
|
| 1508 | - $boxHeight = (float)$size[3]; |
|
| 1507 | + $boxWidth = (float)$size[2]; |
|
| 1508 | + $boxHeight = (float)$size[3]; |
|
| 1509 | 1509 | |
| 1510 | - // calculate the x and y units of the document: |
|
| 1511 | - // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
| 1512 | - // |
|
| 1513 | - // The viewbox combined with the width and height of the svg |
|
| 1514 | - // allow calculating how many pixels are in one unit of the |
|
| 1515 | - // width and height of the document. |
|
| 1510 | + // calculate the x and y units of the document: |
|
| 1511 | + // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
| 1516 | 1512 | // |
| 1517 | - $xUnits = $svgWidth / $boxWidth; |
|
| 1518 | - $yUnits = $svgHeight / $boxHeight; |
|
| 1513 | + // The viewbox combined with the width and height of the svg |
|
| 1514 | + // allow calculating how many pixels are in one unit of the |
|
| 1515 | + // width and height of the document. |
|
| 1516 | + // |
|
| 1517 | + $xUnits = $svgWidth / $boxWidth; |
|
| 1518 | + $yUnits = $svgHeight / $boxHeight; |
|
| 1519 | 1519 | |
| 1520 | - $pxWidth = $xUnits * $svgWidth; |
|
| 1521 | - $pxHeight = $yUnits * $svgHeight; |
|
| 1520 | + $pxWidth = $xUnits * $svgWidth; |
|
| 1521 | + $pxHeight = $yUnits * $svgHeight; |
|
| 1522 | 1522 | |
| 1523 | - return new ImageHelper_Size(array( |
|
| 1523 | + return new ImageHelper_Size(array( |
|
| 1524 | 1524 | (int)$pxWidth, |
| 1525 | 1525 | (int)$pxHeight, |
| 1526 | - 'bits' => 8 |
|
| 1527 | - )); |
|
| 1528 | - } |
|
| 1526 | + 'bits' => 8 |
|
| 1527 | + )); |
|
| 1528 | + } |
|
| 1529 | 1529 | |
| 1530 | 1530 | /** |
| 1531 | 1531 | * Crops the image to the specified width and height, optionally |
@@ -1584,26 +1584,26 @@ discard block |
||
| 1584 | 1584 | return $image->getColorAt(0, 0); |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | - /** |
|
| 1588 | - * Calculates the image's average color value, and |
|
| 1589 | - * returns an associative array with red, green, |
|
| 1590 | - * blue and alpha keys. |
|
| 1591 | - * |
|
| 1592 | - * @throws ImageHelper_Exception |
|
| 1593 | - * @return RGBAColor |
|
| 1594 | - */ |
|
| 1587 | + /** |
|
| 1588 | + * Calculates the image's average color value, and |
|
| 1589 | + * returns an associative array with red, green, |
|
| 1590 | + * blue and alpha keys. |
|
| 1591 | + * |
|
| 1592 | + * @throws ImageHelper_Exception |
|
| 1593 | + * @return RGBAColor |
|
| 1594 | + */ |
|
| 1595 | 1595 | public function calcAverageColorRGB() : RGBAColor |
| 1596 | 1596 | { |
| 1597 | - return $this->calcAverageColor(); |
|
| 1597 | + return $this->calcAverageColor(); |
|
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | - /** |
|
| 1601 | - * Calculates the image's average color value, and |
|
| 1602 | - * returns a hex color string (without the #). |
|
| 1603 | - * |
|
| 1604 | - * @throws ImageHelper_Exception |
|
| 1605 | - * @return string |
|
| 1606 | - */ |
|
| 1600 | + /** |
|
| 1601 | + * Calculates the image's average color value, and |
|
| 1602 | + * returns a hex color string (without the #). |
|
| 1603 | + * |
|
| 1604 | + * @throws ImageHelper_Exception |
|
| 1605 | + * @return string |
|
| 1606 | + */ |
|
| 1607 | 1607 | public function calcAverageColorHex() : string |
| 1608 | 1608 | { |
| 1609 | 1609 | return $this->calcAverageColor()->toHEX(); |
@@ -1656,15 +1656,15 @@ discard block |
||
| 1656 | 1656 | ->getValue(); |
| 1657 | 1657 | } |
| 1658 | 1658 | |
| 1659 | - /** |
|
| 1660 | - * Retrieves a md5 hash of the source image file. |
|
| 1661 | - * |
|
| 1662 | - * NOTE: Only works when the helper has been created |
|
| 1663 | - * from a file. Otherwise, an exception is thrown. |
|
| 1664 | - * |
|
| 1665 | - * @return string |
|
| 1666 | - * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
| 1667 | - */ |
|
| 1659 | + /** |
|
| 1660 | + * Retrieves a md5 hash of the source image file. |
|
| 1661 | + * |
|
| 1662 | + * NOTE: Only works when the helper has been created |
|
| 1663 | + * from a file. Otherwise, an exception is thrown. |
|
| 1664 | + * |
|
| 1665 | + * @return string |
|
| 1666 | + * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
| 1667 | + */ |
|
| 1668 | 1668 | public function getHash() : string |
| 1669 | 1669 | { |
| 1670 | 1670 | if($this->newImage === null) |