@@ -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')) |
@@ -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 | } |
@@ -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, $this->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); |
@@ -235,12 +235,12 @@ discard block |
||
| 235 | 235 | return $this; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Checks whether a section with the specified name exists. |
|
| 240 | - * |
|
| 241 | - * @param string $name |
|
| 242 | - * @return bool |
|
| 243 | - */ |
|
| 238 | + /** |
|
| 239 | + * Checks whether a section with the specified name exists. |
|
| 240 | + * |
|
| 241 | + * @param string $name |
|
| 242 | + * @return bool |
|
| 243 | + */ |
|
| 244 | 244 | public function sectionExists(string $name) : bool |
| 245 | 245 | { |
| 246 | 246 | foreach($this->sections as $section) { |
@@ -252,23 +252,23 @@ discard block |
||
| 252 | 252 | return false; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Retrieves the default section, which is used to add |
|
| 257 | - * values in the root of the document. |
|
| 258 | - * |
|
| 259 | - * @return IniHelper_Section |
|
| 260 | - */ |
|
| 255 | + /** |
|
| 256 | + * Retrieves the default section, which is used to add |
|
| 257 | + * values in the root of the document. |
|
| 258 | + * |
|
| 259 | + * @return IniHelper_Section |
|
| 260 | + */ |
|
| 261 | 261 | public function getDefaultSection() : IniHelper_Section |
| 262 | 262 | { |
| 263 | 263 | return $this->addSection(self::SECTION_DEFAULT); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Retrieves all variable lines for the specified path. |
|
| 268 | - * |
|
| 269 | - * @param string $path A variable path. Either <code>varname</code> or <code>section.varname</code>. |
|
| 270 | - * @return array|\AppUtils\IniHelper_Line[] |
|
| 271 | - */ |
|
| 266 | + /** |
|
| 267 | + * Retrieves all variable lines for the specified path. |
|
| 268 | + * |
|
| 269 | + * @param string $path A variable path. Either <code>varname</code> or <code>section.varname</code>. |
|
| 270 | + * @return array|\AppUtils\IniHelper_Line[] |
|
| 271 | + */ |
|
| 272 | 272 | public function getLinesByVariable(string $path) |
| 273 | 273 | { |
| 274 | 274 | $path = $this->parsePath($path); |
@@ -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; |
@@ -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)."'"; |
@@ -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; |
@@ -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(); |
@@ -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 | } |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | return $this instanceof SVNHelper_Target_Folder; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Runs an update of the file or folder. |
|
| 81 | - * @return SVNHelper_Command_Update |
|
| 82 | - */ |
|
| 79 | + /** |
|
| 80 | + * Runs an update of the file or folder. |
|
| 81 | + * @return SVNHelper_Command_Update |
|
| 82 | + */ |
|
| 83 | 83 | public function runUpdate() |
| 84 | 84 | { |
| 85 | 85 | $cmd = $this->createUpdate(); |
@@ -88,55 +88,55 @@ discard block |
||
| 88 | 88 | return $cmd; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Creates an update command instance for the target file or folder. |
|
| 93 | - * @return SVNHelper_Command_Update |
|
| 94 | - */ |
|
| 91 | + /** |
|
| 92 | + * Creates an update command instance for the target file or folder. |
|
| 93 | + * @return SVNHelper_Command_Update |
|
| 94 | + */ |
|
| 95 | 95 | public function createUpdate() |
| 96 | 96 | { |
| 97 | 97 | return $this->helper->createUpdate($this); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Creates a status command instance for the target file or folder. |
|
| 102 | - * @return SVNHelper_Command_Status |
|
| 103 | - */ |
|
| 100 | + /** |
|
| 101 | + * Creates a status command instance for the target file or folder. |
|
| 102 | + * @return SVNHelper_Command_Status |
|
| 103 | + */ |
|
| 104 | 104 | public function createStatus() |
| 105 | 105 | { |
| 106 | 106 | return $this->helper->createStatus($this); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Creates an info command instance for the target file or folder. |
|
| 111 | - * @return SVNHelper_Command_Info |
|
| 112 | - */ |
|
| 109 | + /** |
|
| 110 | + * Creates an info command instance for the target file or folder. |
|
| 111 | + * @return SVNHelper_Command_Info |
|
| 112 | + */ |
|
| 113 | 113 | public function createInfo() |
| 114 | 114 | { |
| 115 | 115 | return $this->helper->createInfo($this); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Creates a commit command instance for the target file or folder. |
|
| 120 | - * @param string $message |
|
| 121 | - * @return SVNHelper_Command_Commit |
|
| 122 | - */ |
|
| 118 | + /** |
|
| 119 | + * Creates a commit command instance for the target file or folder. |
|
| 120 | + * @param string $message |
|
| 121 | + * @return SVNHelper_Command_Commit |
|
| 122 | + */ |
|
| 123 | 123 | public function createCommit($message) |
| 124 | 124 | { |
| 125 | 125 | return $this->helper->createCommit($this, $message); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Creates an add command instance for the target file or folder. |
|
| 130 | - * @return SVNHelper_Command_Add |
|
| 131 | - */ |
|
| 128 | + /** |
|
| 129 | + * Creates an add command instance for the target file or folder. |
|
| 130 | + * @return SVNHelper_Command_Add |
|
| 131 | + */ |
|
| 132 | 132 | public function createAdd() |
| 133 | 133 | { |
| 134 | 134 | return $this->helper->createAdd($this); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * @return SVNHelper_Command_Status |
|
| 139 | - */ |
|
| 137 | + /** |
|
| 138 | + * @return SVNHelper_Command_Status |
|
| 139 | + */ |
|
| 140 | 140 | public function getStatus() |
| 141 | 141 | { |
| 142 | 142 | $cmd = $this->createStatus(); |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | return $this; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Whether the target is versioned or needs to be added. |
|
| 159 | - * @return boolean |
|
| 160 | - */ |
|
| 157 | + /** |
|
| 158 | + * Whether the target is versioned or needs to be added. |
|
| 159 | + * @return boolean |
|
| 160 | + */ |
|
| 161 | 161 | public function isVersioned() |
| 162 | 162 | { |
| 163 | 163 | return $this->getInfo()->isVersioned(); |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | $this->cache = array(); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * Retrieves information on the target. |
|
| 175 | - * @return SVNHelper_Command_Info |
|
| 176 | - */ |
|
| 173 | + /** |
|
| 174 | + * Retrieves information on the target. |
|
| 175 | + * @return SVNHelper_Command_Info |
|
| 176 | + */ |
|
| 177 | 177 | public function getInfo() |
| 178 | 178 | { |
| 179 | 179 | if(!isset($this->cache['info'])) { |
@@ -183,15 +183,15 @@ discard block |
||
| 183 | 183 | return $this->cache['info']; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Commits the target file or folder. If it has |
|
| 188 | - * not been added to the repository yet, it is |
|
| 189 | - * added automatically beforehand. If it does |
|
| 190 | - * not need to be committed, no changes are made. |
|
| 191 | - * |
|
| 192 | - * @param string $message |
|
| 193 | - * @return SVNHelper_Target |
|
| 194 | - */ |
|
| 186 | + /** |
|
| 187 | + * Commits the target file or folder. If it has |
|
| 188 | + * not been added to the repository yet, it is |
|
| 189 | + * added automatically beforehand. If it does |
|
| 190 | + * not need to be committed, no changes are made. |
|
| 191 | + * |
|
| 192 | + * @param string $message |
|
| 193 | + * @return SVNHelper_Target |
|
| 194 | + */ |
|
| 195 | 195 | public function runCommit($message) |
| 196 | 196 | { |
| 197 | 197 | if(!$this->isVersioned()) { |
@@ -202,8 +202,7 @@ |
||
| 202 | 202 | if(!$this->isCommitted()) { |
| 203 | 203 | $this->createCommit($message)->execute(); |
| 204 | 204 | $this->clearCache(); |
| 205 | - } |
|
| 206 | - else |
|
| 205 | + } else |
|
| 207 | 206 | { |
| 208 | 207 | $this->log('Already committed, nothing to do.'); |
| 209 | 208 | } |
@@ -21,18 +21,18 @@ discard block |
||
| 21 | 21 | const SVN_ERROR_TYPE_WARNING = 'warning'; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * @var SVNHelper |
|
| 25 | - */ |
|
| 24 | + * @var SVNHelper |
|
| 25 | + */ |
|
| 26 | 26 | protected $helper; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var SVNHelper_Target |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var SVNHelper_Target |
|
| 30 | + */ |
|
| 31 | 31 | protected $target; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var SVNHelper_CommandResult |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var SVNHelper_CommandResult |
|
| 35 | + */ |
|
| 36 | 36 | protected $result; |
| 37 | 37 | |
| 38 | 38 | public function __construct(SVNHelper $helper, SVNHelper_Target $target) |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | $this->target = $target; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return SVNHelper |
|
| 46 | - */ |
|
| 44 | + /** |
|
| 45 | + * @return SVNHelper |
|
| 46 | + */ |
|
| 47 | 47 | public function getSVN() |
| 48 | 48 | { |
| 49 | 49 | return $this->helper; |
@@ -99,15 +99,15 @@ discard block |
||
| 99 | 99 | return $cmd; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Executes the specified command, and returns a result |
|
| 104 | - * instance to read the results. |
|
| 105 | - * |
|
| 106 | - * @param string $mode The command mode, e.g. commit / update... |
|
| 107 | - * @param string $path The path to apply the command to |
|
| 108 | - * @param array $params |
|
| 109 | - * @return SVNHelper_CommandResult |
|
| 110 | - */ |
|
| 102 | + /** |
|
| 103 | + * Executes the specified command, and returns a result |
|
| 104 | + * instance to read the results. |
|
| 105 | + * |
|
| 106 | + * @param string $mode The command mode, e.g. commit / update... |
|
| 107 | + * @param string $path The path to apply the command to |
|
| 108 | + * @param array $params |
|
| 109 | + * @return SVNHelper_CommandResult |
|
| 110 | + */ |
|
| 111 | 111 | protected function execCommand($mode, $path=null, $params=array()) |
| 112 | 112 | { |
| 113 | 113 | $relative = $this->helper->relativizePath($path); |
@@ -194,10 +194,10 @@ discard block |
||
| 194 | 194 | return $this->result; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Retrieves the type of command, e.g. "Commit" |
|
| 199 | - * @return string |
|
| 200 | - */ |
|
| 197 | + /** |
|
| 198 | + * Retrieves the type of command, e.g. "Commit" |
|
| 199 | + * @return string |
|
| 200 | + */ |
|
| 201 | 201 | public function getType() |
| 202 | 202 | { |
| 203 | 203 | return str_replace('SVNHelper_Command_', '', get_class($this)); |
@@ -4,37 +4,37 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class SVNHelper_CommandResult |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var SVNHelper_Command |
|
| 9 | - */ |
|
| 7 | + /** |
|
| 8 | + * @var SVNHelper_Command |
|
| 9 | + */ |
|
| 10 | 10 | protected $command; |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string[] |
|
| 14 | - */ |
|
| 12 | + /** |
|
| 13 | + * @var string[] |
|
| 14 | + */ |
|
| 15 | 15 | protected $output; |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var SVNHelper_CommandError[] |
|
| 19 | - */ |
|
| 17 | + /** |
|
| 18 | + * @var SVNHelper_CommandError[] |
|
| 19 | + */ |
|
| 20 | 20 | protected $errors = array(); |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var SVNHelper_CommandError[] |
|
| 24 | - */ |
|
| 22 | + /** |
|
| 23 | + * @var SVNHelper_CommandError[] |
|
| 24 | + */ |
|
| 25 | 25 | protected $warnings = array(); |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * The actual command that has been executed |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 27 | + /** |
|
| 28 | + * The actual command that has been executed |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | 31 | protected $commandLine; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param SVNHelper_Command $command |
|
| 35 | - * @param string[] $output |
|
| 36 | - * @param SVNHelper_CommandError[] $errors |
|
| 37 | - */ |
|
| 33 | + /** |
|
| 34 | + * @param SVNHelper_Command $command |
|
| 35 | + * @param string[] $output |
|
| 36 | + * @param SVNHelper_CommandError[] $errors |
|
| 37 | + */ |
|
| 38 | 38 | public function __construct(SVNHelper_Command $command, $commandLine, $output, $errors) |
| 39 | 39 | { |
| 40 | 40 | $this->command = $command; |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | return $this->command; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Retrieves all error messages. |
|
| 91 | - * |
|
| 92 | - * @param string $asString |
|
| 93 | - * @return string|string[] |
|
| 94 | - */ |
|
| 89 | + /** |
|
| 90 | + * Retrieves all error messages. |
|
| 91 | + * |
|
| 92 | + * @param string $asString |
|
| 93 | + * @return string|string[] |
|
| 94 | + */ |
|
| 95 | 95 | public function getErrorMessages($asString=false) |
| 96 | 96 | { |
| 97 | 97 | if($asString) { |
@@ -44,12 +44,12 @@ |
||
| 44 | 44 | return $result; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Whether the file or folder has already been committed |
|
| 49 | - * and has no pending changes. |
|
| 50 | - * |
|
| 51 | - * @return boolean |
|
| 52 | - */ |
|
| 47 | + /** |
|
| 48 | + * Whether the file or folder has already been committed |
|
| 49 | + * and has no pending changes. |
|
| 50 | + * |
|
| 51 | + * @return boolean |
|
| 52 | + */ |
|
| 53 | 53 | public function isCommitted() |
| 54 | 54 | { |
| 55 | 55 | $status = $this->target->getStatus(); |