@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | $autoload = realpath($root.'/../vendor/autoload.php'); |
| 13 | 13 | |
| 14 | 14 | // we need the autoloader to be present |
| 15 | - if($autoload === false) |
|
| 15 | + if ($autoload === false) |
|
| 16 | 16 | { |
| 17 | 17 | die('<b>ERROR:</b> Autoloader not present. Run composer update first.'); |
| 18 | 18 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | require_once $autoload; |
| 24 | 24 | |
| 25 | - if(!class_exists('\AppLocalize\Localization')) |
|
| 25 | + if (!class_exists('\AppLocalize\Localization')) |
|
| 26 | 26 | { |
| 27 | 27 | die( |
| 28 | 28 | '<b>ERROR:</b> The translation user interface requires the |
@@ -34,41 +34,41 @@ discard block |
||
| 34 | 34 | return new XMLHelper($dom); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Creates a converter instance from an XML file. |
|
| 39 | - * @param string $xmlFile |
|
| 40 | - * @return \AppUtils\XMLHelper_Converter |
|
| 41 | - */ |
|
| 37 | + /** |
|
| 38 | + * Creates a converter instance from an XML file. |
|
| 39 | + * @param string $xmlFile |
|
| 40 | + * @return \AppUtils\XMLHelper_Converter |
|
| 41 | + */ |
|
| 42 | 42 | public static function convertFile(string $xmlFile) |
| 43 | 43 | { |
| 44 | 44 | return XMLHelper_Converter::fromFile($xmlFile); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Creates a converter from an XML string. |
|
| 49 | - * @param string $xmlString |
|
| 50 | - * @return \AppUtils\XMLHelper_Converter |
|
| 51 | - */ |
|
| 47 | + /** |
|
| 48 | + * Creates a converter from an XML string. |
|
| 49 | + * @param string $xmlString |
|
| 50 | + * @return \AppUtils\XMLHelper_Converter |
|
| 51 | + */ |
|
| 52 | 52 | public static function convertString(string $xmlString) |
| 53 | 53 | { |
| 54 | 54 | return XMLHelper_Converter::fromString($xmlString); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Creates a converter from a SimpleXMLElement instance. |
|
| 59 | - * @param \SimpleXMLElement $element |
|
| 60 | - * @return \AppUtils\XMLHelper_Converter |
|
| 61 | - */ |
|
| 57 | + /** |
|
| 58 | + * Creates a converter from a SimpleXMLElement instance. |
|
| 59 | + * @param \SimpleXMLElement $element |
|
| 60 | + * @return \AppUtils\XMLHelper_Converter |
|
| 61 | + */ |
|
| 62 | 62 | public static function convertElement(\SimpleXMLElement $element) |
| 63 | 63 | { |
| 64 | 64 | return XMLHelper_Converter::fromElement($element); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Creates a converter from a DOMElement instance. |
|
| 69 | - * @param \DOMElement $element |
|
| 70 | - * @return \AppUtils\XMLHelper_Converter |
|
| 71 | - */ |
|
| 67 | + /** |
|
| 68 | + * Creates a converter from a DOMElement instance. |
|
| 69 | + * @param \DOMElement $element |
|
| 70 | + * @return \AppUtils\XMLHelper_Converter |
|
| 71 | + */ |
|
| 72 | 72 | public static function convertDOMElement(\DOMElement $element) |
| 73 | 73 | { |
| 74 | 74 | return XMLHelper_Converter::fromDOMElement($element); |
@@ -436,31 +436,31 @@ discard block |
||
| 436 | 436 | return $this->dom->saveXML(); |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - /** |
|
| 440 | - * Creates a new SimpleXML helper instance: this |
|
| 441 | - * object is useful to work with loading XML strings |
|
| 442 | - * and files with easy access to any errors that |
|
| 443 | - * may occurr, since the simplexml functions can be |
|
| 444 | - * somewhat cryptic. |
|
| 445 | - * |
|
| 446 | - * @return XMLHelper_SimpleXML |
|
| 447 | - */ |
|
| 439 | + /** |
|
| 440 | + * Creates a new SimpleXML helper instance: this |
|
| 441 | + * object is useful to work with loading XML strings |
|
| 442 | + * and files with easy access to any errors that |
|
| 443 | + * may occurr, since the simplexml functions can be |
|
| 444 | + * somewhat cryptic. |
|
| 445 | + * |
|
| 446 | + * @return XMLHelper_SimpleXML |
|
| 447 | + */ |
|
| 448 | 448 | public static function createSimplexml() |
| 449 | 449 | { |
| 450 | 450 | return new XMLHelper_SimpleXML(); |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - /** |
|
| 454 | - * Converts a string to valid XML: can be a text only string |
|
| 455 | - * or an HTML string. Returns valid XML code. |
|
| 456 | - * |
|
| 457 | - * NOTE: The string may contain custom tags, which are |
|
| 458 | - * preserved. |
|
| 459 | - * |
|
| 460 | - * @param string $string |
|
| 461 | - * @throws XMLHelper_Exception |
|
| 462 | - * @return string |
|
| 463 | - */ |
|
| 453 | + /** |
|
| 454 | + * Converts a string to valid XML: can be a text only string |
|
| 455 | + * or an HTML string. Returns valid XML code. |
|
| 456 | + * |
|
| 457 | + * NOTE: The string may contain custom tags, which are |
|
| 458 | + * preserved. |
|
| 459 | + * |
|
| 460 | + * @param string $string |
|
| 461 | + * @throws XMLHelper_Exception |
|
| 462 | + * @return string |
|
| 463 | + */ |
|
| 464 | 464 | public static function string2xml(string $string) : string |
| 465 | 465 | { |
| 466 | 466 | if(stristr($string, '<body')) |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | function addAttribute($parent, $name, $value) |
| 109 | 109 | { |
| 110 | - if(!$parent instanceof \DOMNode) { |
|
| 110 | + if (!$parent instanceof \DOMNode) { |
|
| 111 | 111 | throw new XMLHelper_Exception( |
| 112 | 112 | 'The specified parent node is not a node instance.', |
| 113 | 113 | sprintf('Tried adding attribute [%s].', $name), |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | if (!empty($text)) { |
| 231 | 231 | $fragment = $this->dom->createDocumentFragment(); |
| 232 | - if(!@$fragment->appendXML($text)) { |
|
| 232 | + if (!@$fragment->appendXML($text)) { |
|
| 233 | 233 | throw new XMLHelper_Exception( |
| 234 | 234 | 'Cannot append XML fragment', |
| 235 | 235 | sprintf( |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @param array $attributes |
| 272 | 272 | * @return \DOMNode |
| 273 | 273 | */ |
| 274 | - function createRoot($name, $attributes=array()) |
|
| 274 | + function createRoot($name, $attributes = array()) |
|
| 275 | 275 | { |
| 276 | 276 | $root = $this->dom->appendChild($this->dom->createElement($name)); |
| 277 | 277 | $this->addAttributes($root, $attributes); |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | $string = str_replace('<', 'LT_ESCAPE', $string); |
| 292 | 292 | $string = str_replace('>', 'GT_ESCAPE', $string); |
| 293 | 293 | |
| 294 | - $string = str_replace(' ',' ', $string); |
|
| 295 | - $string = str_replace('&','&', $string); |
|
| 294 | + $string = str_replace(' ', ' ', $string); |
|
| 295 | + $string = str_replace('&', '&', $string); |
|
| 296 | 296 | |
| 297 | 297 | return $string; |
| 298 | 298 | } |
@@ -307,8 +307,8 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | public static function downloadXML($xml, $filename = 'download.xml') |
| 309 | 309 | { |
| 310 | - if(!headers_sent() && !self::$simulation) { |
|
| 311 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
| 310 | + if (!headers_sent() && !self::$simulation) { |
|
| 311 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | echo $xml; |
@@ -323,11 +323,11 @@ discard block |
||
| 323 | 323 | */ |
| 324 | 324 | public static function displayXML($xml) |
| 325 | 325 | { |
| 326 | - if(!headers_sent() && !self::$simulation) { |
|
| 326 | + if (!headers_sent() && !self::$simulation) { |
|
| 327 | 327 | header('Content-Type:text/xml; charset=utf-8'); |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if(self::$simulation) { |
|
| 330 | + if (self::$simulation) { |
|
| 331 | 331 | $xml = '<pre>'.htmlspecialchars($xml).'</pre>'; |
| 332 | 332 | } |
| 333 | 333 | |
@@ -345,10 +345,10 @@ discard block |
||
| 345 | 345 | * @param string[] $customInfo Associative array with name => value pairs for custom tags to add to the output xml |
| 346 | 346 | * @see buildErrorXML() |
| 347 | 347 | */ |
| 348 | - public static function displayErrorXML($code, $message, $title, $customInfo=array()) |
|
| 348 | + public static function displayErrorXML($code, $message, $title, $customInfo = array()) |
|
| 349 | 349 | { |
| 350 | - if(!headers_sent() && !self::$simulation) { |
|
| 351 | - header('HTTP/1.1 400 Bad Request: ' . $title, true, 400); |
|
| 350 | + if (!headers_sent() && !self::$simulation) { |
|
| 351 | + header('HTTP/1.1 400 Bad Request: '.$title, true, 400); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | self::displayXML(self::buildErrorXML($code, $message, $title, $customInfo)); |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | |
| 357 | 357 | protected static $simulation = false; |
| 358 | 358 | |
| 359 | - public static function setSimulation($simulate=true) |
|
| 359 | + public static function setSimulation($simulate = true) |
|
| 360 | 360 | { |
| 361 | 361 | self::$simulation = $simulate; |
| 362 | 362 | } |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | * @param string $title |
| 405 | 405 | * @return string |
| 406 | 406 | */ |
| 407 | - public static function buildErrorXML($code, $message, $title, $customInfo=array()) |
|
| 407 | + public static function buildErrorXML($code, $message, $title, $customInfo = array()) |
|
| 408 | 408 | { |
| 409 | 409 | $xml = new \DOMDocument('1.0', 'UTF-8'); |
| 410 | 410 | $xml->formatOutput = true; |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | $helper->addTextTag($root, 'title', $title); |
| 419 | 419 | $helper->addTextTag($root, 'request_uri', $_SERVER['REQUEST_URI']); |
| 420 | 420 | |
| 421 | - foreach($customInfo as $name => $value) { |
|
| 421 | + foreach ($customInfo as $name => $value) { |
|
| 422 | 422 | $helper->addTextTag($root, $name, $value); |
| 423 | 423 | } |
| 424 | 424 | |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | */ |
| 464 | 464 | public static function string2xml(string $string) : string |
| 465 | 465 | { |
| 466 | - if(stristr($string, '<body')) |
|
| 466 | + if (stristr($string, '<body')) |
|
| 467 | 467 | { |
| 468 | 468 | throw new XMLHelper_Exception( |
| 469 | 469 | 'Cannot convert string with existing body element', |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | |
| 494 | 494 | // capture all elements except the body tag itself |
| 495 | 495 | $xml = ''; |
| 496 | - foreach($root->childNodes as $child) { |
|
| 496 | + foreach ($root->childNodes as $child) { |
|
| 497 | 497 | $xml .= $dom->saveXML($child); |
| 498 | 498 | } |
| 499 | 499 | |
@@ -60,23 +60,23 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * The end of line character used in the INI source string. |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 63 | + /** |
|
| 64 | + * The end of line character used in the INI source string. |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | 67 | public function getEOLChar() : string |
| 68 | 68 | { |
| 69 | 69 | return $this->eol; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Factory method: creates a new helper instance loading the |
|
| 74 | - * ini content from the specified file. |
|
| 75 | - * |
|
| 76 | - * @param string $iniPath |
|
| 77 | - * @throws IniHelper_Exception |
|
| 78 | - * @return \AppUtils\IniHelper |
|
| 79 | - */ |
|
| 72 | + /** |
|
| 73 | + * Factory method: creates a new helper instance loading the |
|
| 74 | + * ini content from the specified file. |
|
| 75 | + * |
|
| 76 | + * @param string $iniPath |
|
| 77 | + * @throws IniHelper_Exception |
|
| 78 | + * @return \AppUtils\IniHelper |
|
| 79 | + */ |
|
| 80 | 80 | public static function createFromFile(string $iniPath) |
| 81 | 81 | { |
| 82 | 82 | $iniPath = FileHelper::requireFileExists($iniPath); |
@@ -96,35 +96,35 @@ discard block |
||
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Factory method: Creates a new ini helper instance from an ini string. |
|
| 101 | - * |
|
| 102 | - * @param string $iniContent |
|
| 103 | - * @return \AppUtils\IniHelper |
|
| 104 | - */ |
|
| 99 | + /** |
|
| 100 | + * Factory method: Creates a new ini helper instance from an ini string. |
|
| 101 | + * |
|
| 102 | + * @param string $iniContent |
|
| 103 | + * @return \AppUtils\IniHelper |
|
| 104 | + */ |
|
| 105 | 105 | public static function createFromString(string $iniContent) |
| 106 | 106 | { |
| 107 | 107 | return new IniHelper($iniContent); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Factory method: Creates a new empty ini helper. |
|
| 112 | - * |
|
| 113 | - * @return \AppUtils\IniHelper |
|
| 114 | - */ |
|
| 110 | + /** |
|
| 111 | + * Factory method: Creates a new empty ini helper. |
|
| 112 | + * |
|
| 113 | + * @return \AppUtils\IniHelper |
|
| 114 | + */ |
|
| 115 | 115 | public static function createNew() |
| 116 | 116 | { |
| 117 | 117 | return self::createFromString(''); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Adds a new data section, and returns the section instance. |
|
| 122 | - * If a section with the name already exists, returns that |
|
| 123 | - * section instead of creating a new one. |
|
| 124 | - * |
|
| 125 | - * @param string $name |
|
| 126 | - * @return IniHelper_Section |
|
| 127 | - */ |
|
| 120 | + /** |
|
| 121 | + * Adds a new data section, and returns the section instance. |
|
| 122 | + * If a section with the name already exists, returns that |
|
| 123 | + * section instead of creating a new one. |
|
| 124 | + * |
|
| 125 | + * @param string $name |
|
| 126 | + * @return IniHelper_Section |
|
| 127 | + */ |
|
| 128 | 128 | public function addSection(string $name) : IniHelper_Section |
| 129 | 129 | { |
| 130 | 130 | if(!isset($this->sections[$name])) { |
@@ -134,12 +134,12 @@ discard block |
||
| 134 | 134 | return $this->sections[$name]; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Retrieves a section by its name, if it exists. |
|
| 139 | - * |
|
| 140 | - * @param string $name |
|
| 141 | - * @return IniHelper_Section|NULL |
|
| 142 | - */ |
|
| 137 | + /** |
|
| 138 | + * Retrieves a section by its name, if it exists. |
|
| 139 | + * |
|
| 140 | + * @param string $name |
|
| 141 | + * @return IniHelper_Section|NULL |
|
| 142 | + */ |
|
| 143 | 143 | public function getSection(string $name) : ?IniHelper_Section |
| 144 | 144 | { |
| 145 | 145 | if(isset($this->sections[$name])) { |
@@ -149,11 +149,11 @@ discard block |
||
| 149 | 149 | return null; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Gets the data from the INI file as an associative array. |
|
| 154 | - * |
|
| 155 | - * @return array |
|
| 156 | - */ |
|
| 152 | + /** |
|
| 153 | + * Gets the data from the INI file as an associative array. |
|
| 154 | + * |
|
| 155 | + * @return array |
|
| 156 | + */ |
|
| 157 | 157 | public function toArray() : array |
| 158 | 158 | { |
| 159 | 159 | $result = array(); |
@@ -173,17 +173,17 @@ discard block |
||
| 173 | 173 | return $result; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Saves the INI content to the target file. |
|
| 178 | - * |
|
| 179 | - * @param string $filePath |
|
| 180 | - * @return IniHelper |
|
| 181 | - * @throws FileHelper_Exception |
|
| 182 | - * |
|
| 183 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 184 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 185 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 186 | - */ |
|
| 176 | + /** |
|
| 177 | + * Saves the INI content to the target file. |
|
| 178 | + * |
|
| 179 | + * @param string $filePath |
|
| 180 | + * @return IniHelper |
|
| 181 | + * @throws FileHelper_Exception |
|
| 182 | + * |
|
| 183 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 184 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 185 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 186 | + */ |
|
| 187 | 187 | public function saveToFile(string $filePath) : IniHelper |
| 188 | 188 | { |
| 189 | 189 | FileHelper::saveFile($filePath, self::saveToString()); |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | return $this; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Returns the INI content as string. |
|
| 196 | - * |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 194 | + /** |
|
| 195 | + * Returns the INI content as string. |
|
| 196 | + * |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | 199 | public function saveToString() : string |
| 200 | 200 | { |
| 201 | 201 | $parts = array(); |
@@ -208,15 +208,15 @@ discard block |
||
| 208 | 208 | return implode($this->eol, $parts); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * Sets or adds the value of a setting in the INI content. |
|
| 213 | - * If the setting does not exist, it is added. Otherwise, |
|
| 214 | - * the existing value is overwritten. |
|
| 215 | - * |
|
| 216 | - * @param string $path A variable path, either <code>varname</code> or <code>section.varname</code>. |
|
| 217 | - * @param mixed $value |
|
| 218 | - * @return IniHelper |
|
| 219 | - */ |
|
| 211 | + /** |
|
| 212 | + * Sets or adds the value of a setting in the INI content. |
|
| 213 | + * If the setting does not exist, it is added. Otherwise, |
|
| 214 | + * the existing value is overwritten. |
|
| 215 | + * |
|
| 216 | + * @param string $path A variable path, either <code>varname</code> or <code>section.varname</code>. |
|
| 217 | + * @param mixed $value |
|
| 218 | + * @return IniHelper |
|
| 219 | + */ |
|
| 220 | 220 | public function setValue(string $path, $value) : IniHelper |
| 221 | 221 | { |
| 222 | 222 | $path = $this->parsePath($path); |
@@ -251,12 +251,12 @@ discard block |
||
| 251 | 251 | return $this->addSection(self::SECTION_DEFAULT); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Retrieves all variable lines for the specified path. |
|
| 256 | - * |
|
| 257 | - * @param string $path A variable path. Either <code>varname</code> or <code>section.varname</code>. |
|
| 258 | - * @return array|\AppUtils\IniHelper_Line[] |
|
| 259 | - */ |
|
| 254 | + /** |
|
| 255 | + * Retrieves all variable lines for the specified path. |
|
| 256 | + * |
|
| 257 | + * @param string $path A variable path. Either <code>varname</code> or <code>section.varname</code>. |
|
| 258 | + * @return array|\AppUtils\IniHelper_Line[] |
|
| 259 | + */ |
|
| 260 | 260 | public function getLinesByVariable(string $path) |
| 261 | 261 | { |
| 262 | 262 | $path = $this->parsePath($path); |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | $section = $this->addSection(self::SECTION_DEFAULT); |
| 37 | 37 | |
| 38 | - if(empty($iniString)) { |
|
| 38 | + if (empty($iniString)) { |
|
| 39 | 39 | return; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $eol = ConvertHelper::detectEOLCharacter($iniString); |
| 43 | - if($eol !== null) { |
|
| 43 | + if ($eol !== null) { |
|
| 44 | 44 | $this->eol = $eol->getCharacter(); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $total = count($lines); |
| 50 | 50 | |
| 51 | - for($i=0; $i < $total; $i++) |
|
| 51 | + for ($i = 0; $i < $total; $i++) |
|
| 52 | 52 | { |
| 53 | 53 | $line = new IniHelper_Line($lines[$i], $i); |
| 54 | 54 | |
| 55 | - if($line->isSection()) { |
|
| 55 | + if ($line->isSection()) { |
|
| 56 | 56 | $section = $this->addSection($line->getSectionName()); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $iniPath = FileHelper::requireFileExists($iniPath); |
| 83 | 83 | |
| 84 | 84 | $content = file_get_contents($iniPath); |
| 85 | - if($content !== false) { |
|
| 85 | + if ($content !== false) { |
|
| 86 | 86 | return self::createFromString($content); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function addSection(string $name) : IniHelper_Section |
| 129 | 129 | { |
| 130 | - if(!isset($this->sections[$name])) { |
|
| 130 | + if (!isset($this->sections[$name])) { |
|
| 131 | 131 | $this->sections[$name] = new IniHelper_Section($this, $name); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function getSection(string $name) : ?IniHelper_Section |
| 144 | 144 | { |
| 145 | - if(isset($this->sections[$name])) { |
|
| 145 | + if (isset($this->sections[$name])) { |
|
| 146 | 146 | return $this->sections[$name]; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | $result = array(); |
| 160 | 160 | |
| 161 | - foreach($this->sections as $section) |
|
| 161 | + foreach ($this->sections as $section) |
|
| 162 | 162 | { |
| 163 | - if($section->isDefault()) |
|
| 163 | + if ($section->isDefault()) |
|
| 164 | 164 | { |
| 165 | 165 | $result = array_merge($result, $section->toArray()); |
| 166 | 166 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | $parts = array(); |
| 202 | 202 | |
| 203 | - foreach($this->sections as $section) |
|
| 203 | + foreach ($this->sections as $section) |
|
| 204 | 204 | { |
| 205 | 205 | $parts[] = $section->toString(); |
| 206 | 206 | } |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | public function sectionExists(string $name) |
| 239 | 239 | { |
| 240 | - foreach($this->sections as $section) { |
|
| 241 | - if($section->getName() === $name) { |
|
| 240 | + foreach ($this->sections as $section) { |
|
| 241 | + if ($section->getName() === $name) { |
|
| 242 | 242 | return true; |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | { |
| 262 | 262 | $path = $this->parsePath($path); |
| 263 | 263 | |
| 264 | - if(!$this->sectionExists($path['section'])) { |
|
| 264 | + if (!$this->sectionExists($path['section'])) { |
|
| 265 | 265 | return array(); |
| 266 | 266 | } |
| 267 | 267 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | { |
| 273 | 273 | $path = explode($this->pathSeparator, $path); |
| 274 | 274 | |
| 275 | - if(count($path) === 1) |
|
| 275 | + if (count($path) === 1) |
|
| 276 | 276 | { |
| 277 | 277 | return array( |
| 278 | 278 | 'section' => self::SECTION_DEFAULT, |
@@ -163,8 +163,7 @@ |
||
| 163 | 163 | if($section->isDefault()) |
| 164 | 164 | { |
| 165 | 165 | $result = array_merge($result, $section->toArray()); |
| 166 | - } |
|
| 167 | - else |
|
| 166 | + } else |
|
| 168 | 167 | { |
| 169 | 168 | $result[$section->getName()] = $section->toArray(); |
| 170 | 169 | } |
@@ -26,48 +26,48 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | class JSHelper |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * Quote style using single quotes. |
|
| 31 | - * @var integer |
|
| 32 | - */ |
|
| 29 | + /** |
|
| 30 | + * Quote style using single quotes. |
|
| 31 | + * @var integer |
|
| 32 | + */ |
|
| 33 | 33 | const QUOTE_STYLE_SINGLE = 1; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Quote style using double quotes. |
|
| 37 | - * @var integer |
|
| 38 | - */ |
|
| 35 | + /** |
|
| 36 | + * Quote style using double quotes. |
|
| 37 | + * @var integer |
|
| 38 | + */ |
|
| 39 | 39 | const QUOTE_STYLE_DOUBLE = 2; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | 44 | protected static $variableCache = array(); |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var integer |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var integer |
|
| 48 | + */ |
|
| 49 | 49 | protected static $elementCounter = 0; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | 54 | protected static $idPrefix = 'E'; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Builds a javascript statement. The first parameter is the |
|
| 58 | - * javascript function to call, any additional parameters are |
|
| 59 | - * used as arguments for the javascript function call. Variable |
|
| 60 | - * types are automagically converted to the javascript equivalents. |
|
| 61 | - * |
|
| 62 | - * Examples: |
|
| 63 | - * |
|
| 64 | - * // add an alert(); statement: |
|
| 65 | - * JSHelper::buildStatement('alert'); |
|
| 66 | - * |
|
| 67 | - * // add an alert('Alert text'); statement |
|
| 68 | - * JSHelper::buildStatement('alert', 'Alert text'); |
|
| 69 | - * |
|
| 70 | - */ |
|
| 56 | + /** |
|
| 57 | + * Builds a javascript statement. The first parameter is the |
|
| 58 | + * javascript function to call, any additional parameters are |
|
| 59 | + * used as arguments for the javascript function call. Variable |
|
| 60 | + * types are automagically converted to the javascript equivalents. |
|
| 61 | + * |
|
| 62 | + * Examples: |
|
| 63 | + * |
|
| 64 | + * // add an alert(); statement: |
|
| 65 | + * JSHelper::buildStatement('alert'); |
|
| 66 | + * |
|
| 67 | + * // add an alert('Alert text'); statement |
|
| 68 | + * JSHelper::buildStatement('alert', 'Alert text'); |
|
| 69 | + * |
|
| 70 | + */ |
|
| 71 | 71 | public static function buildStatement() : string |
| 72 | 72 | { |
| 73 | 73 | $args = func_get_args(); |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | return call_user_func_array(array(self::class, 'buildStatementQuoteStyle'), $args); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Like {@link JSHelper::buildStatement()}, but using single quotes |
|
| 80 | - * to make it possible to use the statement in an HTML tag attribute. |
|
| 81 | - * |
|
| 82 | - * @return string |
|
| 83 | - * @see JSHelper::buildStatement() |
|
| 84 | - */ |
|
| 78 | + /** |
|
| 79 | + * Like {@link JSHelper::buildStatement()}, but using single quotes |
|
| 80 | + * to make it possible to use the statement in an HTML tag attribute. |
|
| 81 | + * |
|
| 82 | + * @return string |
|
| 83 | + * @see JSHelper::buildStatement() |
|
| 84 | + */ |
|
| 85 | 85 | public static function buildStatementAttribute() : string |
| 86 | 86 | { |
| 87 | 87 | $args = func_get_args(); |
@@ -111,39 +111,39 @@ discard block |
||
| 111 | 111 | return $call . ');'; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Builds a set variable statement. The variable value is |
|
| 116 | - * automatically converted to the javascript equivalent. |
|
| 117 | - * |
|
| 118 | - * Examples: |
|
| 119 | - * |
|
| 120 | - * // foo = 'bar'; |
|
| 121 | - * JSHelper::buildVariable('foo', 'bar'); |
|
| 122 | - * |
|
| 123 | - * // foo = 42; |
|
| 124 | - * JSHelper::buildVariable('foo', 42); |
|
| 125 | - * |
|
| 126 | - * // foo = true; |
|
| 127 | - * JSHelper::buildVariable('foo', true); |
|
| 128 | - * |
|
| 129 | - * @param string $varName |
|
| 130 | - * @param mixed $varValue |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 114 | + /** |
|
| 115 | + * Builds a set variable statement. The variable value is |
|
| 116 | + * automatically converted to the javascript equivalent. |
|
| 117 | + * |
|
| 118 | + * Examples: |
|
| 119 | + * |
|
| 120 | + * // foo = 'bar'; |
|
| 121 | + * JSHelper::buildVariable('foo', 'bar'); |
|
| 122 | + * |
|
| 123 | + * // foo = 42; |
|
| 124 | + * JSHelper::buildVariable('foo', 42); |
|
| 125 | + * |
|
| 126 | + * // foo = true; |
|
| 127 | + * JSHelper::buildVariable('foo', true); |
|
| 128 | + * |
|
| 129 | + * @param string $varName |
|
| 130 | + * @param mixed $varValue |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | 133 | public static function buildVariable(string $varName, $varValue) : string |
| 134 | 134 | { |
| 135 | 135 | return $varName . "=" . self::phpVariable2JS($varValue) . ';'; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Converts a PHP variable to its javascript equivalent. Note that |
|
| 140 | - * if a variable cannot be converted (like a PHP resource), this will |
|
| 141 | - * return a javascript "null". |
|
| 142 | - * |
|
| 143 | - * @param mixed $variable |
|
| 144 | - * @param int $quoteStyle The quote style to use for strings |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 138 | + /** |
|
| 139 | + * Converts a PHP variable to its javascript equivalent. Note that |
|
| 140 | + * if a variable cannot be converted (like a PHP resource), this will |
|
| 141 | + * return a javascript "null". |
|
| 142 | + * |
|
| 143 | + * @param mixed $variable |
|
| 144 | + * @param int $quoteStyle The quote style to use for strings |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | 147 | public static function phpVariable2JS($variable, int $quoteStyle=self::QUOTE_STYLE_DOUBLE) : string |
| 148 | 148 | { |
| 149 | 149 | // after much profiling, this variant of the method offers |
@@ -221,26 +221,26 @@ discard block |
||
| 221 | 221 | return $result; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Converts a variable to a JS string that can be |
|
| 226 | - * used in an HTML attribute: it uses single quotes |
|
| 227 | - * instead of the default double quotes. |
|
| 228 | - * |
|
| 229 | - * @param mixed $variable |
|
| 230 | - * @return string |
|
| 231 | - */ |
|
| 224 | + /** |
|
| 225 | + * Converts a variable to a JS string that can be |
|
| 226 | + * used in an HTML attribute: it uses single quotes |
|
| 227 | + * instead of the default double quotes. |
|
| 228 | + * |
|
| 229 | + * @param mixed $variable |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 232 | 232 | public static function phpVariable2AttributeJS($variable) : string |
| 233 | 233 | { |
| 234 | 234 | return self::phpVariable2JS($variable, self::QUOTE_STYLE_SINGLE); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * Generates a dynamic element ID to be used with dynamically generated |
|
| 239 | - * HTML code to tie in with clientside javascript when compact but unique |
|
| 240 | - * IDs are needed in a request. |
|
| 241 | - * |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 237 | + /** |
|
| 238 | + * Generates a dynamic element ID to be used with dynamically generated |
|
| 239 | + * HTML code to tie in with clientside javascript when compact but unique |
|
| 240 | + * IDs are needed in a request. |
|
| 241 | + * |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | 244 | public static function nextElementID() : string |
| 245 | 245 | { |
| 246 | 246 | self::$elementCounter++; |
@@ -248,33 +248,33 @@ discard block |
||
| 248 | 248 | return self::$idPrefix . self::$elementCounter; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * Retrieves the ID prefix currently used. |
|
| 253 | - * |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 251 | + /** |
|
| 252 | + * Retrieves the ID prefix currently used. |
|
| 253 | + * |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | 256 | public static function getIDPrefix() : string |
| 257 | 257 | { |
| 258 | 258 | return self::$idPrefix; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Retrieves the value of the internal elements counter. |
|
| 263 | - * |
|
| 264 | - * @return integer |
|
| 265 | - */ |
|
| 261 | + /** |
|
| 262 | + * Retrieves the value of the internal elements counter. |
|
| 263 | + * |
|
| 264 | + * @return integer |
|
| 265 | + */ |
|
| 266 | 266 | public static function getElementCounter() : int |
| 267 | 267 | { |
| 268 | 268 | return self::$elementCounter; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Sets the prefix that is added in front of all IDs |
|
| 273 | - * retrieved using the {@link nextElementID()} method. |
|
| 274 | - * |
|
| 275 | - * @param string $prefix |
|
| 276 | - * @see JSHelper::nextElementID() |
|
| 277 | - */ |
|
| 271 | + /** |
|
| 272 | + * Sets the prefix that is added in front of all IDs |
|
| 273 | + * retrieved using the {@link nextElementID()} method. |
|
| 274 | + * |
|
| 275 | + * @param string $prefix |
|
| 276 | + * @see JSHelper::nextElementID() |
|
| 277 | + */ |
|
| 278 | 278 | public static function setIDPrefix(string $prefix) |
| 279 | 279 | { |
| 280 | 280 | self::$idPrefix = $prefix; |
@@ -95,20 +95,20 @@ discard block |
||
| 95 | 95 | $quoteStyle = array_shift($params); |
| 96 | 96 | $method = array_shift($params); |
| 97 | 97 | |
| 98 | - $call = $method . '('; |
|
| 98 | + $call = $method.'('; |
|
| 99 | 99 | |
| 100 | 100 | $total = count($params); |
| 101 | - if($total > 0) { |
|
| 102 | - for($i=0; $i < $total; $i++) |
|
| 101 | + if ($total > 0) { |
|
| 102 | + for ($i = 0; $i < $total; $i++) |
|
| 103 | 103 | { |
| 104 | 104 | $call .= self::phpVariable2JS($params[$i], $quoteStyle); |
| 105 | - if($i < ($total-1)) { |
|
| 105 | + if ($i < ($total - 1)) { |
|
| 106 | 106 | $call .= ','; |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return $call . ');'; |
|
| 111 | + return $call.');'; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | public static function buildVariable(string $varName, $varValue) : string |
| 134 | 134 | { |
| 135 | - return $varName . "=" . self::phpVariable2JS($varValue) . ';'; |
|
| 135 | + return $varName."=".self::phpVariable2JS($varValue).';'; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param int $quoteStyle The quote style to use for strings |
| 145 | 145 | * @return string |
| 146 | 146 | */ |
| 147 | - public static function phpVariable2JS($variable, int $quoteStyle=self::QUOTE_STYLE_DOUBLE) : string |
|
| 147 | + public static function phpVariable2JS($variable, int $quoteStyle = self::QUOTE_STYLE_DOUBLE) : string |
|
| 148 | 148 | { |
| 149 | 149 | // after much profiling, this variant of the method offers |
| 150 | 150 | // the best performance. Repeat scalar values are cached |
@@ -152,22 +152,22 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | $type = gettype($variable); |
| 154 | 154 | $hash = null; |
| 155 | - if(is_scalar($variable) === true) |
|
| 155 | + if (is_scalar($variable) === true) |
|
| 156 | 156 | { |
| 157 | 157 | $hash = $variable; |
| 158 | 158 | |
| 159 | - if($hash === true) |
|
| 159 | + if ($hash === true) |
|
| 160 | 160 | { |
| 161 | 161 | $hash = 'true'; |
| 162 | 162 | } |
| 163 | - else if($hash === false) |
|
| 163 | + else if ($hash === false) |
|
| 164 | 164 | { |
| 165 | 165 | $hash = 'false'; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | $hash .= '-'.$quoteStyle.'-'.$type; |
| 169 | 169 | |
| 170 | - if(isset(self::$variableCache[$hash])) { |
|
| 170 | + if (isset(self::$variableCache[$hash])) { |
|
| 171 | 171 | return self::$variableCache[$hash]; |
| 172 | 172 | } |
| 173 | 173 | } |
@@ -175,19 +175,19 @@ discard block |
||
| 175 | 175 | $result = 'null'; |
| 176 | 176 | |
| 177 | 177 | // one gettype call is better than a strict if-else. |
| 178 | - switch($type) |
|
| 178 | + switch ($type) |
|
| 179 | 179 | { |
| 180 | 180 | case 'double': |
| 181 | 181 | case 'string': |
| 182 | 182 | $string = json_encode($variable); |
| 183 | 183 | |
| 184 | - if($string === false) |
|
| 184 | + if ($string === false) |
|
| 185 | 185 | { |
| 186 | 186 | $string = ''; |
| 187 | 187 | } |
| 188 | - else if($quoteStyle === self::QUOTE_STYLE_SINGLE) |
|
| 188 | + else if ($quoteStyle === self::QUOTE_STYLE_SINGLE) |
|
| 189 | 189 | { |
| 190 | - $string = mb_substr($string, 1, mb_strlen($string)-2); |
|
| 190 | + $string = mb_substr($string, 1, mb_strlen($string) - 2); |
|
| 191 | 191 | $string = "'".str_replace("'", "\'", $string)."'"; |
| 192 | 192 | } |
| 193 | 193 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | break; |
| 196 | 196 | |
| 197 | 197 | case 'boolean': |
| 198 | - if($variable === true) { |
|
| 198 | + if ($variable === true) { |
|
| 199 | 199 | $result = 'true'; |
| 200 | 200 | } else { |
| 201 | 201 | $result = 'false'; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // cache cacheable values |
| 216 | - if($hash !== null) |
|
| 216 | + if ($hash !== null) |
|
| 217 | 217 | { |
| 218 | 218 | self::$variableCache[$hash] = $result; |
| 219 | 219 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | { |
| 246 | 246 | self::$elementCounter++; |
| 247 | 247 | |
| 248 | - return self::$idPrefix . self::$elementCounter; |
|
| 248 | + return self::$idPrefix.self::$elementCounter; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -159,8 +159,7 @@ discard block |
||
| 159 | 159 | if($hash === true) |
| 160 | 160 | { |
| 161 | 161 | $hash = 'true'; |
| 162 | - } |
|
| 163 | - else if($hash === false) |
|
| 162 | + } else if($hash === false) |
|
| 164 | 163 | { |
| 165 | 164 | $hash = 'false'; |
| 166 | 165 | } |
@@ -184,8 +183,7 @@ discard block |
||
| 184 | 183 | if($string === false) |
| 185 | 184 | { |
| 186 | 185 | $string = ''; |
| 187 | - } |
|
| 188 | - else if($quoteStyle === self::QUOTE_STYLE_SINGLE) |
|
| 186 | + } else if($quoteStyle === self::QUOTE_STYLE_SINGLE) |
|
| 189 | 187 | { |
| 190 | 188 | $string = mb_substr($string, 1, mb_strlen($string)-2); |
| 191 | 189 | $string = "'".str_replace("'", "\'", $string)."'"; |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | $contentLength = 0; |
| 98 | 98 | if (!empty($this->variables)) { |
| 99 | 99 | foreach ($this->variables as $name => $value) { |
| 100 | - $this->data .= '--' . $this->mimeBoundary . $this->eol; |
|
| 101 | - $this->data .= 'Content-Disposition: form-data; name="' . $name . '"' . $this->eol; |
|
| 100 | + $this->data .= '--'.$this->mimeBoundary.$this->eol; |
|
| 101 | + $this->data .= 'Content-Disposition: form-data; name="'.$name.'"'.$this->eol; |
|
| 102 | 102 | $this->data .= $this->eol; |
| 103 | - $this->data .= $value . $this->eol; |
|
| 103 | + $this->data .= $value.$this->eol; |
|
| 104 | 104 | |
| 105 | 105 | $contentLength += strlen($value); |
| 106 | 106 | } |
@@ -108,17 +108,17 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | if (!empty($this->files)) { |
| 110 | 110 | foreach ($this->files as $varName => $def) { |
| 111 | - $this->data .= '--' . $this->mimeBoundary . $this->eol; |
|
| 112 | - $this->data .= 'Content-Disposition: form-data; name="' . $varName . '"; filename="' . $def['fileName'] . '"' . $this->eol; |
|
| 113 | - $this->data .= 'Content-Type: ' . $def['contentType'] . '; charset=' . $def['encoding']; |
|
| 114 | - $this->data .= $this->eol . $this->eol; |
|
| 115 | - $this->data .= $def['content'] . $this->eol; |
|
| 111 | + $this->data .= '--'.$this->mimeBoundary.$this->eol; |
|
| 112 | + $this->data .= 'Content-Disposition: form-data; name="'.$varName.'"; filename="'.$def['fileName'].'"'.$this->eol; |
|
| 113 | + $this->data .= 'Content-Type: '.$def['contentType'].'; charset='.$def['encoding']; |
|
| 114 | + $this->data .= $this->eol.$this->eol; |
|
| 115 | + $this->data .= $def['content'].$this->eol; |
|
| 116 | 116 | |
| 117 | 117 | $contentLength += strlen($def['content']); |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $this->data .= "--" . $this->mimeBoundary . "--" . $this->eol . $this->eol; // finish with two eol's!! |
|
| 121 | + $this->data .= "--".$this->mimeBoundary."--".$this->eol.$this->eol; // finish with two eol's!! |
|
| 122 | 122 | |
| 123 | 123 | //echo '<pre>'.print_r($this->data,true).'</pre>'; |
| 124 | 124 | |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | 'http' => array( |
| 127 | 127 | 'method' => 'POST', |
| 128 | 128 | 'header' => |
| 129 | - 'Content-Length: ' . $contentLength . $this->eol . |
|
| 130 | - 'Content-Type: multipart/form-data; charset=UTF-8; boundary=' . $this->mimeBoundary . $this->eol |
|
| 129 | + 'Content-Length: '.$contentLength.$this->eol. |
|
| 130 | + 'Content-Type: multipart/form-data; charset=UTF-8; boundary='.$this->mimeBoundary.$this->eol |
|
| 131 | 131 | , |
| 132 | 132 | 'content' => $this->data |
| 133 | 133 | ) |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $errorMessage = error_get_last(); |
| 142 | 142 | throw new RequestHelper_Exception( |
| 143 | 143 | 'Request failed.', |
| 144 | - 'Request error message: ' . $errorMessage['message'] . ' in ' . $errorMessage['file'] . ':' . $errorMessage['line'], |
|
| 144 | + 'Request error message: '.$errorMessage['message'].' in '.$errorMessage['file'].':'.$errorMessage['line'], |
|
| 145 | 145 | self::ERROR_REQUEST_FAILED |
| 146 | 146 | ); |
| 147 | 147 | } |
@@ -8,9 +8,9 @@ discard block |
||
| 8 | 8 | * @param mixed $value |
| 9 | 9 | * @return \AppUtils\NumberInfo |
| 10 | 10 | */ |
| 11 | -function parseNumber($value, $forceNew=false) |
|
| 11 | +function parseNumber($value, $forceNew = false) |
|
| 12 | 12 | { |
| 13 | - if($value instanceof NumberInfo && $forceNew !== true) { |
|
| 13 | + if ($value instanceof NumberInfo && $forceNew !== true) { |
|
| 14 | 14 | return $value; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $args = func_get_args(); |
| 80 | 80 | |
| 81 | 81 | // is the localization package installed? |
| 82 | - if(class_exists('\AppLocalize\Localization')) |
|
| 82 | + if (class_exists('\AppLocalize\Localization')) |
|
| 83 | 83 | { |
| 84 | 84 | return call_user_func_array('\AppLocalize\t', $args); |
| 85 | 85 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | function init() |
| 97 | 97 | { |
| 98 | - if(!class_exists('\AppLocalize\Localization')) { |
|
| 98 | + if (!class_exists('\AppLocalize\Localization')) { |
|
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | return $default; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Enforces that the option value is a string. Scalar |
|
| 43 | - * values are converted to string, and non-scalar values |
|
| 44 | - * are converted to an empty string. |
|
| 45 | - * |
|
| 46 | - * @param string $name |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 41 | + /** |
|
| 42 | + * Enforces that the option value is a string. Scalar |
|
| 43 | + * values are converted to string, and non-scalar values |
|
| 44 | + * are converted to an empty string. |
|
| 45 | + * |
|
| 46 | + * @param string $name |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | 49 | public function getStringOption(string $name) : string |
| 50 | 50 | { |
| 51 | 51 | $value = $this->getOption($name, false); |
@@ -57,15 +57,15 @@ discard block |
||
| 57 | 57 | return ''; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Treats the option value as a boolean value: will return |
|
| 62 | - * true if the value actually is a boolean true. |
|
| 63 | - * |
|
| 64 | - * NOTE: boolean string representations are not accepted. |
|
| 65 | - * |
|
| 66 | - * @param string $name |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 60 | + /** |
|
| 61 | + * Treats the option value as a boolean value: will return |
|
| 62 | + * true if the value actually is a boolean true. |
|
| 63 | + * |
|
| 64 | + * NOTE: boolean string representations are not accepted. |
|
| 65 | + * |
|
| 66 | + * @param string $name |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | 69 | public function getBoolOption(string $name) : bool |
| 70 | 70 | { |
| 71 | 71 | if($this->getOption($name) === true) { |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public function setOption(string $name, $value) : Interface_Optionable |
| 10 | 10 | { |
| 11 | - if(!isset($this->options)) { |
|
| 11 | + if (!isset($this->options)) { |
|
| 12 | 12 | $this->options = $this->getDefaultOptions(); |
| 13 | 13 | } |
| 14 | 14 | |
@@ -18,20 +18,20 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function setOptions(array $options) : Interface_Optionable |
| 20 | 20 | { |
| 21 | - foreach($options as $name => $value) { |
|
| 21 | + foreach ($options as $name => $value) { |
|
| 22 | 22 | $this->setOption($name, $value); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | return $this; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function getOption(string $name, $default=null) |
|
| 28 | + public function getOption(string $name, $default = null) |
|
| 29 | 29 | { |
| 30 | - if(!isset($this->options)) { |
|
| 30 | + if (!isset($this->options)) { |
|
| 31 | 31 | $this->options = $this->getDefaultOptions(); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if(isset($this->options[$name])) { |
|
| 34 | + if (isset($this->options[$name])) { |
|
| 35 | 35 | return $this->options[$name]; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | $value = $this->getOption($name, false); |
| 52 | 52 | |
| 53 | - if(is_scalar($value)) { |
|
| 53 | + if (is_scalar($value)) { |
|
| 54 | 54 | return (string)$value; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function getBoolOption(string $name) : bool |
| 70 | 70 | { |
| 71 | - if($this->getOption($name) === true) { |
|
| 71 | + if ($this->getOption($name) === true) { |
|
| 72 | 72 | return true; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | public function hasOption($name) : bool |
| 79 | 79 | { |
| 80 | - if(!isset($this->options)) { |
|
| 80 | + if (!isset($this->options)) { |
|
| 81 | 81 | $this->options = $this->getDefaultOptions(); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public function getOptions() : array |
| 88 | 88 | { |
| 89 | - if(!isset($this->options)) { |
|
| 89 | + if (!isset($this->options)) { |
|
| 90 | 90 | $this->options = $this->getDefaultOptions(); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | interface Interface_Optionable |
| 103 | 103 | { |
| 104 | 104 | function setOption(string $name, $value) : Interface_Optionable; |
| 105 | - function getOption(string $name, $default=null); |
|
| 105 | + function getOption(string $name, $default = null); |
|
| 106 | 106 | function setOptions(array $options) : Interface_Optionable; |
| 107 | 107 | function getOptions() : array; |
| 108 | 108 | function isOption($name, $value) : bool; |
@@ -24,56 +24,56 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | class PaginationHelper |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * @var int |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var int |
|
| 29 | + */ |
|
| 30 | 30 | protected $total; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | 35 | protected $perPage; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var int |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var int |
|
| 39 | + */ |
|
| 40 | 40 | protected $current; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | 45 | protected $next = 0; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var int |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var int |
|
| 49 | + */ |
|
| 50 | 50 | protected $prev = 0; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var int |
|
| 54 | - */ |
|
| 52 | + /** |
|
| 53 | + * @var int |
|
| 54 | + */ |
|
| 55 | 55 | protected $last = 0; |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @var int |
|
| 59 | - */ |
|
| 57 | + /** |
|
| 58 | + * @var int |
|
| 59 | + */ |
|
| 60 | 60 | protected $adjacentPages = 3; |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @var int |
|
| 64 | - */ |
|
| 62 | + /** |
|
| 63 | + * @var int |
|
| 64 | + */ |
|
| 65 | 65 | protected $offsetEnd = 0; |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @var int |
|
| 69 | - */ |
|
| 67 | + /** |
|
| 68 | + * @var int |
|
| 69 | + */ |
|
| 70 | 70 | protected $offsetStart = 0; |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @param int $totalItems The total amount of items available. |
|
| 74 | - * @param int $itemsPerPage How many items to display per page. |
|
| 75 | - * @param int $currentPage The current page number (1-based) |
|
| 76 | - */ |
|
| 72 | + /** |
|
| 73 | + * @param int $totalItems The total amount of items available. |
|
| 74 | + * @param int $itemsPerPage How many items to display per page. |
|
| 75 | + * @param int $currentPage The current page number (1-based) |
|
| 76 | + */ |
|
| 77 | 77 | public function __construct(int $totalItems, int $itemsPerPage, int $currentPage) |
| 78 | 78 | { |
| 79 | 79 | $this->total = $totalItems; |
@@ -83,34 +83,34 @@ discard block |
||
| 83 | 83 | $this->calculate(); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Sets the amount of adjacent pages to display next to the |
|
| 88 | - * current one when using the pages list. |
|
| 89 | - * |
|
| 90 | - * @param int $amount |
|
| 91 | - * @return PaginationHelper |
|
| 92 | - */ |
|
| 86 | + /** |
|
| 87 | + * Sets the amount of adjacent pages to display next to the |
|
| 88 | + * current one when using the pages list. |
|
| 89 | + * |
|
| 90 | + * @param int $amount |
|
| 91 | + * @return PaginationHelper |
|
| 92 | + */ |
|
| 93 | 93 | public function setAdjacentPages(int $amount) : PaginationHelper |
| 94 | 94 | { |
| 95 | 95 | $this->adjacentPages = $amount; |
| 96 | 96 | return $this; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Whether there is a next page after the current page. |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 99 | + /** |
|
| 100 | + * Whether there is a next page after the current page. |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | 103 | public function hasNextPage() : bool |
| 104 | 104 | { |
| 105 | 105 | return $this->next > 0; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * The next page number. Returns the last page |
|
| 110 | - * number if there is no next page. |
|
| 111 | - * |
|
| 112 | - * @return int |
|
| 113 | - */ |
|
| 108 | + /** |
|
| 109 | + * The next page number. Returns the last page |
|
| 110 | + * number if there is no next page. |
|
| 111 | + * |
|
| 112 | + * @return int |
|
| 113 | + */ |
|
| 114 | 114 | public function getNextPage() : int |
| 115 | 115 | { |
| 116 | 116 | if($this->next === 0) { |
@@ -120,21 +120,21 @@ discard block |
||
| 120 | 120 | return $this->next; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Whether there is a previous page before the current page. |
|
| 125 | - * @return bool |
|
| 126 | - */ |
|
| 123 | + /** |
|
| 124 | + * Whether there is a previous page before the current page. |
|
| 125 | + * @return bool |
|
| 126 | + */ |
|
| 127 | 127 | public function hasPreviousPage() : bool |
| 128 | 128 | { |
| 129 | 129 | return $this->prev > 0; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * The previous page number. Returns the first page |
|
| 134 | - * number if there is no previous page. |
|
| 135 | - * |
|
| 136 | - * @return int |
|
| 137 | - */ |
|
| 132 | + /** |
|
| 133 | + * The previous page number. Returns the first page |
|
| 134 | + * number if there is no previous page. |
|
| 135 | + * |
|
| 136 | + * @return int |
|
| 137 | + */ |
|
| 138 | 138 | public function getPreviousPage() : int |
| 139 | 139 | { |
| 140 | 140 | if($this->prev === 0) { |
@@ -144,21 +144,21 @@ discard block |
||
| 144 | 144 | return $this->prev; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Retrieves the last page number. |
|
| 149 | - * @return int |
|
| 150 | - */ |
|
| 147 | + /** |
|
| 148 | + * Retrieves the last page number. |
|
| 149 | + * @return int |
|
| 150 | + */ |
|
| 151 | 151 | public function getLastPage() : int |
| 152 | 152 | { |
| 153 | 153 | return $this->last; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Whether there is more than one page, i.e. whether |
|
| 158 | - * pagination is required at all. |
|
| 159 | - * |
|
| 160 | - * @return bool |
|
| 161 | - */ |
|
| 156 | + /** |
|
| 157 | + * Whether there is more than one page, i.e. whether |
|
| 158 | + * pagination is required at all. |
|
| 159 | + * |
|
| 160 | + * @return bool |
|
| 161 | + */ |
|
| 162 | 162 | public function hasPages() : bool |
| 163 | 163 | { |
| 164 | 164 | return $this->last > 1; |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | return $this->current; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Retrieves a list of page numbers for a page |
|
| 174 | - * navigator, to quickly jump between pages. |
|
| 175 | - * |
|
| 176 | - * @return int[] |
|
| 177 | - */ |
|
| 172 | + /** |
|
| 173 | + * Retrieves a list of page numbers for a page |
|
| 174 | + * navigator, to quickly jump between pages. |
|
| 175 | + * |
|
| 176 | + * @return int[] |
|
| 177 | + */ |
|
| 178 | 178 | public function getPageNumbers() : array |
| 179 | 179 | { |
| 180 | 180 | $adjacent = $this->adjacentPages; |
@@ -250,66 +250,66 @@ discard block |
||
| 250 | 250 | return $numbers; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Whether the specified page number is the current page. |
|
| 255 | - * |
|
| 256 | - * @param int $pageNumber |
|
| 257 | - * @return bool |
|
| 258 | - */ |
|
| 253 | + /** |
|
| 254 | + * Whether the specified page number is the current page. |
|
| 255 | + * |
|
| 256 | + * @param int $pageNumber |
|
| 257 | + * @return bool |
|
| 258 | + */ |
|
| 259 | 259 | public function isCurrentPage(int $pageNumber) : bool |
| 260 | 260 | { |
| 261 | 261 | return $pageNumber === $this->current; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - /** |
|
| 265 | - * Retrieves the 1-based starting offset of |
|
| 266 | - * items currently displayed in the page. |
|
| 267 | - * |
|
| 268 | - * Note: Use this to create a text like |
|
| 269 | - * "showing entries x to y". |
|
| 270 | - * |
|
| 271 | - * @return int |
|
| 272 | - * @see PaginationHelper::getOffsetEnd() |
|
| 273 | - */ |
|
| 264 | + /** |
|
| 265 | + * Retrieves the 1-based starting offset of |
|
| 266 | + * items currently displayed in the page. |
|
| 267 | + * |
|
| 268 | + * Note: Use this to create a text like |
|
| 269 | + * "showing entries x to y". |
|
| 270 | + * |
|
| 271 | + * @return int |
|
| 272 | + * @see PaginationHelper::getOffsetEnd() |
|
| 273 | + */ |
|
| 274 | 274 | public function getItemsStart() : int |
| 275 | 275 | { |
| 276 | 276 | return $this->getOffsetStart() + 1; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Retrieves the 1-based ending offset of |
|
| 281 | - * items currently displayed in the page. |
|
| 282 | - * |
|
| 283 | - * Note: Use this to create a text like |
|
| 284 | - * "showing entries x to y". |
|
| 285 | - * |
|
| 286 | - * @return int |
|
| 287 | - * @see PaginationHelper::getOffsetStart() |
|
| 288 | - */ |
|
| 279 | + /** |
|
| 280 | + * Retrieves the 1-based ending offset of |
|
| 281 | + * items currently displayed in the page. |
|
| 282 | + * |
|
| 283 | + * Note: Use this to create a text like |
|
| 284 | + * "showing entries x to y". |
|
| 285 | + * |
|
| 286 | + * @return int |
|
| 287 | + * @see PaginationHelper::getOffsetStart() |
|
| 288 | + */ |
|
| 289 | 289 | public function getItemsEnd() : int |
| 290 | 290 | { |
| 291 | 291 | return $this->getOffsetEnd() + 1; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - /** |
|
| 295 | - * Retrieves the 0-based starting offset of |
|
| 296 | - * items currently displayed in the page. |
|
| 297 | - * |
|
| 298 | - * @return int |
|
| 299 | - * @see PaginationHelper::getItemsStart() |
|
| 300 | - */ |
|
| 294 | + /** |
|
| 295 | + * Retrieves the 0-based starting offset of |
|
| 296 | + * items currently displayed in the page. |
|
| 297 | + * |
|
| 298 | + * @return int |
|
| 299 | + * @see PaginationHelper::getItemsStart() |
|
| 300 | + */ |
|
| 301 | 301 | public function getOffsetStart() : int |
| 302 | 302 | { |
| 303 | 303 | return $this->offsetStart; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Retrieves the 0-based ending offset of |
|
| 308 | - * items currently displayed in the page. |
|
| 309 | - * |
|
| 310 | - * @return int |
|
| 311 | - * @see PaginationHelper::getItemsEnd() |
|
| 312 | - */ |
|
| 306 | + /** |
|
| 307 | + * Retrieves the 0-based ending offset of |
|
| 308 | + * items currently displayed in the page. |
|
| 309 | + * |
|
| 310 | + * @return int |
|
| 311 | + * @see PaginationHelper::getItemsEnd() |
|
| 312 | + */ |
|
| 313 | 313 | public function getOffsetEnd() : int |
| 314 | 314 | { |
| 315 | 315 | return $this->offsetEnd; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function getNextPage() : int |
| 115 | 115 | { |
| 116 | - if($this->next === 0) { |
|
| 116 | + if ($this->next === 0) { |
|
| 117 | 117 | return $this->last; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function getPreviousPage() : int |
| 139 | 139 | { |
| 140 | - if($this->prev === 0) { |
|
| 140 | + if ($this->prev === 0) { |
|
| 141 | 141 | return 1; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // adjust the adjacent value if it exceeds the |
| 183 | 183 | // total amount of pages |
| 184 | 184 | $adjacentTotal = ($adjacent * 2) + 1; |
| 185 | - if($adjacentTotal > $this->last) |
|
| 185 | + if ($adjacentTotal > $this->last) |
|
| 186 | 186 | { |
| 187 | 187 | $adjacent = (int)floor($this->last / 2); |
| 188 | 188 | } |
@@ -195,13 +195,13 @@ discard block |
||
| 195 | 195 | $back = 0; |
| 196 | 196 | $fwd = 0; |
| 197 | 197 | |
| 198 | - if($maxBack >= $adjacent) { |
|
| 198 | + if ($maxBack >= $adjacent) { |
|
| 199 | 199 | $back = $adjacent; |
| 200 | 200 | } else { |
| 201 | 201 | $back = $maxBack; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if($maxFwd >= $adjacent) { |
|
| 204 | + if ($maxFwd >= $adjacent) { |
|
| 205 | 205 | $fwd = $adjacent; |
| 206 | 206 | } else { |
| 207 | 207 | $fwd = $maxFwd; |
@@ -217,16 +217,16 @@ discard block |
||
| 217 | 217 | $fwd += $backDiff; |
| 218 | 218 | $back += $fwdDiff; |
| 219 | 219 | |
| 220 | - if($fwd > $maxFwd) { $fwd = $maxFwd; } |
|
| 221 | - if($back > $maxBack) { $back = $maxBack; } |
|
| 220 | + if ($fwd > $maxFwd) { $fwd = $maxFwd; } |
|
| 221 | + if ($back > $maxBack) { $back = $maxBack; } |
|
| 222 | 222 | |
| 223 | 223 | // calculate the first and last page in the list |
| 224 | 224 | $prev = $this->current - $back; |
| 225 | 225 | $next = $this->current + $fwd; |
| 226 | 226 | |
| 227 | 227 | // failsafe so we stay within the bounds |
| 228 | - if($prev < 1) { $prev = 1; } |
|
| 229 | - if($next > $this->last) { $next = $this->last; } |
|
| 228 | + if ($prev < 1) { $prev = 1; } |
|
| 229 | + if ($next > $this->last) { $next = $this->last; } |
|
| 230 | 230 | |
| 231 | 231 | // create and return the page numbers list |
| 232 | 232 | $numbers = range($prev, $next); |
@@ -319,37 +319,37 @@ discard block |
||
| 319 | 319 | { |
| 320 | 320 | $pages = (int)ceil($this->total / $this->perPage); |
| 321 | 321 | |
| 322 | - if($this->current < 1) |
|
| 322 | + if ($this->current < 1) |
|
| 323 | 323 | { |
| 324 | 324 | $this->current = 1; |
| 325 | 325 | } |
| 326 | - else if($this->current > $pages) |
|
| 326 | + else if ($this->current > $pages) |
|
| 327 | 327 | { |
| 328 | 328 | $this->current = $pages; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $offset = ($this->current-1) * $this->perPage; |
|
| 331 | + $offset = ($this->current - 1) * $this->perPage; |
|
| 332 | 332 | $this->last = $pages; |
| 333 | 333 | |
| 334 | 334 | $start = $offset; |
| 335 | - if($start === 0) { |
|
| 335 | + if ($start === 0) { |
|
| 336 | 336 | $start = 1; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | $nextPage = $this->current + 1; |
| 340 | - if($nextPage <= $pages) { |
|
| 340 | + if ($nextPage <= $pages) { |
|
| 341 | 341 | $this->next = $nextPage; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | $prevPage = $this->current - 1; |
| 345 | - if($prevPage > 0) { |
|
| 345 | + if ($prevPage > 0) { |
|
| 346 | 346 | $this->prev = $prevPage; |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | $this->offsetStart = ($this->current - 1) * $this->perPage; |
| 350 | 350 | |
| 351 | 351 | $this->offsetEnd = $this->offsetStart + $this->perPage; |
| 352 | - if($this->offsetEnd > ($this->total - 1)) { |
|
| 352 | + if ($this->offsetEnd > ($this->total - 1)) { |
|
| 353 | 353 | $this->offsetEnd = ($this->total - 1); |
| 354 | 354 | } |
| 355 | 355 | } |
@@ -322,8 +322,7 @@ |
||
| 322 | 322 | if($this->current < 1) |
| 323 | 323 | { |
| 324 | 324 | $this->current = 1; |
| 325 | - } |
|
| 326 | - else if($this->current > $pages) |
|
| 325 | + } else if($this->current > $pages) |
|
| 327 | 326 | { |
| 328 | 327 | $this->current = $pages; |
| 329 | 328 | } |
@@ -68,54 +68,54 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | const ERROR_GD_LIBRARY_NOT_INSTALLED = 513024; |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @var string |
|
| 73 | - */ |
|
| 71 | + /** |
|
| 72 | + * @var string |
|
| 73 | + */ |
|
| 74 | 74 | protected $file; |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @var ImageHelper_Size |
|
| 78 | - */ |
|
| 76 | + /** |
|
| 77 | + * @var ImageHelper_Size |
|
| 78 | + */ |
|
| 79 | 79 | protected $info; |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 81 | + /** |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | 84 | protected $type; |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @var resource|NULL |
|
| 88 | - */ |
|
| 86 | + /** |
|
| 87 | + * @var resource|NULL |
|
| 88 | + */ |
|
| 89 | 89 | protected $newImage; |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @var resource |
|
| 93 | - */ |
|
| 91 | + /** |
|
| 92 | + * @var resource |
|
| 93 | + */ |
|
| 94 | 94 | protected $sourceImage; |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @var int |
|
| 98 | - */ |
|
| 96 | + /** |
|
| 97 | + * @var int |
|
| 98 | + */ |
|
| 99 | 99 | protected $width; |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @var int |
|
| 103 | - */ |
|
| 101 | + /** |
|
| 102 | + * @var int |
|
| 103 | + */ |
|
| 104 | 104 | protected $height; |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @var int |
|
| 108 | - */ |
|
| 106 | + /** |
|
| 107 | + * @var int |
|
| 108 | + */ |
|
| 109 | 109 | protected $newWidth; |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @var int |
|
| 113 | - */ |
|
| 111 | + /** |
|
| 112 | + * @var int |
|
| 113 | + */ |
|
| 114 | 114 | protected $newHeight; |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * @var int |
|
| 118 | - */ |
|
| 116 | + /** |
|
| 117 | + * @var int |
|
| 118 | + */ |
|
| 119 | 119 | protected $quality = 85; |
| 120 | 120 | |
| 121 | 121 | protected static $imageTypes = array( |
@@ -203,31 +203,31 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Factory method: creates a new helper with a blank image. |
|
| 208 | - * |
|
| 209 | - * @param integer $width |
|
| 210 | - * @param integer $height |
|
| 211 | - * @param string $type The target file type when saving |
|
| 212 | - * @return ImageHelper |
|
| 213 | - */ |
|
| 206 | + /** |
|
| 207 | + * Factory method: creates a new helper with a blank image. |
|
| 208 | + * |
|
| 209 | + * @param integer $width |
|
| 210 | + * @param integer $height |
|
| 211 | + * @param string $type The target file type when saving |
|
| 212 | + * @return ImageHelper |
|
| 213 | + */ |
|
| 214 | 214 | public static function createNew($width, $height, $type='png') |
| 215 | 215 | { |
| 216 | 216 | return self::createFromResource(imagecreatetruecolor($width, $height), 'png'); |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Factory method: creates an image helper from an |
|
| 221 | - * existing image resource. |
|
| 222 | - * |
|
| 223 | - * Note: while the resource is type independent, the |
|
| 224 | - * type parameter is required for some methods, as well |
|
| 225 | - * as to be able to save the image. |
|
| 226 | - * |
|
| 227 | - * @param resource $resource |
|
| 228 | - * @param string $type The target image type, e.g. "jpeg", "png", etc. |
|
| 229 | - * @return ImageHelper |
|
| 230 | - */ |
|
| 219 | + /** |
|
| 220 | + * Factory method: creates an image helper from an |
|
| 221 | + * existing image resource. |
|
| 222 | + * |
|
| 223 | + * Note: while the resource is type independent, the |
|
| 224 | + * type parameter is required for some methods, as well |
|
| 225 | + * as to be able to save the image. |
|
| 226 | + * |
|
| 227 | + * @param resource $resource |
|
| 228 | + * @param string $type The target image type, e.g. "jpeg", "png", etc. |
|
| 229 | + * @return ImageHelper |
|
| 230 | + */ |
|
| 231 | 231 | public static function createFromResource($resource, string $type) |
| 232 | 232 | { |
| 233 | 233 | self::requireResource($resource); |
@@ -235,29 +235,29 @@ discard block |
||
| 235 | 235 | return new ImageHelper(null, $resource, $type); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Factory method: creates an image helper from an |
|
| 240 | - * image file on disk. |
|
| 241 | - * |
|
| 242 | - * @param string $path |
|
| 243 | - * @return ImageHelper |
|
| 244 | - */ |
|
| 238 | + /** |
|
| 239 | + * Factory method: creates an image helper from an |
|
| 240 | + * image file on disk. |
|
| 241 | + * |
|
| 242 | + * @param string $path |
|
| 243 | + * @return ImageHelper |
|
| 244 | + */ |
|
| 245 | 245 | public static function createFromFile($file) |
| 246 | 246 | { |
| 247 | 247 | return new ImageHelper($file); |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * Sets a global image helper configuration value. Available |
|
| 252 | - * configuration settings are: |
|
| 253 | - * |
|
| 254 | - * <ul> |
|
| 255 | - * <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> |
|
| 256 | - * </ul> |
|
| 257 | - * |
|
| 258 | - * @param string $name |
|
| 259 | - * @param mixed $value |
|
| 260 | - */ |
|
| 250 | + /** |
|
| 251 | + * Sets a global image helper configuration value. Available |
|
| 252 | + * configuration settings are: |
|
| 253 | + * |
|
| 254 | + * <ul> |
|
| 255 | + * <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> |
|
| 256 | + * </ul> |
|
| 257 | + * |
|
| 258 | + * @param string $name |
|
| 259 | + * @param mixed $value |
|
| 260 | + */ |
|
| 261 | 261 | public static function setConfig($name, $value) |
| 262 | 262 | { |
| 263 | 263 | if(isset(self::$config[$name])) { |
@@ -265,22 +265,22 @@ discard block |
||
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Shorthand for setting the automatic memory adjustment |
|
| 270 | - * global configuration setting. |
|
| 271 | - * |
|
| 272 | - * @param bool $enabled |
|
| 273 | - */ |
|
| 268 | + /** |
|
| 269 | + * Shorthand for setting the automatic memory adjustment |
|
| 270 | + * global configuration setting. |
|
| 271 | + * |
|
| 272 | + * @param bool $enabled |
|
| 273 | + */ |
|
| 274 | 274 | public static function setAutoMemoryAdjustment($enabled=true) |
| 275 | 275 | { |
| 276 | 276 | self::setConfig('auto-memory-adjustment', $enabled); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Duplicates an image resource. |
|
| 281 | - * @param resource $img |
|
| 282 | - * @return resource |
|
| 283 | - */ |
|
| 279 | + /** |
|
| 280 | + * Duplicates an image resource. |
|
| 281 | + * @param resource $img |
|
| 282 | + * @return resource |
|
| 283 | + */ |
|
| 284 | 284 | protected function duplicateImage($img) |
| 285 | 285 | { |
| 286 | 286 | self::requireResource($img); |
@@ -292,12 +292,12 @@ discard block |
||
| 292 | 292 | return $duplicate; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * Duplicates the current state of the image into a new |
|
| 297 | - * image helper instance. |
|
| 298 | - * |
|
| 299 | - * @return ImageHelper |
|
| 300 | - */ |
|
| 295 | + /** |
|
| 296 | + * Duplicates the current state of the image into a new |
|
| 297 | + * image helper instance. |
|
| 298 | + * |
|
| 299 | + * @return ImageHelper |
|
| 300 | + */ |
|
| 301 | 301 | public function duplicate() |
| 302 | 302 | { |
| 303 | 303 | return ImageHelper::createFromResource($this->duplicateImage($this->newImage)); |
@@ -485,13 +485,13 @@ discard block |
||
| 485 | 485 | )); |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - /** |
|
| 489 | - * Resamples the image to a new width, maintaining |
|
| 490 | - * aspect ratio. |
|
| 491 | - * |
|
| 492 | - * @param int $width |
|
| 493 | - * @return ImageHelper |
|
| 494 | - */ |
|
| 488 | + /** |
|
| 489 | + * Resamples the image to a new width, maintaining |
|
| 490 | + * aspect ratio. |
|
| 491 | + * |
|
| 492 | + * @param int $width |
|
| 493 | + * @return ImageHelper |
|
| 494 | + */ |
|
| 495 | 495 | public function resampleByWidth($width) |
| 496 | 496 | { |
| 497 | 497 | $size = $this->getSizeByWidth($width); |
@@ -501,12 +501,12 @@ discard block |
||
| 501 | 501 | return $this; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - /** |
|
| 505 | - * Resamples the image by height, and creates a new image file on disk. |
|
| 506 | - * |
|
| 507 | - * @param int $height |
|
| 508 | - * @return ImageHelper |
|
| 509 | - */ |
|
| 504 | + /** |
|
| 505 | + * Resamples the image by height, and creates a new image file on disk. |
|
| 506 | + * |
|
| 507 | + * @param int $height |
|
| 508 | + * @return ImageHelper |
|
| 509 | + */ |
|
| 510 | 510 | public function resampleByHeight($height) : ImageHelper |
| 511 | 511 | { |
| 512 | 512 | $size = $this->getSizeByHeight($height); |
@@ -514,13 +514,13 @@ discard block |
||
| 514 | 514 | return $this->resampleImage($size[0], $size[1]); |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - /** |
|
| 518 | - * Resamples the image without keeping the aspect ratio. |
|
| 519 | - * |
|
| 520 | - * @param int $width |
|
| 521 | - * @param int $height |
|
| 522 | - * @return ImageHelper |
|
| 523 | - */ |
|
| 517 | + /** |
|
| 518 | + * Resamples the image without keeping the aspect ratio. |
|
| 519 | + * |
|
| 520 | + * @param int $width |
|
| 521 | + * @param int $height |
|
| 522 | + * @return ImageHelper |
|
| 523 | + */ |
|
| 524 | 524 | public function resample($width = null, $height = null) : ImageHelper |
| 525 | 525 | { |
| 526 | 526 | if($this->isVector()) { |
@@ -585,12 +585,12 @@ discard block |
||
| 585 | 585 | |
| 586 | 586 | protected $alpha = false; |
| 587 | 587 | |
| 588 | - /** |
|
| 589 | - * Configures the specified image resource to make it alpha compatible. |
|
| 590 | - * |
|
| 591 | - * @param resource $canvas |
|
| 592 | - * @param bool $fill Whether to fill the whole canvas with the transparency |
|
| 593 | - */ |
|
| 588 | + /** |
|
| 589 | + * Configures the specified image resource to make it alpha compatible. |
|
| 590 | + * |
|
| 591 | + * @param resource $canvas |
|
| 592 | + * @param bool $fill Whether to fill the whole canvas with the transparency |
|
| 593 | + */ |
|
| 594 | 594 | public static function addAlphaSupport($canvas, $fill=true) |
| 595 | 595 | { |
| 596 | 596 | self::requireResource($canvas); |
@@ -713,12 +713,12 @@ discard block |
||
| 713 | 713 | $this->quality = $quality * 1; |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - /** |
|
| 717 | - * Attempts to adjust the memory to the required size |
|
| 718 | - * to work with the current image. |
|
| 719 | - * |
|
| 720 | - * @return boolean |
|
| 721 | - */ |
|
| 716 | + /** |
|
| 717 | + * Attempts to adjust the memory to the required size |
|
| 718 | + * to work with the current image. |
|
| 719 | + * |
|
| 720 | + * @return boolean |
|
| 721 | + */ |
|
| 722 | 722 | protected function adjustMemory() : bool |
| 723 | 723 | { |
| 724 | 724 | if(!self::$config['auto-memory-adjustment']) { |
@@ -758,27 +758,27 @@ discard block |
||
| 758 | 758 | return false; |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | - /** |
|
| 762 | - * Stretches the image to the specified dimensions. |
|
| 763 | - * |
|
| 764 | - * @param int $width |
|
| 765 | - * @param int $height |
|
| 766 | - * @return ImageHelper |
|
| 767 | - */ |
|
| 761 | + /** |
|
| 762 | + * Stretches the image to the specified dimensions. |
|
| 763 | + * |
|
| 764 | + * @param int $width |
|
| 765 | + * @param int $height |
|
| 766 | + * @return ImageHelper |
|
| 767 | + */ |
|
| 768 | 768 | public function stretch(int $width, int $height) : ImageHelper |
| 769 | 769 | { |
| 770 | 770 | return $this->resampleImage($width, $height); |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - /** |
|
| 774 | - * Creates a new image from the current image, |
|
| 775 | - * resampling it to the new size. |
|
| 776 | - * |
|
| 777 | - * @param int $newWidth |
|
| 778 | - * @param int $newHeight |
|
| 779 | - * @throws ImageHelper_Exception |
|
| 780 | - * @return ImageHelper |
|
| 781 | - */ |
|
| 773 | + /** |
|
| 774 | + * Creates a new image from the current image, |
|
| 775 | + * resampling it to the new size. |
|
| 776 | + * |
|
| 777 | + * @param int $newWidth |
|
| 778 | + * @param int $newHeight |
|
| 779 | + * @throws ImageHelper_Exception |
|
| 780 | + * @return ImageHelper |
|
| 781 | + */ |
|
| 782 | 782 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
| 783 | 783 | { |
| 784 | 784 | if($this->isVector()) { |
@@ -924,32 +924,32 @@ discard block |
||
| 924 | 924 | exit; |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | - /** |
|
| 928 | - * Displays the current image. |
|
| 929 | - */ |
|
| 927 | + /** |
|
| 928 | + * Displays the current image. |
|
| 929 | + */ |
|
| 930 | 930 | public function display() |
| 931 | 931 | { |
| 932 | 932 | $this->displayImageStream($this->newImage, $this->getType(), $this->resolveQuality()); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - /** |
|
| 936 | - * Trims the current loaded image. |
|
| 937 | - * |
|
| 938 | - * @param array $color A color definition, as an associative array with red, green, and blue keys. If not specified, the color at pixel position 0,0 will be used. |
|
| 939 | - */ |
|
| 935 | + /** |
|
| 936 | + * Trims the current loaded image. |
|
| 937 | + * |
|
| 938 | + * @param array $color A color definition, as an associative array with red, green, and blue keys. If not specified, the color at pixel position 0,0 will be used. |
|
| 939 | + */ |
|
| 940 | 940 | public function trim($color=null) |
| 941 | 941 | { |
| 942 | 942 | return $this->trimImage($this->newImage, $color); |
| 943 | 943 | } |
| 944 | 944 | |
| 945 | - /** |
|
| 946 | - * Trims the specified image resource by removing the specified color. |
|
| 947 | - * Also works with transparency. |
|
| 948 | - * |
|
| 949 | - * @param resource $img |
|
| 950 | - * @param array $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. |
|
| 951 | - * @return ImageHelper |
|
| 952 | - */ |
|
| 945 | + /** |
|
| 946 | + * Trims the specified image resource by removing the specified color. |
|
| 947 | + * Also works with transparency. |
|
| 948 | + * |
|
| 949 | + * @param resource $img |
|
| 950 | + * @param array $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. |
|
| 951 | + * @return ImageHelper |
|
| 952 | + */ |
|
| 953 | 953 | protected function trimImage($img, $color=null) : ImageHelper |
| 954 | 954 | { |
| 955 | 955 | if($this->isVector()) { |
@@ -1036,12 +1036,12 @@ discard block |
||
| 1036 | 1036 | return $this; |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | - /** |
|
| 1040 | - * Sets the new image after a transformation operation: |
|
| 1041 | - * automatically adjusts the new size information. |
|
| 1042 | - * |
|
| 1043 | - * @param resource $image |
|
| 1044 | - */ |
|
| 1039 | + /** |
|
| 1040 | + * Sets the new image after a transformation operation: |
|
| 1041 | + * automatically adjusts the new size information. |
|
| 1042 | + * |
|
| 1043 | + * @param resource $image |
|
| 1044 | + */ |
|
| 1045 | 1045 | protected function setNewImage($image) |
| 1046 | 1046 | { |
| 1047 | 1047 | self::requireResource($image); |
@@ -1051,12 +1051,12 @@ discard block |
||
| 1051 | 1051 | $this->newHeight= imagesy($image); |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | - /** |
|
| 1055 | - * Requires the subject to be a resource. |
|
| 1056 | - * |
|
| 1057 | - * @param resource $subject |
|
| 1058 | - * @throws ImageHelper_Exception |
|
| 1059 | - */ |
|
| 1054 | + /** |
|
| 1055 | + * Requires the subject to be a resource. |
|
| 1056 | + * |
|
| 1057 | + * @param resource $subject |
|
| 1058 | + * @throws ImageHelper_Exception |
|
| 1059 | + */ |
|
| 1060 | 1060 | protected static function requireResource($subject) |
| 1061 | 1061 | { |
| 1062 | 1062 | if(is_resource($subject)) { |
@@ -1073,14 +1073,14 @@ discard block |
||
| 1073 | 1073 | ); |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | - /** |
|
| 1077 | - * Creates a new image resource, with transparent background. |
|
| 1078 | - * |
|
| 1079 | - * @param int $width |
|
| 1080 | - * @param int $height |
|
| 1081 | - * @throws ImageHelper_Exception |
|
| 1082 | - * @return resource |
|
| 1083 | - */ |
|
| 1076 | + /** |
|
| 1077 | + * Creates a new image resource, with transparent background. |
|
| 1078 | + * |
|
| 1079 | + * @param int $width |
|
| 1080 | + * @param int $height |
|
| 1081 | + * @throws ImageHelper_Exception |
|
| 1082 | + * @return resource |
|
| 1083 | + */ |
|
| 1084 | 1084 | protected function createNewImage(int $width, int $height) |
| 1085 | 1085 | { |
| 1086 | 1086 | $img = imagecreatetruecolor($width, $height); |
@@ -1097,54 +1097,54 @@ discard block |
||
| 1097 | 1097 | return $img; |
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | - /** |
|
| 1101 | - * Whether the two specified colors are the same. |
|
| 1102 | - * |
|
| 1103 | - * @param array $a |
|
| 1104 | - * @param array $b |
|
| 1105 | - * @return boolean |
|
| 1106 | - */ |
|
| 1107 | - protected function colorsMatch($a, $b) : bool |
|
| 1108 | - { |
|
| 1109 | - $parts = array('red', 'green', 'blue'); |
|
| 1110 | - foreach($parts as $part) { |
|
| 1111 | - if($a[$part] != $b[$part]) { |
|
| 1112 | - return false; |
|
| 1113 | - } |
|
| 1114 | - } |
|
| 1100 | + /** |
|
| 1101 | + * Whether the two specified colors are the same. |
|
| 1102 | + * |
|
| 1103 | + * @param array $a |
|
| 1104 | + * @param array $b |
|
| 1105 | + * @return boolean |
|
| 1106 | + */ |
|
| 1107 | + protected function colorsMatch($a, $b) : bool |
|
| 1108 | + { |
|
| 1109 | + $parts = array('red', 'green', 'blue'); |
|
| 1110 | + foreach($parts as $part) { |
|
| 1111 | + if($a[$part] != $b[$part]) { |
|
| 1112 | + return false; |
|
| 1113 | + } |
|
| 1114 | + } |
|
| 1115 | 1115 | |
| 1116 | - return true; |
|
| 1117 | - } |
|
| 1116 | + return true; |
|
| 1117 | + } |
|
| 1118 | 1118 | |
| 1119 | - public function fillWhite($x=0, $y=0) |
|
| 1120 | - { |
|
| 1121 | - $this->addRGBColor('white', 255, 255, 255); |
|
| 1119 | + public function fillWhite($x=0, $y=0) |
|
| 1120 | + { |
|
| 1121 | + $this->addRGBColor('white', 255, 255, 255); |
|
| 1122 | 1122 | return $this->fill('white', $x, $y); |
| 1123 | - } |
|
| 1123 | + } |
|
| 1124 | 1124 | |
| 1125 | - public function fillTransparent() : ImageHelper |
|
| 1126 | - { |
|
| 1125 | + public function fillTransparent() : ImageHelper |
|
| 1126 | + { |
|
| 1127 | 1127 | $this->enableAlpha(); |
| 1128 | 1128 | |
| 1129 | - self::fillImageTransparent($this->newImage); |
|
| 1129 | + self::fillImageTransparent($this->newImage); |
|
| 1130 | 1130 | |
| 1131 | - return $this; |
|
| 1132 | - } |
|
| 1131 | + return $this; |
|
| 1132 | + } |
|
| 1133 | 1133 | |
| 1134 | - public static function fillImageTransparent($resource) |
|
| 1135 | - { |
|
| 1136 | - self::requireResource($resource); |
|
| 1134 | + public static function fillImageTransparent($resource) |
|
| 1135 | + { |
|
| 1136 | + self::requireResource($resource); |
|
| 1137 | 1137 | |
| 1138 | - $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
| 1139 | - imagecolortransparent ($resource, $transparent); |
|
| 1140 | - imagefill($resource, 0, 0, $transparent); |
|
| 1141 | - } |
|
| 1138 | + $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
| 1139 | + imagecolortransparent ($resource, $transparent); |
|
| 1140 | + imagefill($resource, 0, 0, $transparent); |
|
| 1141 | + } |
|
| 1142 | 1142 | |
| 1143 | - public function fill($colorName, $x=0, $y=0) |
|
| 1144 | - { |
|
| 1145 | - imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
| 1146 | - return $this; |
|
| 1147 | - } |
|
| 1143 | + public function fill($colorName, $x=0, $y=0) |
|
| 1144 | + { |
|
| 1145 | + imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
| 1146 | + return $this; |
|
| 1147 | + } |
|
| 1148 | 1148 | |
| 1149 | 1149 | protected $colors = array(); |
| 1150 | 1150 | |
@@ -1165,9 +1165,9 @@ discard block |
||
| 1165 | 1165 | return $this; |
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | - /** |
|
| 1169 | - * @return resource |
|
| 1170 | - */ |
|
| 1168 | + /** |
|
| 1169 | + * @return resource |
|
| 1170 | + */ |
|
| 1171 | 1171 | public function getImage() |
| 1172 | 1172 | { |
| 1173 | 1173 | return $this->newImage; |
@@ -1185,27 +1185,27 @@ discard block |
||
| 1185 | 1185 | return $this; |
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | - /** |
|
| 1189 | - * Retrieves the size of the image. |
|
| 1190 | - * |
|
| 1191 | - * @param bool $exception Whether to trigger an exception when the image does not exist |
|
| 1192 | - * @return ImageHelper_Size |
|
| 1193 | - * @throws ImageHelper_Exception |
|
| 1194 | - * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
| 1195 | - */ |
|
| 1196 | - public function getSize($exception=true) : ImageHelper_Size |
|
| 1188 | + /** |
|
| 1189 | + * Retrieves the size of the image. |
|
| 1190 | + * |
|
| 1191 | + * @param bool $exception Whether to trigger an exception when the image does not exist |
|
| 1192 | + * @return ImageHelper_Size |
|
| 1193 | + * @throws ImageHelper_Exception |
|
| 1194 | + * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
| 1195 | + */ |
|
| 1196 | + public function getSize($exception=true) : ImageHelper_Size |
|
| 1197 | 1197 | { |
| 1198 | - return self::getImageSize($this->newImage, $exception); |
|
| 1198 | + return self::getImageSize($this->newImage, $exception); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | protected $TTFFile; |
| 1202 | 1202 | |
| 1203 | - /** |
|
| 1204 | - * Sets the TTF font file to use for text operations. |
|
| 1205 | - * |
|
| 1206 | - * @param string $filePath |
|
| 1207 | - * @return ImageHelper |
|
| 1208 | - */ |
|
| 1203 | + /** |
|
| 1204 | + * Sets the TTF font file to use for text operations. |
|
| 1205 | + * |
|
| 1206 | + * @param string $filePath |
|
| 1207 | + * @return ImageHelper |
|
| 1208 | + */ |
|
| 1209 | 1209 | public function setFontTTF($filePath) |
| 1210 | 1210 | { |
| 1211 | 1211 | $this->TTFFile = $filePath; |
@@ -1277,160 +1277,160 @@ discard block |
||
| 1277 | 1277 | return; |
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | - throw new ImageHelper_Exception( |
|
| 1280 | + throw new ImageHelper_Exception( |
|
| 1281 | 1281 | 'No true type font specified', |
| 1282 | 1282 | 'This functionality requires a TTF font file to be specified with the [setFontTTF] method.', |
| 1283 | 1283 | self::ERROR_NO_TRUE_TYPE_FONT_SET |
| 1284 | 1284 | ); |
| 1285 | 1285 | } |
| 1286 | 1286 | |
| 1287 | - /** |
|
| 1288 | - * Retrieves the size of an image file on disk, or |
|
| 1289 | - * an existing image resource. |
|
| 1290 | - * |
|
| 1291 | - * <pre> |
|
| 1292 | - * array( |
|
| 1293 | - * 0: (width), |
|
| 1294 | - * 1: (height), |
|
| 1295 | - * "channels": the amount of channels |
|
| 1296 | - * "bits": bits per channel |
|
| 1287 | + /** |
|
| 1288 | + * Retrieves the size of an image file on disk, or |
|
| 1289 | + * an existing image resource. |
|
| 1290 | + * |
|
| 1291 | + * <pre> |
|
| 1292 | + * array( |
|
| 1293 | + * 0: (width), |
|
| 1294 | + * 1: (height), |
|
| 1295 | + * "channels": the amount of channels |
|
| 1296 | + * "bits": bits per channel |
|
| 1297 | 1297 | * ) |
| 1298 | - * </pre> |
|
| 1299 | - * |
|
| 1300 | - * @param string|resource $pathOrResource |
|
| 1301 | - * @param bool $exception Whether to trigger an exception when the image does not exist |
|
| 1302 | - * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize |
|
| 1303 | - * @see ImageHelper_Size |
|
| 1304 | - * @throws ImageHelper_Exception |
|
| 1305 | - * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
| 1306 | - * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE |
|
| 1307 | - * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
| 1308 | - * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
|
| 1309 | - */ |
|
| 1310 | - public static function getImageSize($pathOrResource, $exception=true) : ImageHelper_Size |
|
| 1311 | - { |
|
| 1312 | - if(is_resource($pathOrResource)) |
|
| 1313 | - { |
|
| 1314 | - return new ImageHelper_Size(array( |
|
| 1315 | - 'width' => imagesx($pathOrResource), |
|
| 1316 | - 'height' => imagesy($pathOrResource), |
|
| 1317 | - 'channels' => 1, |
|
| 1318 | - 'bits' => 8 |
|
| 1319 | - )); |
|
| 1320 | - } |
|
| 1298 | + * </pre> |
|
| 1299 | + * |
|
| 1300 | + * @param string|resource $pathOrResource |
|
| 1301 | + * @param bool $exception Whether to trigger an exception when the image does not exist |
|
| 1302 | + * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize |
|
| 1303 | + * @see ImageHelper_Size |
|
| 1304 | + * @throws ImageHelper_Exception |
|
| 1305 | + * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
| 1306 | + * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE |
|
| 1307 | + * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
| 1308 | + * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
|
| 1309 | + */ |
|
| 1310 | + public static function getImageSize($pathOrResource, $exception=true) : ImageHelper_Size |
|
| 1311 | + { |
|
| 1312 | + if(is_resource($pathOrResource)) |
|
| 1313 | + { |
|
| 1314 | + return new ImageHelper_Size(array( |
|
| 1315 | + 'width' => imagesx($pathOrResource), |
|
| 1316 | + 'height' => imagesy($pathOrResource), |
|
| 1317 | + 'channels' => 1, |
|
| 1318 | + 'bits' => 8 |
|
| 1319 | + )); |
|
| 1320 | + } |
|
| 1321 | 1321 | |
| 1322 | - $type = self::getFileImageType($pathOrResource); |
|
| 1322 | + $type = self::getFileImageType($pathOrResource); |
|
| 1323 | 1323 | |
| 1324 | - $info = false; |
|
| 1325 | - $method = 'getImageSize_'.$type; |
|
| 1326 | - if(method_exists(__CLASS__, $method)) |
|
| 1327 | - { |
|
| 1328 | - $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
|
| 1329 | - } |
|
| 1330 | - else |
|
| 1331 | - { |
|
| 1332 | - $info = getimagesize($pathOrResource); |
|
| 1333 | - } |
|
| 1324 | + $info = false; |
|
| 1325 | + $method = 'getImageSize_'.$type; |
|
| 1326 | + if(method_exists(__CLASS__, $method)) |
|
| 1327 | + { |
|
| 1328 | + $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
|
| 1329 | + } |
|
| 1330 | + else |
|
| 1331 | + { |
|
| 1332 | + $info = getimagesize($pathOrResource); |
|
| 1333 | + } |
|
| 1334 | 1334 | |
| 1335 | - if($info === false) { |
|
| 1336 | - if($exception) { |
|
| 1337 | - throw new ImageHelper_Exception( |
|
| 1338 | - 'Error opening image file', |
|
| 1339 | - sprintf( |
|
| 1340 | - 'Could not get image size for image [%s]', |
|
| 1341 | - $pathOrResource |
|
| 1342 | - ), |
|
| 1343 | - self::ERROR_CANNOT_GET_IMAGE_SIZE |
|
| 1344 | - ); |
|
| 1345 | - } |
|
| 1335 | + if($info === false) { |
|
| 1336 | + if($exception) { |
|
| 1337 | + throw new ImageHelper_Exception( |
|
| 1338 | + 'Error opening image file', |
|
| 1339 | + sprintf( |
|
| 1340 | + 'Could not get image size for image [%s]', |
|
| 1341 | + $pathOrResource |
|
| 1342 | + ), |
|
| 1343 | + self::ERROR_CANNOT_GET_IMAGE_SIZE |
|
| 1344 | + ); |
|
| 1345 | + } |
|
| 1346 | 1346 | |
| 1347 | - return false; |
|
| 1348 | - } |
|
| 1347 | + return false; |
|
| 1348 | + } |
|
| 1349 | 1349 | |
| 1350 | - return new ImageHelper_Size($info); |
|
| 1351 | - } |
|
| 1350 | + return new ImageHelper_Size($info); |
|
| 1351 | + } |
|
| 1352 | 1352 | |
| 1353 | - protected static function getImageSize_svg($imagePath) |
|
| 1354 | - { |
|
| 1355 | - $xml = XMLHelper::createSimplexml(); |
|
| 1356 | - $xml->loadFile($imagePath); |
|
| 1353 | + protected static function getImageSize_svg($imagePath) |
|
| 1354 | + { |
|
| 1355 | + $xml = XMLHelper::createSimplexml(); |
|
| 1356 | + $xml->loadFile($imagePath); |
|
| 1357 | 1357 | |
| 1358 | - if($xml->hasErrors()) { |
|
| 1359 | - throw new ImageHelper_Exception( |
|
| 1360 | - 'Error opening SVG image', |
|
| 1361 | - sprintf( |
|
| 1362 | - 'The XML content of the image [%s] could not be parsed.', |
|
| 1363 | - $imagePath |
|
| 1358 | + if($xml->hasErrors()) { |
|
| 1359 | + throw new ImageHelper_Exception( |
|
| 1360 | + 'Error opening SVG image', |
|
| 1361 | + sprintf( |
|
| 1362 | + 'The XML content of the image [%s] could not be parsed.', |
|
| 1363 | + $imagePath |
|
| 1364 | 1364 | ), |
| 1365 | - self::ERROR_CANNOT_READ_SVG_IMAGE |
|
| 1365 | + self::ERROR_CANNOT_READ_SVG_IMAGE |
|
| 1366 | 1366 | ); |
| 1367 | - } |
|
| 1367 | + } |
|
| 1368 | 1368 | |
| 1369 | - $data = $xml->toArray(); |
|
| 1370 | - $xml->dispose(); |
|
| 1371 | - unset($xml); |
|
| 1369 | + $data = $xml->toArray(); |
|
| 1370 | + $xml->dispose(); |
|
| 1371 | + unset($xml); |
|
| 1372 | 1372 | |
| 1373 | - if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
| 1374 | - throw new ImageHelper_Exception( |
|
| 1375 | - 'SVG Image is corrupted', |
|
| 1376 | - sprintf( |
|
| 1377 | - 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
| 1378 | - $imagePath |
|
| 1373 | + if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
| 1374 | + throw new ImageHelper_Exception( |
|
| 1375 | + 'SVG Image is corrupted', |
|
| 1376 | + sprintf( |
|
| 1377 | + 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
| 1378 | + $imagePath |
|
| 1379 | 1379 | ), |
| 1380 | - self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
| 1380 | + self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
| 1381 | 1381 | ); |
| 1382 | - } |
|
| 1382 | + } |
|
| 1383 | 1383 | |
| 1384 | - $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
| 1385 | - $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
| 1384 | + $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
| 1385 | + $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
| 1386 | 1386 | |
| 1387 | - $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
| 1388 | - $viewBox = explode(',', $viewBox); |
|
| 1389 | - if(count($viewBox) != 4) { |
|
| 1390 | - throw new ImageHelper_Exception( |
|
| 1391 | - 'SVG image has an invalid viewBox attribute', |
|
| 1392 | - sprintf( |
|
| 1393 | - 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
| 1394 | - $viewBox, |
|
| 1395 | - $imagePath |
|
| 1387 | + $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
| 1388 | + $viewBox = explode(',', $viewBox); |
|
| 1389 | + if(count($viewBox) != 4) { |
|
| 1390 | + throw new ImageHelper_Exception( |
|
| 1391 | + 'SVG image has an invalid viewBox attribute', |
|
| 1392 | + sprintf( |
|
| 1393 | + 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
| 1394 | + $viewBox, |
|
| 1395 | + $imagePath |
|
| 1396 | 1396 | ), |
| 1397 | - self::ERROR_SVG_VIEWBOX_INVALID |
|
| 1397 | + self::ERROR_SVG_VIEWBOX_INVALID |
|
| 1398 | 1398 | ); |
| 1399 | - } |
|
| 1399 | + } |
|
| 1400 | 1400 | |
| 1401 | - $boxWidth = $viewBox[2]; |
|
| 1402 | - $boxHeight = $viewBox[3]; |
|
| 1401 | + $boxWidth = $viewBox[2]; |
|
| 1402 | + $boxHeight = $viewBox[3]; |
|
| 1403 | 1403 | |
| 1404 | - // calculate the x and y units of the document: |
|
| 1405 | - // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
| 1406 | - // |
|
| 1407 | - // The viewbox combined with the width and heigt of the svg |
|
| 1408 | - // allow calculating how many pixels are in one unit of the |
|
| 1409 | - // width and height of the document. |
|
| 1404 | + // calculate the x and y units of the document: |
|
| 1405 | + // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
| 1406 | + // |
|
| 1407 | + // The viewbox combined with the width and heigt of the svg |
|
| 1408 | + // allow calculating how many pixels are in one unit of the |
|
| 1409 | + // width and height of the document. |
|
| 1410 | 1410 | // |
| 1411 | - $xUnits = $svgWidth / $boxWidth; |
|
| 1412 | - $yUnits = $svgHeight / $boxHeight; |
|
| 1411 | + $xUnits = $svgWidth / $boxWidth; |
|
| 1412 | + $yUnits = $svgHeight / $boxHeight; |
|
| 1413 | 1413 | |
| 1414 | - $pxWidth = $xUnits * $svgWidth; |
|
| 1415 | - $pxHeight = $yUnits * $svgHeight; |
|
| 1414 | + $pxWidth = $xUnits * $svgWidth; |
|
| 1415 | + $pxHeight = $yUnits * $svgHeight; |
|
| 1416 | 1416 | |
| 1417 | - return array( |
|
| 1418 | - $pxWidth, |
|
| 1419 | - $pxHeight, |
|
| 1420 | - 'bits' => 8 |
|
| 1421 | - ); |
|
| 1422 | - } |
|
| 1417 | + return array( |
|
| 1418 | + $pxWidth, |
|
| 1419 | + $pxHeight, |
|
| 1420 | + 'bits' => 8 |
|
| 1421 | + ); |
|
| 1422 | + } |
|
| 1423 | 1423 | |
| 1424 | - /** |
|
| 1425 | - * Crops the image to the specified width and height, optionally |
|
| 1426 | - * specifying the origin position to crop from. |
|
| 1427 | - * |
|
| 1428 | - * @param integer $width |
|
| 1429 | - * @param integer $height |
|
| 1430 | - * @param integer $x |
|
| 1431 | - * @param integer $y |
|
| 1432 | - * @return ImageHelper |
|
| 1433 | - */ |
|
| 1424 | + /** |
|
| 1425 | + * Crops the image to the specified width and height, optionally |
|
| 1426 | + * specifying the origin position to crop from. |
|
| 1427 | + * |
|
| 1428 | + * @param integer $width |
|
| 1429 | + * @param integer $height |
|
| 1430 | + * @param integer $x |
|
| 1431 | + * @param integer $y |
|
| 1432 | + * @return ImageHelper |
|
| 1433 | + */ |
|
| 1434 | 1434 | public function crop($width, $height, $x=0, $y=0) |
| 1435 | 1435 | { |
| 1436 | 1436 | $new = $this->createNewImage($width, $height); |
@@ -1452,13 +1452,13 @@ discard block |
||
| 1452 | 1452 | return $this->newHeight; |
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | - /** |
|
| 1456 | - * Calculates the average color value used in |
|
| 1457 | - * the image. Returns an associative array |
|
| 1458 | - * with the red, green, blue and alpha components. |
|
| 1459 | - * |
|
| 1460 | - * @return array |
|
| 1461 | - */ |
|
| 1455 | + /** |
|
| 1456 | + * Calculates the average color value used in |
|
| 1457 | + * the image. Returns an associative array |
|
| 1458 | + * with the red, green, blue and alpha components. |
|
| 1459 | + * |
|
| 1460 | + * @return array |
|
| 1461 | + */ |
|
| 1462 | 1462 | public function calcAverageColor($format=self::COLORFORMAT_RGB) |
| 1463 | 1463 | { |
| 1464 | 1464 | $image = $this->duplicate(); |
@@ -1480,14 +1480,14 @@ discard block |
||
| 1480 | 1480 | |
| 1481 | 1481 | const COLORFORMAT_HEX = 2; |
| 1482 | 1482 | |
| 1483 | - /** |
|
| 1484 | - * Retrieves the color value at the specified pixel |
|
| 1485 | - * coordinates in the image. |
|
| 1486 | - * |
|
| 1487 | - * @param int $x |
|
| 1488 | - * @param int $y |
|
| 1489 | - * @return array |
|
| 1490 | - */ |
|
| 1483 | + /** |
|
| 1484 | + * Retrieves the color value at the specified pixel |
|
| 1485 | + * coordinates in the image. |
|
| 1486 | + * |
|
| 1487 | + * @param int $x |
|
| 1488 | + * @param int $y |
|
| 1489 | + * @return array |
|
| 1490 | + */ |
|
| 1491 | 1491 | public function getColorAt($x, $y, $format=self::COLORFORMAT_RGB) |
| 1492 | 1492 | { |
| 1493 | 1493 | if($x > $this->getWidth() || $y > $this->getHeight()) { |
@@ -1514,21 +1514,21 @@ discard block |
||
| 1514 | 1514 | return $rgb; |
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | - /** |
|
| 1518 | - * Converts an RGB value to its luminance equivalent. |
|
| 1519 | - * |
|
| 1520 | - * @param array $rgb |
|
| 1521 | - * @return integer Integer, from 0 to 255 (0=black, 255=white) |
|
| 1522 | - */ |
|
| 1517 | + /** |
|
| 1518 | + * Converts an RGB value to its luminance equivalent. |
|
| 1519 | + * |
|
| 1520 | + * @param array $rgb |
|
| 1521 | + * @return integer Integer, from 0 to 255 (0=black, 255=white) |
|
| 1522 | + */ |
|
| 1523 | 1523 | public static function rgb2luma($rgb) |
| 1524 | 1524 | { |
| 1525 | 1525 | return (($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6; |
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | - /** |
|
| 1529 | - * Retrieves the brightness of the image, in percent. |
|
| 1530 | - * @return number |
|
| 1531 | - */ |
|
| 1528 | + /** |
|
| 1529 | + * Retrieves the brightness of the image, in percent. |
|
| 1530 | + * @return number |
|
| 1531 | + */ |
|
| 1532 | 1532 | public function getBrightness() |
| 1533 | 1533 | { |
| 1534 | 1534 | $luma = self::rgb2luma($this->calcAverageColor()); |
@@ -1536,15 +1536,15 @@ discard block |
||
| 1536 | 1536 | return $percent; |
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | - /** |
|
| 1540 | - * Retrieves an md5 hash of the source image file. |
|
| 1541 | - * |
|
| 1542 | - * NOTE: Only works when the helper has been created |
|
| 1543 | - * from a file. Otherwise an exception is thrown. |
|
| 1544 | - * |
|
| 1545 | - * @return string |
|
| 1546 | - * @throws ImageHelper_Exception |
|
| 1547 | - */ |
|
| 1539 | + /** |
|
| 1540 | + * Retrieves an md5 hash of the source image file. |
|
| 1541 | + * |
|
| 1542 | + * NOTE: Only works when the helper has been created |
|
| 1543 | + * from a file. Otherwise an exception is thrown. |
|
| 1544 | + * |
|
| 1545 | + * @return string |
|
| 1546 | + * @throws ImageHelper_Exception |
|
| 1547 | + */ |
|
| 1548 | 1548 | public function getHash() |
| 1549 | 1549 | { |
| 1550 | 1550 | ob_start(); |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | 'gif' |
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | - public function __construct($sourceFile=null, $resource=null, $type=null) |
|
| 139 | + public function __construct($sourceFile = null, $resource = null, $type = null) |
|
| 140 | 140 | { |
| 141 | 141 | // ensure that the GD library is installed |
| 142 | - if(!function_exists('imagecreate')) |
|
| 142 | + if (!function_exists('imagecreate')) |
|
| 143 | 143 | { |
| 144 | 144 | throw new ImageHelper_Exception( |
| 145 | 145 | 'The PHP GD extension is not installed or not enabled.', |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if(is_resource($resource)) |
|
| 151 | + if (is_resource($resource)) |
|
| 152 | 152 | { |
| 153 | 153 | $this->sourceImage = $resource; |
| 154 | 154 | $this->type = $type; |
@@ -172,21 +172,21 @@ discard block |
||
| 172 | 172 | if (is_null($this->type)) { |
| 173 | 173 | throw new ImageHelper_Exception( |
| 174 | 174 | 'Error opening image', |
| 175 | - 'Not a valid supported image type for image ' . $this->file, |
|
| 175 | + 'Not a valid supported image type for image '.$this->file, |
|
| 176 | 176 | self::ERROR_UNSUPPORTED_IMAGE_TYPE |
| 177 | 177 | ); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | $this->info = self::getImageSize($this->file); |
| 181 | 181 | |
| 182 | - if(!$this->isVector()) |
|
| 182 | + if (!$this->isVector()) |
|
| 183 | 183 | { |
| 184 | - $method = 'imagecreatefrom' . $this->type; |
|
| 184 | + $method = 'imagecreatefrom'.$this->type; |
|
| 185 | 185 | $this->sourceImage = $method($this->file); |
| 186 | 186 | if (!$this->sourceImage) { |
| 187 | 187 | throw new ImageHelper_Exception( |
| 188 | 188 | 'Error creating new image', |
| 189 | - $method . ' failed', |
|
| 189 | + $method.' failed', |
|
| 190 | 190 | self::ERROR_FAILED_TO_CREATE_NEW_IMAGE |
| 191 | 191 | ); |
| 192 | 192 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $this->width = $this->info->getWidth(); |
| 199 | 199 | $this->height = $this->info->getHeight(); |
| 200 | 200 | |
| 201 | - if(!$this->isVector()) { |
|
| 201 | + if (!$this->isVector()) { |
|
| 202 | 202 | $this->setNewImage($this->duplicateImage($this->sourceImage, true)); |
| 203 | 203 | } |
| 204 | 204 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @param string $type The target file type when saving |
| 212 | 212 | * @return ImageHelper |
| 213 | 213 | */ |
| 214 | - public static function createNew($width, $height, $type='png') |
|
| 214 | + public static function createNew($width, $height, $type = 'png') |
|
| 215 | 215 | { |
| 216 | 216 | return self::createFromResource(imagecreatetruecolor($width, $height), 'png'); |
| 217 | 217 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | public static function setConfig($name, $value) |
| 262 | 262 | { |
| 263 | - if(isset(self::$config[$name])) { |
|
| 263 | + if (isset(self::$config[$name])) { |
|
| 264 | 264 | self::$config[$name] = $value; |
| 265 | 265 | } |
| 266 | 266 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * |
| 272 | 272 | * @param bool $enabled |
| 273 | 273 | */ |
| 274 | - public static function setAutoMemoryAdjustment($enabled=true) |
|
| 274 | + public static function setAutoMemoryAdjustment($enabled = true) |
|
| 275 | 275 | { |
| 276 | 276 | self::setConfig('auto-memory-adjustment', $enabled); |
| 277 | 277 | } |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | |
| 306 | 306 | public function enableAlpha() |
| 307 | 307 | { |
| 308 | - if(!$this->alpha) |
|
| 308 | + if (!$this->alpha) |
|
| 309 | 309 | { |
| 310 | 310 | self::addAlphaSupport($this->newImage, false); |
| 311 | 311 | $this->alpha = true; |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | * @param number $percent |
| 337 | 337 | * @return ImageHelper |
| 338 | 338 | */ |
| 339 | - public function sharpen($percent=0) |
|
| 339 | + public function sharpen($percent = 0) |
|
| 340 | 340 | { |
| 341 | - if($percent <= 0) { |
|
| 341 | + if ($percent <= 0) { |
|
| 342 | 342 | return $this; |
| 343 | 343 | } |
| 344 | 344 | |
@@ -347,9 +347,9 @@ discard block |
||
| 347 | 347 | return $this->convolute($factor); |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - public function blur($percent=0) |
|
| 350 | + public function blur($percent = 0) |
|
| 351 | 351 | { |
| 352 | - if($percent <= 0) { |
|
| 352 | + if ($percent <= 0) { |
|
| 353 | 353 | return $this; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | { |
| 363 | 363 | // get a value thats equal to 64 - abs( factor ) |
| 364 | 364 | // ( using min/max to limited the factor to 0 - 64 to not get out of range values ) |
| 365 | - $val1Adjustment = 64 - min( 64, max( 0, abs( $factor ) ) ); |
|
| 365 | + $val1Adjustment = 64 - min(64, max(0, abs($factor))); |
|
| 366 | 366 | |
| 367 | 367 | // the base factor for the "current" pixel depends on if we are blurring or sharpening. |
| 368 | 368 | // If we are blurring use 1, if sharpening use 9. |
| 369 | 369 | $val1Base = 9; |
| 370 | - if( abs( $factor ) != $factor ) { |
|
| 370 | + if (abs($factor) != $factor) { |
|
| 371 | 371 | $val1Base = 1; |
| 372 | 372 | } |
| 373 | 373 | |
@@ -380,24 +380,24 @@ discard block |
||
| 380 | 380 | |
| 381 | 381 | // the value for the surrounding pixels is either positive or negative depending on if we are blurring or sharpening. |
| 382 | 382 | $val2 = -1; |
| 383 | - if( abs( $factor ) != $factor ) { |
|
| 383 | + if (abs($factor) != $factor) { |
|
| 384 | 384 | $val2 = 1; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | // setup matrix .. |
| 388 | 388 | $matrix = array( |
| 389 | - array( $val2, $val2, $val2 ), |
|
| 390 | - array( $val2, $val1, $val2 ), |
|
| 391 | - array( $val2, $val2, $val2 ) |
|
| 389 | + array($val2, $val2, $val2), |
|
| 390 | + array($val2, $val1, $val2), |
|
| 391 | + array($val2, $val2, $val2) |
|
| 392 | 392 | ); |
| 393 | 393 | |
| 394 | 394 | // calculate the correct divisor |
| 395 | 395 | // actual divisor is equal to "$divisor = $val1 + $val2 * 8;" |
| 396 | 396 | // but the following line is more generic |
| 397 | - $divisor = array_sum( array_map( 'array_sum', $matrix ) ); |
|
| 397 | + $divisor = array_sum(array_map('array_sum', $matrix)); |
|
| 398 | 398 | |
| 399 | 399 | // apply the matrix |
| 400 | - imageconvolution( $this->newImage, $matrix, $divisor, 0 ); |
|
| 400 | + imageconvolution($this->newImage, $matrix, $divisor, 0); |
|
| 401 | 401 | |
| 402 | 402 | return $this; |
| 403 | 403 | } |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | */ |
| 524 | 524 | public function resample($width = null, $height = null) : ImageHelper |
| 525 | 525 | { |
| 526 | - if($this->isVector()) { |
|
| 526 | + if ($this->isVector()) { |
|
| 527 | 527 | return $this; |
| 528 | 528 | } |
| 529 | 529 | |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | public function resampleAndCrop($width, $height) : ImageHelper |
| 546 | 546 | { |
| 547 | - if($this->isVector()) { |
|
| 547 | + if ($this->isVector()) { |
|
| 548 | 548 | return $this; |
| 549 | 549 | } |
| 550 | 550 | |
@@ -591,14 +591,14 @@ discard block |
||
| 591 | 591 | * @param resource $canvas |
| 592 | 592 | * @param bool $fill Whether to fill the whole canvas with the transparency |
| 593 | 593 | */ |
| 594 | - public static function addAlphaSupport($canvas, $fill=true) |
|
| 594 | + public static function addAlphaSupport($canvas, $fill = true) |
|
| 595 | 595 | { |
| 596 | 596 | self::requireResource($canvas); |
| 597 | 597 | |
| 598 | - imagealphablending($canvas,true); |
|
| 598 | + imagealphablending($canvas, true); |
|
| 599 | 599 | imagesavealpha($canvas, true); |
| 600 | 600 | |
| 601 | - if($fill) { |
|
| 601 | + if ($fill) { |
|
| 602 | 602 | self::fillImageTransparent($canvas); |
| 603 | 603 | } |
| 604 | 604 | } |
@@ -608,9 +608,9 @@ discard block |
||
| 608 | 608 | return $this->alpha; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | - public function save(string $targetFile, $dispose=true) |
|
| 611 | + public function save(string $targetFile, $dispose = true) |
|
| 612 | 612 | { |
| 613 | - if($this->isVector()) { |
|
| 613 | + if ($this->isVector()) { |
|
| 614 | 614 | return true; |
| 615 | 615 | } |
| 616 | 616 | |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | ); |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - if($this->newImage === false) { |
|
| 625 | + if ($this->newImage === false) { |
|
| 626 | 626 | throw new ImageHelper_Exception( |
| 627 | 627 | 'Cannot save image, not a valid image resource', |
| 628 | 628 | 'The image is not a resource, but boolean false', |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | unlink($targetFile); |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | - $method = 'image' . $this->type; |
|
| 637 | + $method = 'image'.$this->type; |
|
| 638 | 638 | if (!$method($this->newImage, $targetFile, $this->resolveQuality())) { |
| 639 | 639 | throw new ImageHelper_Exception( |
| 640 | 640 | 'Error creating new image', |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | ); |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | - if($dispose) { |
|
| 658 | + if ($dispose) { |
|
| 659 | 659 | $this->dispose(); |
| 660 | 660 | } |
| 661 | 661 | |
@@ -664,11 +664,11 @@ discard block |
||
| 664 | 664 | |
| 665 | 665 | public function dispose() |
| 666 | 666 | { |
| 667 | - if(is_resource($this->sourceImage)) { |
|
| 667 | + if (is_resource($this->sourceImage)) { |
|
| 668 | 668 | imagedestroy($this->sourceImage); |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - if(is_resource($this->newImage)) { |
|
| 671 | + if (is_resource($this->newImage)) { |
|
| 672 | 672 | imagedestroy($this->newImage); |
| 673 | 673 | } |
| 674 | 674 | } |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | */ |
| 722 | 722 | protected function adjustMemory() : bool |
| 723 | 723 | { |
| 724 | - if(!self::$config['auto-memory-adjustment']) { |
|
| 724 | + if (!self::$config['auto-memory-adjustment']) { |
|
| 725 | 725 | return true; |
| 726 | 726 | } |
| 727 | 727 | |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) { |
| 751 | 751 | $newLimit = ($memoryLimit + (memory_get_usage() + $memoryNeeded)) / $MB; |
| 752 | 752 | $newLimit = ceil($newLimit); |
| 753 | - ini_set('memory_limit', $newLimit . 'M'); |
|
| 753 | + ini_set('memory_limit', $newLimit.'M'); |
|
| 754 | 754 | |
| 755 | 755 | return true; |
| 756 | 756 | } |
@@ -781,19 +781,19 @@ discard block |
||
| 781 | 781 | */ |
| 782 | 782 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
| 783 | 783 | { |
| 784 | - if($this->isVector()) { |
|
| 784 | + if ($this->isVector()) { |
|
| 785 | 785 | return $this; |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | - if(is_null($newWidth)) { $newWidth = $this->newWidth; } |
|
| 789 | - if(is_null($newHeight)) { $newHeight = $this->newHeight; } |
|
| 788 | + if (is_null($newWidth)) { $newWidth = $this->newWidth; } |
|
| 789 | + if (is_null($newHeight)) { $newHeight = $this->newHeight; } |
|
| 790 | 790 | |
| 791 | - if($this->newWidth==$newWidth && $this->newHeight==$newHeight) { |
|
| 791 | + if ($this->newWidth == $newWidth && $this->newHeight == $newHeight) { |
|
| 792 | 792 | return $this; |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - if($newWidth < 1) { $newWidth = 1; } |
|
| 796 | - if($newHeight < 1) { $newHeight = 1; } |
|
| 795 | + if ($newWidth < 1) { $newWidth = 1; } |
|
| 796 | + if ($newHeight < 1) { $newHeight = 1; } |
|
| 797 | 797 | |
| 798 | 798 | $this->adjustMemory(); |
| 799 | 799 | |
@@ -857,11 +857,11 @@ discard block |
||
| 857 | 857 | * @param string $imageType The image format to send, i.e. "jpeg", "png" |
| 858 | 858 | * @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 |
| 859 | 859 | */ |
| 860 | - public static function displayImageStream($resource, $imageType, $quality=-1) |
|
| 860 | + public static function displayImageStream($resource, $imageType, $quality = -1) |
|
| 861 | 861 | { |
| 862 | 862 | $imageType = strtolower($imageType); |
| 863 | 863 | |
| 864 | - if(!in_array($imageType, self::$streamTypes)) { |
|
| 864 | + if (!in_array($imageType, self::$streamTypes)) { |
|
| 865 | 865 | throw new ImageHelper_Exception( |
| 866 | 866 | 'Invalid image stream type', |
| 867 | 867 | sprintf( |
@@ -872,9 +872,9 @@ discard block |
||
| 872 | 872 | ); |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - header('Content-type:image/' . $imageType); |
|
| 875 | + header('Content-type:image/'.$imageType); |
|
| 876 | 876 | |
| 877 | - $function = 'image' . $imageType; |
|
| 877 | + $function = 'image'.$imageType; |
|
| 878 | 878 | |
| 879 | 879 | $function($resource, null, $quality); |
| 880 | 880 | |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | if (headers_sent($file, $line)) { |
| 893 | 893 | throw new ImageHelper_Exception( |
| 894 | 894 | 'Error displaying image', |
| 895 | - 'Headers have already been sent: in file ' . $file . ':' . $line, |
|
| 895 | + 'Headers have already been sent: in file '.$file.':'.$line, |
|
| 896 | 896 | self::ERROR_HEADERS_ALREADY_SENT |
| 897 | 897 | ); |
| 898 | 898 | } |
@@ -909,16 +909,16 @@ discard block |
||
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | $format = self::getFileImageType($imageFile); |
| 912 | - if($format == 'svg') { |
|
| 912 | + if ($format == 'svg') { |
|
| 913 | 913 | $format = 'svg+xml'; |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | - $contentType = 'image/' . $format; |
|
| 916 | + $contentType = 'image/'.$format; |
|
| 917 | 917 | |
| 918 | 918 | header('Content-Type: '.$contentType); |
| 919 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($imageFile)) . " GMT"); |
|
| 919 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($imageFile))." GMT"); |
|
| 920 | 920 | header('Cache-Control: public'); |
| 921 | - header('Content-Length: ' . filesize($imageFile)); |
|
| 921 | + header('Content-Length: '.filesize($imageFile)); |
|
| 922 | 922 | |
| 923 | 923 | readfile($imageFile); |
| 924 | 924 | exit; |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | * |
| 938 | 938 | * @param array $color A color definition, as an associative array with red, green, and blue keys. If not specified, the color at pixel position 0,0 will be used. |
| 939 | 939 | */ |
| 940 | - public function trim($color=null) |
|
| 940 | + public function trim($color = null) |
|
| 941 | 941 | { |
| 942 | 942 | return $this->trimImage($this->newImage, $color); |
| 943 | 943 | } |
@@ -950,15 +950,15 @@ discard block |
||
| 950 | 950 | * @param array $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. |
| 951 | 951 | * @return ImageHelper |
| 952 | 952 | */ |
| 953 | - protected function trimImage($img, $color=null) : ImageHelper |
|
| 953 | + protected function trimImage($img, $color = null) : ImageHelper |
|
| 954 | 954 | { |
| 955 | - if($this->isVector()) { |
|
| 955 | + if ($this->isVector()) { |
|
| 956 | 956 | return $this; |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | self::requireResource($img); |
| 960 | 960 | |
| 961 | - if(empty($color)) { |
|
| 961 | + if (empty($color)) { |
|
| 962 | 962 | $color = imagecolorat($img, 0, 0); |
| 963 | 963 | $color = imagecolorsforindex($img, $color); |
| 964 | 964 | } |
@@ -974,16 +974,16 @@ discard block |
||
| 974 | 974 | $ymax = null; |
| 975 | 975 | |
| 976 | 976 | // Start scanning for the edges. |
| 977 | - for ($iy=0; $iy<$imh; $iy++) |
|
| 977 | + for ($iy = 0; $iy < $imh; $iy++) |
|
| 978 | 978 | { |
| 979 | 979 | $first = true; |
| 980 | 980 | |
| 981 | - for ($ix=0; $ix<$imw; $ix++) |
|
| 981 | + for ($ix = 0; $ix < $imw; $ix++) |
|
| 982 | 982 | { |
| 983 | 983 | $ndx = imagecolorat($img, $ix, $iy); |
| 984 | 984 | $colors = imagecolorsforindex($img, $ndx); |
| 985 | 985 | |
| 986 | - if(!$this->colorsMatch($colors, $color)) |
|
| 986 | + if (!$this->colorsMatch($colors, $color)) |
|
| 987 | 987 | { |
| 988 | 988 | if ($xmin > $ix) { $xmin = $ix; } |
| 989 | 989 | if ($xmax < $ix) { $xmax = $ix; } |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | |
| 992 | 992 | $ymax = $iy; |
| 993 | 993 | |
| 994 | - if($first) |
|
| 994 | + if ($first) |
|
| 995 | 995 | { |
| 996 | 996 | $ix = $xmax; |
| 997 | 997 | $first = false; |
@@ -1001,18 +1001,18 @@ discard block |
||
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | // no trimming border found |
| 1004 | - if($ymax === null && $ymax === null) { |
|
| 1004 | + if ($ymax === null && $ymax === null) { |
|
| 1005 | 1005 | return $this; |
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | // The new width and height of the image. |
| 1009 | - $imw = 1+$xmax-$xmin; // Image width in pixels |
|
| 1010 | - $imh = 1+$ymax-$ymin; // Image height in pixels |
|
| 1009 | + $imw = 1 + $xmax - $xmin; // Image width in pixels |
|
| 1010 | + $imh = 1 + $ymax - $ymin; // Image height in pixels |
|
| 1011 | 1011 | |
| 1012 | 1012 | // Make another image to place the trimmed version in. |
| 1013 | 1013 | $im2 = $this->createNewImage($imw, $imh); |
| 1014 | 1014 | |
| 1015 | - if($color['alpha'] > 0) |
|
| 1015 | + if ($color['alpha'] > 0) |
|
| 1016 | 1016 | { |
| 1017 | 1017 | $bg2 = imagecolorallocatealpha($im2, $color['red'], $color['green'], $color['blue'], $color['alpha']); |
| 1018 | 1018 | imagecolortransparent($im2, $bg2); |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | |
| 1049 | 1049 | $this->newImage = $image; |
| 1050 | 1050 | $this->newWidth = imagesx($image); |
| 1051 | - $this->newHeight= imagesy($image); |
|
| 1051 | + $this->newHeight = imagesy($image); |
|
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | /** |
@@ -1059,7 +1059,7 @@ discard block |
||
| 1059 | 1059 | */ |
| 1060 | 1060 | protected static function requireResource($subject) |
| 1061 | 1061 | { |
| 1062 | - if(is_resource($subject)) { |
|
| 1062 | + if (is_resource($subject)) { |
|
| 1063 | 1063 | return; |
| 1064 | 1064 | } |
| 1065 | 1065 | |
@@ -1107,8 +1107,8 @@ discard block |
||
| 1107 | 1107 | protected function colorsMatch($a, $b) : bool |
| 1108 | 1108 | { |
| 1109 | 1109 | $parts = array('red', 'green', 'blue'); |
| 1110 | - foreach($parts as $part) { |
|
| 1111 | - if($a[$part] != $b[$part]) { |
|
| 1110 | + foreach ($parts as $part) { |
|
| 1111 | + if ($a[$part] != $b[$part]) { |
|
| 1112 | 1112 | return false; |
| 1113 | 1113 | } |
| 1114 | 1114 | } |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | return true; |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | - public function fillWhite($x=0, $y=0) |
|
| 1119 | + public function fillWhite($x = 0, $y = 0) |
|
| 1120 | 1120 | { |
| 1121 | 1121 | $this->addRGBColor('white', 255, 255, 255); |
| 1122 | 1122 | return $this->fill('white', $x, $y); |
@@ -1136,11 +1136,11 @@ discard block |
||
| 1136 | 1136 | self::requireResource($resource); |
| 1137 | 1137 | |
| 1138 | 1138 | $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
| 1139 | - imagecolortransparent ($resource, $transparent); |
|
| 1139 | + imagecolortransparent($resource, $transparent); |
|
| 1140 | 1140 | imagefill($resource, 0, 0, $transparent); |
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | - public function fill($colorName, $x=0, $y=0) |
|
| 1143 | + public function fill($colorName, $x = 0, $y = 0) |
|
| 1144 | 1144 | { |
| 1145 | 1145 | imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
| 1146 | 1146 | return $this; |
@@ -1154,7 +1154,7 @@ discard block |
||
| 1154 | 1154 | return $this; |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - public function textTTF($text, $size, $colorName, $x=0, $y=0, $angle=0) |
|
| 1157 | + public function textTTF($text, $size, $colorName, $x = 0, $y = 0, $angle = 0) |
|
| 1158 | 1158 | { |
| 1159 | 1159 | imagealphablending($this->newImage, true); |
| 1160 | 1160 | |
@@ -1173,11 +1173,11 @@ discard block |
||
| 1173 | 1173 | return $this->newImage; |
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | - public function paste(ImageHelper $target, $xpos=0, $ypos=0, $sourceX=0, $sourceY=0) |
|
| 1176 | + public function paste(ImageHelper $target, $xpos = 0, $ypos = 0, $sourceX = 0, $sourceY = 0) |
|
| 1177 | 1177 | { |
| 1178 | 1178 | $img = $target->getImage(); |
| 1179 | 1179 | |
| 1180 | - if($target->isAlpha()) { |
|
| 1180 | + if ($target->isAlpha()) { |
|
| 1181 | 1181 | $this->enableAlpha(); |
| 1182 | 1182 | } |
| 1183 | 1183 | |
@@ -1193,7 +1193,7 @@ discard block |
||
| 1193 | 1193 | * @throws ImageHelper_Exception |
| 1194 | 1194 | * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
| 1195 | 1195 | */ |
| 1196 | - public function getSize($exception=true) : ImageHelper_Size |
|
| 1196 | + public function getSize($exception = true) : ImageHelper_Size |
|
| 1197 | 1197 | { |
| 1198 | 1198 | return self::getImageSize($this->newImage, $exception); |
| 1199 | 1199 | } |
@@ -1223,10 +1223,10 @@ discard block |
||
| 1223 | 1223 | public function fitText($text, $matchWidth) |
| 1224 | 1224 | { |
| 1225 | 1225 | $sizes = array(); |
| 1226 | - for($i=1; $i<=1000; $i=$i+0.1) { |
|
| 1226 | + for ($i = 1; $i <= 1000; $i = $i + 0.1) { |
|
| 1227 | 1227 | $size = $this->calcTextSize($text, $i); |
| 1228 | 1228 | $sizes[] = $size; |
| 1229 | - if($size['width'] >= $matchWidth) { |
|
| 1229 | + if ($size['width'] >= $matchWidth) { |
|
| 1230 | 1230 | break; |
| 1231 | 1231 | } |
| 1232 | 1232 | } |
@@ -1238,7 +1238,7 @@ discard block |
||
| 1238 | 1238 | $diffLast = $last['width'] - $matchWidth; |
| 1239 | 1239 | $diffPrev = $matchWidth - $prev['width']; |
| 1240 | 1240 | |
| 1241 | - if($diffLast <= $diffPrev) { |
|
| 1241 | + if ($diffLast <= $diffPrev) { |
|
| 1242 | 1242 | return $last; |
| 1243 | 1243 | } |
| 1244 | 1244 | |
@@ -1266,14 +1266,14 @@ discard block |
||
| 1266 | 1266 | 'bottom_left_y' => $box[1], |
| 1267 | 1267 | 'bottom_right_x' => $box[2], |
| 1268 | 1268 | 'bottom_right_y' => $box[3], |
| 1269 | - 'width' => $right-$left, |
|
| 1270 | - 'height' => $bottom-$top |
|
| 1269 | + 'width' => $right - $left, |
|
| 1270 | + 'height' => $bottom - $top |
|
| 1271 | 1271 | ); |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | protected function requireTTFFont() |
| 1275 | 1275 | { |
| 1276 | - if(isset($this->TTFFile)) { |
|
| 1276 | + if (isset($this->TTFFile)) { |
|
| 1277 | 1277 | return; |
| 1278 | 1278 | } |
| 1279 | 1279 | |
@@ -1307,9 +1307,9 @@ discard block |
||
| 1307 | 1307 | * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
| 1308 | 1308 | * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
| 1309 | 1309 | */ |
| 1310 | - public static function getImageSize($pathOrResource, $exception=true) : ImageHelper_Size |
|
| 1310 | + public static function getImageSize($pathOrResource, $exception = true) : ImageHelper_Size |
|
| 1311 | 1311 | { |
| 1312 | - if(is_resource($pathOrResource)) |
|
| 1312 | + if (is_resource($pathOrResource)) |
|
| 1313 | 1313 | { |
| 1314 | 1314 | return new ImageHelper_Size(array( |
| 1315 | 1315 | 'width' => imagesx($pathOrResource), |
@@ -1323,7 +1323,7 @@ discard block |
||
| 1323 | 1323 | |
| 1324 | 1324 | $info = false; |
| 1325 | 1325 | $method = 'getImageSize_'.$type; |
| 1326 | - if(method_exists(__CLASS__, $method)) |
|
| 1326 | + if (method_exists(__CLASS__, $method)) |
|
| 1327 | 1327 | { |
| 1328 | 1328 | $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
| 1329 | 1329 | } |
@@ -1332,8 +1332,8 @@ discard block |
||
| 1332 | 1332 | $info = getimagesize($pathOrResource); |
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | - if($info === false) { |
|
| 1336 | - if($exception) { |
|
| 1335 | + if ($info === false) { |
|
| 1336 | + if ($exception) { |
|
| 1337 | 1337 | throw new ImageHelper_Exception( |
| 1338 | 1338 | 'Error opening image file', |
| 1339 | 1339 | sprintf( |
@@ -1355,7 +1355,7 @@ discard block |
||
| 1355 | 1355 | $xml = XMLHelper::createSimplexml(); |
| 1356 | 1356 | $xml->loadFile($imagePath); |
| 1357 | 1357 | |
| 1358 | - if($xml->hasErrors()) { |
|
| 1358 | + if ($xml->hasErrors()) { |
|
| 1359 | 1359 | throw new ImageHelper_Exception( |
| 1360 | 1360 | 'Error opening SVG image', |
| 1361 | 1361 | sprintf( |
@@ -1370,7 +1370,7 @@ discard block |
||
| 1370 | 1370 | $xml->dispose(); |
| 1371 | 1371 | unset($xml); |
| 1372 | 1372 | |
| 1373 | - if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
| 1373 | + if (!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
| 1374 | 1374 | throw new ImageHelper_Exception( |
| 1375 | 1375 | 'SVG Image is corrupted', |
| 1376 | 1376 | sprintf( |
@@ -1386,7 +1386,7 @@ discard block |
||
| 1386 | 1386 | |
| 1387 | 1387 | $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
| 1388 | 1388 | $viewBox = explode(',', $viewBox); |
| 1389 | - if(count($viewBox) != 4) { |
|
| 1389 | + if (count($viewBox) != 4) { |
|
| 1390 | 1390 | throw new ImageHelper_Exception( |
| 1391 | 1391 | 'SVG image has an invalid viewBox attribute', |
| 1392 | 1392 | sprintf( |
@@ -1431,7 +1431,7 @@ discard block |
||
| 1431 | 1431 | * @param integer $y |
| 1432 | 1432 | * @return ImageHelper |
| 1433 | 1433 | */ |
| 1434 | - public function crop($width, $height, $x=0, $y=0) |
|
| 1434 | + public function crop($width, $height, $x = 0, $y = 0) |
|
| 1435 | 1435 | { |
| 1436 | 1436 | $new = $this->createNewImage($width, $height); |
| 1437 | 1437 | |
@@ -1459,7 +1459,7 @@ discard block |
||
| 1459 | 1459 | * |
| 1460 | 1460 | * @return array |
| 1461 | 1461 | */ |
| 1462 | - public function calcAverageColor($format=self::COLORFORMAT_RGB) |
|
| 1462 | + public function calcAverageColor($format = self::COLORFORMAT_RGB) |
|
| 1463 | 1463 | { |
| 1464 | 1464 | $image = $this->duplicate(); |
| 1465 | 1465 | $image->resample(1, 1); |
@@ -1488,9 +1488,9 @@ discard block |
||
| 1488 | 1488 | * @param int $y |
| 1489 | 1489 | * @return array |
| 1490 | 1490 | */ |
| 1491 | - public function getColorAt($x, $y, $format=self::COLORFORMAT_RGB) |
|
| 1491 | + public function getColorAt($x, $y, $format = self::COLORFORMAT_RGB) |
|
| 1492 | 1492 | { |
| 1493 | - if($x > $this->getWidth() || $y > $this->getHeight()) { |
|
| 1493 | + if ($x > $this->getWidth() || $y > $this->getHeight()) { |
|
| 1494 | 1494 | throw new ImageHelper_Exception( |
| 1495 | 1495 | 'Position out of bounds', |
| 1496 | 1496 | sprintf( |
@@ -1507,7 +1507,7 @@ discard block |
||
| 1507 | 1507 | $idx = imagecolorat($this->newImage, $x, $y); |
| 1508 | 1508 | $rgb = imagecolorsforindex($this->newImage, $idx); |
| 1509 | 1509 | |
| 1510 | - if($format == self::COLORFORMAT_HEX) { |
|
| 1510 | + if ($format == self::COLORFORMAT_HEX) { |
|
| 1511 | 1511 | return self::rgb2hex($rgb); |
| 1512 | 1512 | } |
| 1513 | 1513 | |
@@ -1522,7 +1522,7 @@ discard block |
||
| 1522 | 1522 | */ |
| 1523 | 1523 | public static function rgb2luma($rgb) |
| 1524 | 1524 | { |
| 1525 | - return (($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6; |
|
| 1525 | + return (($rgb['red'] * 2) + $rgb['blue'] + ($rgb['green'] * 3)) / 6; |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | 1528 | /** |
@@ -153,8 +153,7 @@ discard block |
||
| 153 | 153 | $this->sourceImage = $resource; |
| 154 | 154 | $this->type = $type; |
| 155 | 155 | $this->info = self::getImageSize($resource); |
| 156 | - } |
|
| 157 | - else |
|
| 156 | + } else |
|
| 158 | 157 | { |
| 159 | 158 | $this->file = $sourceFile; |
| 160 | 159 | if (!file_exists($this->file)) { |
@@ -551,8 +550,7 @@ discard block |
||
| 551 | 550 | if ($this->width <= $this->height) |
| 552 | 551 | { |
| 553 | 552 | return $this->resampleByWidth($width); |
| 554 | - } |
|
| 555 | - else |
|
| 553 | + } else |
|
| 556 | 554 | { |
| 557 | 555 | return $this->resampleByHeight($height); |
| 558 | 556 | } |
@@ -1016,8 +1014,7 @@ discard block |
||
| 1016 | 1014 | { |
| 1017 | 1015 | $bg2 = imagecolorallocatealpha($im2, $color['red'], $color['green'], $color['blue'], $color['alpha']); |
| 1018 | 1016 | imagecolortransparent($im2, $bg2); |
| 1019 | - } |
|
| 1020 | - else |
|
| 1017 | + } else |
|
| 1021 | 1018 | { |
| 1022 | 1019 | $bg2 = imagecolorallocate($im2, $color['red'], $color['green'], $color['blue']); |
| 1023 | 1020 | } |
@@ -1326,8 +1323,7 @@ discard block |
||
| 1326 | 1323 | if(method_exists(__CLASS__, $method)) |
| 1327 | 1324 | { |
| 1328 | 1325 | $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
| 1329 | - } |
|
| 1330 | - else |
|
| 1326 | + } else |
|
| 1331 | 1327 | { |
| 1332 | 1328 | $info = getimagesize($pathOrResource); |
| 1333 | 1329 | } |