@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | use Traits_Optionable; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var array<string,mixed> |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var array<string,mixed> |
|
| 28 | + */ |
|
| 29 | 29 | private $overrides = array(); |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var Request_RefreshParams_Exclude[] |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var Request_RefreshParams_Exclude[] |
|
| 33 | + */ |
|
| 34 | 34 | private $excludes = array(); |
| 35 | 35 | |
| 36 | 36 | public function getDefaultOptions() : array |
@@ -41,27 +41,27 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Whether to automatically exclude the session variable |
|
| 46 | - * from the parameters. |
|
| 47 | - * |
|
| 48 | - * @param bool $exclude |
|
| 49 | - * @return Request_RefreshParams |
|
| 50 | - */ |
|
| 44 | + /** |
|
| 45 | + * Whether to automatically exclude the session variable |
|
| 46 | + * from the parameters. |
|
| 47 | + * |
|
| 48 | + * @param bool $exclude |
|
| 49 | + * @return Request_RefreshParams |
|
| 50 | + */ |
|
| 51 | 51 | public function setExcludeSessionName(bool $exclude=true) : Request_RefreshParams |
| 52 | 52 | { |
| 53 | 53 | $this->setOption('exclude-session-name', $exclude); |
| 54 | 54 | return $this; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Whether to automatically exclude the HTML_QuickForm2 |
|
| 59 | - * request variable used to track whether a form has been |
|
| 60 | - * submitted. |
|
| 61 | - * |
|
| 62 | - * @param bool $exclude |
|
| 63 | - * @return Request_RefreshParams |
|
| 64 | - */ |
|
| 57 | + /** |
|
| 58 | + * Whether to automatically exclude the HTML_QuickForm2 |
|
| 59 | + * request variable used to track whether a form has been |
|
| 60 | + * submitted. |
|
| 61 | + * |
|
| 62 | + * @param bool $exclude |
|
| 63 | + * @return Request_RefreshParams |
|
| 64 | + */ |
|
| 65 | 65 | public function setExcludeQuickform(bool $exclude) : Request_RefreshParams |
| 66 | 66 | { |
| 67 | 67 | $this->setOption('exclude-quickform-submitter', $exclude); |
@@ -78,20 +78,20 @@ discard block |
||
| 78 | 78 | return $this; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Exclude a request using a callback function. |
|
| 83 | - * |
|
| 84 | - * The function gets two parameters: |
|
| 85 | - * |
|
| 86 | - * - The name of the request parameter |
|
| 87 | - * - The value of the request parameter |
|
| 88 | - * |
|
| 89 | - * If the callback returns a boolean true, the |
|
| 90 | - * parameter will be excluded. |
|
| 91 | - * |
|
| 92 | - * @param callable $callback |
|
| 93 | - * @return Request_RefreshParams |
|
| 94 | - */ |
|
| 81 | + /** |
|
| 82 | + * Exclude a request using a callback function. |
|
| 83 | + * |
|
| 84 | + * The function gets two parameters: |
|
| 85 | + * |
|
| 86 | + * - The name of the request parameter |
|
| 87 | + * - The value of the request parameter |
|
| 88 | + * |
|
| 89 | + * If the callback returns a boolean true, the |
|
| 90 | + * parameter will be excluded. |
|
| 91 | + * |
|
| 92 | + * @param callable $callback |
|
| 93 | + * @return Request_RefreshParams |
|
| 94 | + */ |
|
| 95 | 95 | public function excludeParamByCallback($callback) : Request_RefreshParams |
| 96 | 96 | { |
| 97 | 97 | $this->excludes[] = new Request_RefreshParams_Exclude_Callback($callback); |
@@ -99,12 +99,12 @@ discard block |
||
| 99 | 99 | return $this; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Excludes a request parameter by name. |
|
| 104 | - * |
|
| 105 | - * @param array $paramNames |
|
| 106 | - * @return Request_RefreshParams |
|
| 107 | - */ |
|
| 102 | + /** |
|
| 103 | + * Excludes a request parameter by name. |
|
| 104 | + * |
|
| 105 | + * @param array $paramNames |
|
| 106 | + * @return Request_RefreshParams |
|
| 107 | + */ |
|
| 108 | 108 | public function excludeParamsByName(array $paramNames) : Request_RefreshParams |
| 109 | 109 | { |
| 110 | 110 | foreach($paramNames as $name) |
@@ -115,15 +115,15 @@ discard block |
||
| 115 | 115 | return $this; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Overrides a parameter: even if it exists, this |
|
| 120 | - * value will be used instead - even if it is on |
|
| 121 | - * the list of excluded parameters. |
|
| 122 | - * |
|
| 123 | - * @param string $paramName |
|
| 124 | - * @param mixed $paramValue |
|
| 125 | - * @return Request_RefreshParams |
|
| 126 | - */ |
|
| 118 | + /** |
|
| 119 | + * Overrides a parameter: even if it exists, this |
|
| 120 | + * value will be used instead - even if it is on |
|
| 121 | + * the list of excluded parameters. |
|
| 122 | + * |
|
| 123 | + * @param string $paramName |
|
| 124 | + * @param mixed $paramValue |
|
| 125 | + * @return Request_RefreshParams |
|
| 126 | + */ |
|
| 127 | 127 | public function overrideParam(string $paramName, $paramValue) : Request_RefreshParams |
| 128 | 128 | { |
| 129 | 129 | $this->overrides[$paramName] = $paramValue; |
@@ -131,12 +131,12 @@ discard block |
||
| 131 | 131 | return $this; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Overrides an array of parameters. |
|
| 136 | - * |
|
| 137 | - * @param array $params |
|
| 138 | - * @return Request_RefreshParams |
|
| 139 | - */ |
|
| 134 | + /** |
|
| 135 | + * Overrides an array of parameters. |
|
| 136 | + * |
|
| 137 | + * @param array $params |
|
| 138 | + * @return Request_RefreshParams |
|
| 139 | + */ |
|
| 140 | 140 | public function overrideParams(array $params) : Request_RefreshParams |
| 141 | 141 | { |
| 142 | 142 | foreach($params as $name => $value) |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | return $this; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Resolves all the parameter exclusions that should |
|
| 152 | - * be applied to the list of parameters. This includes |
|
| 153 | - * the manually added exclusions and the dynamic exclusions |
|
| 154 | - * like the session name. |
|
| 155 | - * |
|
| 156 | - * @return Request_RefreshParams_Exclude[] |
|
| 157 | - */ |
|
| 150 | + /** |
|
| 151 | + * Resolves all the parameter exclusions that should |
|
| 152 | + * be applied to the list of parameters. This includes |
|
| 153 | + * the manually added exclusions and the dynamic exclusions |
|
| 154 | + * like the session name. |
|
| 155 | + * |
|
| 156 | + * @return Request_RefreshParams_Exclude[] |
|
| 157 | + */ |
|
| 158 | 158 | private function resolveExcludes() : array |
| 159 | 159 | { |
| 160 | 160 | $excludes = $this->excludes; |
@@ -165,12 +165,12 @@ discard block |
||
| 165 | 165 | return $excludes; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Automatically excludes the session name from the |
|
| 170 | - * parameters, if present. |
|
| 171 | - * |
|
| 172 | - * @param Request_RefreshParams_Exclude[] $excludes |
|
| 173 | - */ |
|
| 168 | + /** |
|
| 169 | + * Automatically excludes the session name from the |
|
| 170 | + * parameters, if present. |
|
| 171 | + * |
|
| 172 | + * @param Request_RefreshParams_Exclude[] $excludes |
|
| 173 | + */ |
|
| 174 | 174 | private function autoExcludeSessionName(array &$excludes) : void |
| 175 | 175 | { |
| 176 | 176 | if($this->getBoolOption('exclude-session-name')) |
@@ -179,12 +179,12 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Automatically excludes the HTML_QuickForm2 submit |
|
| 184 | - * tracking variable, when enabled. |
|
| 185 | - * |
|
| 186 | - * @param Request_RefreshParams_Exclude[] $excludes |
|
| 187 | - */ |
|
| 182 | + /** |
|
| 183 | + * Automatically excludes the HTML_QuickForm2 submit |
|
| 184 | + * tracking variable, when enabled. |
|
| 185 | + * |
|
| 186 | + * @param Request_RefreshParams_Exclude[] $excludes |
|
| 187 | + */ |
|
| 188 | 188 | private function autoExcludeQuickform(array &$excludes) : void |
| 189 | 189 | { |
| 190 | 190 | if($this->getBoolOption('exclude-quickform-submitter')) |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Retrieves the list of parameters matching the |
|
| 201 | - * current settings. |
|
| 202 | - * |
|
| 203 | - * @return array<string,mixed> |
|
| 204 | - */ |
|
| 199 | + /** |
|
| 200 | + * Retrieves the list of parameters matching the |
|
| 201 | + * current settings. |
|
| 202 | + * |
|
| 203 | + * @return array<string,mixed> |
|
| 204 | + */ |
|
| 205 | 205 | public function getParams() : array |
| 206 | 206 | { |
| 207 | 207 | $params = $this->removeExcluded($_REQUEST); |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | return $params; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Removes all excluded parameters from the array. |
|
| 222 | - * |
|
| 223 | - * @param array<string,mixed> $params |
|
| 224 | - * @return array<string,mixed> |
|
| 225 | - */ |
|
| 220 | + /** |
|
| 221 | + * Removes all excluded parameters from the array. |
|
| 222 | + * |
|
| 223 | + * @param array<string,mixed> $params |
|
| 224 | + * @return array<string,mixed> |
|
| 225 | + */ |
|
| 226 | 226 | private function removeExcluded(array $params) : array |
| 227 | 227 | { |
| 228 | 228 | $result = array(); |
@@ -240,14 +240,14 @@ discard block |
||
| 240 | 240 | return $result; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Checks all configured exclusions to see if the |
|
| 245 | - * parameter should be excluded or not. |
|
| 246 | - * |
|
| 247 | - * @param string $paramName |
|
| 248 | - * @param mixed $paramValue |
|
| 249 | - * @return bool |
|
| 250 | - */ |
|
| 243 | + /** |
|
| 244 | + * Checks all configured exclusions to see if the |
|
| 245 | + * parameter should be excluded or not. |
|
| 246 | + * |
|
| 247 | + * @param string $paramName |
|
| 248 | + * @param mixed $paramValue |
|
| 249 | + * @return bool |
|
| 250 | + */ |
|
| 251 | 251 | public function isExcluded(string $paramName, $paramValue) : bool |
| 252 | 252 | { |
| 253 | 253 | $excludes = $this->resolveExcludes(); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param bool $exclude |
| 49 | 49 | * @return Request_RefreshParams |
| 50 | 50 | */ |
| 51 | - public function setExcludeSessionName(bool $exclude=true) : Request_RefreshParams |
|
| 51 | + public function setExcludeSessionName(bool $exclude = true) : Request_RefreshParams |
|
| 52 | 52 | { |
| 53 | 53 | $this->setOption('exclude-session-name', $exclude); |
| 54 | 54 | return $this; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | public function excludeParamByName(string $paramName) : Request_RefreshParams |
| 72 | 72 | { |
| 73 | - if($paramName !== '') |
|
| 73 | + if ($paramName !== '') |
|
| 74 | 74 | { |
| 75 | 75 | $this->excludes[] = new Request_RefreshParams_Exclude_Name($paramName); |
| 76 | 76 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function excludeParamsByName(array $paramNames) : Request_RefreshParams |
| 109 | 109 | { |
| 110 | - foreach($paramNames as $name) |
|
| 110 | + foreach ($paramNames as $name) |
|
| 111 | 111 | { |
| 112 | 112 | $this->excludeParamByName((string)$name); |
| 113 | 113 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function overrideParams(array $params) : Request_RefreshParams |
| 141 | 141 | { |
| 142 | - foreach($params as $name => $value) |
|
| 142 | + foreach ($params as $name => $value) |
|
| 143 | 143 | { |
| 144 | 144 | $this->overrideParam((string)$name, $value); |
| 145 | 145 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | private function autoExcludeSessionName(array &$excludes) : void |
| 175 | 175 | { |
| 176 | - if($this->getBoolOption('exclude-session-name')) |
|
| 176 | + if ($this->getBoolOption('exclude-session-name')) |
|
| 177 | 177 | { |
| 178 | 178 | $excludes[] = new Request_RefreshParams_Exclude_Name(session_name()); |
| 179 | 179 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | private function autoExcludeQuickform(array &$excludes) : void |
| 189 | 189 | { |
| 190 | - if($this->getBoolOption('exclude-quickform-submitter')) |
|
| 190 | + if ($this->getBoolOption('exclude-quickform-submitter')) |
|
| 191 | 191 | { |
| 192 | 192 | $excludes[] = new Request_RefreshParams_Exclude_Callback(function(string $paramName) |
| 193 | 193 | { |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | // Note: using this loop instead of array_merge, |
| 210 | 210 | // because array_merge has weird behavior when |
| 211 | 211 | // using numeric keys. |
| 212 | - foreach($this->overrides as $name => $val) |
|
| 212 | + foreach ($this->overrides as $name => $val) |
|
| 213 | 213 | { |
| 214 | 214 | $params[$name] = $val; |
| 215 | 215 | } |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | { |
| 228 | 228 | $result = array(); |
| 229 | 229 | |
| 230 | - foreach($params as $name => $value) |
|
| 230 | + foreach ($params as $name => $value) |
|
| 231 | 231 | { |
| 232 | 232 | $name = (string)$name; |
| 233 | 233 | |
| 234 | - if(!$this->isExcluded($name, $value)) |
|
| 234 | + if (!$this->isExcluded($name, $value)) |
|
| 235 | 235 | { |
| 236 | 236 | $result[$name] = $value; |
| 237 | 237 | } |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | { |
| 253 | 253 | $excludes = $this->resolveExcludes(); |
| 254 | 254 | |
| 255 | - foreach($excludes as $exclude) |
|
| 255 | + foreach ($excludes as $exclude) |
|
| 256 | 256 | { |
| 257 | - if($exclude->isExcluded($paramName, $paramValue)) |
|
| 257 | + if ($exclude->isExcluded($paramName, $paramValue)) |
|
| 258 | 258 | { |
| 259 | 259 | return true; |
| 260 | 260 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | $output = curl_exec($ch); |
| 243 | 243 | |
| 244 | - if(isset($this->logfilePointer)) |
|
| 244 | + if (isset($this->logfilePointer)) |
|
| 245 | 245 | { |
| 246 | 246 | fclose($this->logfilePointer); |
| 247 | 247 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | // CURL will complain about an empty response when the |
| 254 | 254 | // server sends a 100-continue code. That should not be |
| 255 | 255 | // regarded as an error. |
| 256 | - if($output === false && $this->response->getCode() !== 100) |
|
| 256 | + if ($output === false && $this->response->getCode() !== 100) |
|
| 257 | 257 | { |
| 258 | 258 | $curlCode = curl_errno($ch); |
| 259 | 259 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | { |
| 290 | 290 | $ch = curl_init(); |
| 291 | 291 | |
| 292 | - if(!is_resource($ch)) |
|
| 292 | + if (!is_resource($ch)) |
|
| 293 | 293 | { |
| 294 | 294 | throw new RequestHelper_Exception( |
| 295 | 295 | 'Could not initialize a new cURL instance.', |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | $this->setHeader('Content-Length', (string)$this->boundaries->getContentLength()); |
| 302 | - $this->setHeader('Content-Type', 'multipart/form-data; boundary=' . $this->mimeBoundary); |
|
| 302 | + $this->setHeader('Content-Type', 'multipart/form-data; boundary='.$this->mimeBoundary); |
|
| 303 | 303 | |
| 304 | 304 | curl_setopt($ch, CURLOPT_POST, true); |
| 305 | 305 | curl_setopt($ch, CURLOPT_URL, $url->getNormalizedWithoutAuth()); |
@@ -312,18 +312,18 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | $loggingEnabled = $this->configureLogging($ch); |
| 314 | 314 | |
| 315 | - if(!$loggingEnabled) |
|
| 315 | + if (!$loggingEnabled) |
|
| 316 | 316 | { |
| 317 | 317 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if($this->verifySSL) |
|
| 320 | + if ($this->verifySSL) |
|
| 321 | 321 | { |
| 322 | 322 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
| 323 | 323 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if($url->hasUsername()) |
|
| 326 | + if ($url->hasUsername()) |
|
| 327 | 327 | { |
| 328 | 328 | curl_setopt($ch, CURLOPT_USERNAME, $url->getUsername()); |
| 329 | 329 | curl_setopt($ch, CURLOPT_PASSWORD, $url->getPassword()); |
@@ -338,14 +338,14 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | protected function configureLogging($ch) : bool |
| 340 | 340 | { |
| 341 | - if(empty($this->logfile)) |
|
| 341 | + if (empty($this->logfile)) |
|
| 342 | 342 | { |
| 343 | 343 | return false; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | $res = fopen($this->logfile, 'w+'); |
| 347 | 347 | |
| 348 | - if($res === false) |
|
| 348 | + if ($res === false) |
|
| 349 | 349 | { |
| 350 | 350 | throw new RequestHelper_Exception( |
| 351 | 351 | 'Cannot open logfile for writing.', |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | $this->setHeader('Expect', ''); |
| 377 | 377 | |
| 378 | - foreach($this->headers as $name => $value) { |
|
| 378 | + foreach ($this->headers as $name => $value) { |
|
| 379 | 379 | $result[] = $name.': '.$value; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | { |
| 393 | 393 | $response = $this->getResponse(); |
| 394 | 394 | |
| 395 | - if($response !== null) { |
|
| 395 | + if ($response !== null) { |
|
| 396 | 396 | return $response->getHeaders(); |
| 397 | 397 | } |
| 398 | 398 | |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | */ |
| 429 | 429 | public function getHeader(string $name) : string |
| 430 | 430 | { |
| 431 | - if(isset($this->headers[$name])) |
|
| 431 | + if (isset($this->headers[$name])) |
|
| 432 | 432 | { |
| 433 | 433 | return $this->headers[$name]; |
| 434 | 434 | } |
@@ -261,8 +261,7 @@ |
||
| 261 | 261 | $curlCode, |
| 262 | 262 | curl_error($ch).' | Explanation: '.curl_strerror($curlCode) |
| 263 | 263 | ); |
| 264 | - } |
|
| 265 | - else |
|
| 264 | + } else |
|
| 266 | 265 | { |
| 267 | 266 | $this->response->setBody((string)$output); |
| 268 | 267 | } |
@@ -32,62 +32,62 @@ discard block |
||
| 32 | 32 | public const ERROR_CURL_INIT_FAILED = 17903; |
| 33 | 33 | public const ERROR_CANNOT_OPEN_LOGFILE = 17904; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | 38 | protected $eol = "\r\n"; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | 43 | protected $mimeBoundary; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | 48 | protected $destination; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var array<string,string> |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var array<string,string> |
|
| 52 | + */ |
|
| 53 | 53 | protected $headers = array(); |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Whether to verify SSL certificates. |
|
| 57 | - * @var bool |
|
| 58 | - */ |
|
| 55 | + /** |
|
| 56 | + * Whether to verify SSL certificates. |
|
| 57 | + * @var bool |
|
| 58 | + */ |
|
| 59 | 59 | protected $verifySSL = true; |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var RequestHelper_Boundaries |
|
| 63 | - */ |
|
| 61 | + /** |
|
| 62 | + * @var RequestHelper_Boundaries |
|
| 63 | + */ |
|
| 64 | 64 | protected $boundaries; |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @var RequestHelper_Response|NULL |
|
| 68 | - */ |
|
| 66 | + /** |
|
| 67 | + * @var RequestHelper_Response|NULL |
|
| 68 | + */ |
|
| 69 | 69 | protected $response; |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Timeout duration, in seconds. |
|
| 73 | - * @var integer |
|
| 74 | - */ |
|
| 71 | + /** |
|
| 72 | + * Timeout duration, in seconds. |
|
| 73 | + * @var integer |
|
| 74 | + */ |
|
| 75 | 75 | protected $timeout = 30; |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @var string |
|
| 79 | - */ |
|
| 77 | + /** |
|
| 78 | + * @var string |
|
| 79 | + */ |
|
| 80 | 80 | protected $logfile = ''; |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @var resource|NULL |
|
| 84 | - */ |
|
| 82 | + /** |
|
| 83 | + * @var resource|NULL |
|
| 84 | + */ |
|
| 85 | 85 | protected $logfilePointer = null; |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Creates a new request helper to send POST data to the specified destination URL. |
|
| 89 | - * @param string $destinationURL |
|
| 90 | - */ |
|
| 87 | + /** |
|
| 88 | + * Creates a new request helper to send POST data to the specified destination URL. |
|
| 89 | + * @param string $destinationURL |
|
| 90 | + */ |
|
| 91 | 91 | public function __construct(string $destinationURL) |
| 92 | 92 | { |
| 93 | 93 | $this->destination = $destinationURL; |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | return $this->eol; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Sets the timeout for the request, in seconds. If the request |
|
| 115 | - * takes longer, it will be cancelled and an exception triggered. |
|
| 116 | - * |
|
| 117 | - * @param int $seconds |
|
| 118 | - * @return RequestHelper |
|
| 119 | - */ |
|
| 113 | + /** |
|
| 114 | + * Sets the timeout for the request, in seconds. If the request |
|
| 115 | + * takes longer, it will be cancelled and an exception triggered. |
|
| 116 | + * |
|
| 117 | + * @param int $seconds |
|
| 118 | + * @return RequestHelper |
|
| 119 | + */ |
|
| 120 | 120 | public function setTimeout(int $seconds) : RequestHelper |
| 121 | 121 | { |
| 122 | 122 | $this->timeout = $seconds; |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | return $this->timeout; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Enables verbose logging of the CURL request, which |
|
| 134 | - * is then redirected to the target file. |
|
| 135 | - * |
|
| 136 | - * @param string $targetFile |
|
| 137 | - * @return RequestHelper |
|
| 138 | - */ |
|
| 132 | + /** |
|
| 133 | + * Enables verbose logging of the CURL request, which |
|
| 134 | + * is then redirected to the target file. |
|
| 135 | + * |
|
| 136 | + * @param string $targetFile |
|
| 137 | + * @return RequestHelper |
|
| 138 | + */ |
|
| 139 | 139 | public function enableLogging(string $targetFile) : RequestHelper |
| 140 | 140 | { |
| 141 | 141 | $this->logfile = $targetFile; |
@@ -143,15 +143,15 @@ discard block |
||
| 143 | 143 | return $this; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Adds a file to be sent with the request. |
|
| 148 | - * |
|
| 149 | - * @param string $varName The variable name to send the file in |
|
| 150 | - * @param string $fileName The name of the file as it should be received at the destination |
|
| 151 | - * @param string $content The raw content of the file |
|
| 152 | - * @param string $contentType The content type, use the constants to specify this |
|
| 153 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 154 | - */ |
|
| 146 | + /** |
|
| 147 | + * Adds a file to be sent with the request. |
|
| 148 | + * |
|
| 149 | + * @param string $varName The variable name to send the file in |
|
| 150 | + * @param string $fileName The name of the file as it should be received at the destination |
|
| 151 | + * @param string $content The raw content of the file |
|
| 152 | + * @param string $contentType The content type, use the constants to specify this |
|
| 153 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 154 | + */ |
|
| 155 | 155 | public function addFile(string $varName, string $fileName, string $content, string $contentType = '', string $encoding = '') : RequestHelper |
| 156 | 156 | { |
| 157 | 157 | $this->boundaries->addFile($varName, $fileName, $content, $contentType, $encoding); |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | return $this; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Adds arbitrary content. |
|
| 164 | - * |
|
| 165 | - * @param string $varName The variable name to send the content in. |
|
| 166 | - * @param string $content |
|
| 167 | - * @param string $contentType |
|
| 168 | - */ |
|
| 162 | + /** |
|
| 163 | + * Adds arbitrary content. |
|
| 164 | + * |
|
| 165 | + * @param string $varName The variable name to send the content in. |
|
| 166 | + * @param string $content |
|
| 167 | + * @param string $contentType |
|
| 168 | + */ |
|
| 169 | 169 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper |
| 170 | 170 | { |
| 171 | 171 | $this->boundaries->addContent($varName, $content, $contentType); |
@@ -173,13 +173,13 @@ discard block |
||
| 173 | 173 | return $this; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Adds a variable to be sent with the request. If it |
|
| 178 | - * already exists, its value is overwritten. |
|
| 179 | - * |
|
| 180 | - * @param string $name |
|
| 181 | - * @param string $value |
|
| 182 | - */ |
|
| 176 | + /** |
|
| 177 | + * Adds a variable to be sent with the request. If it |
|
| 178 | + * already exists, its value is overwritten. |
|
| 179 | + * |
|
| 180 | + * @param string $name |
|
| 181 | + * @param string $value |
|
| 182 | + */ |
|
| 183 | 183 | public function addVariable(string $name, string $value) : RequestHelper |
| 184 | 184 | { |
| 185 | 185 | $this->boundaries->addVariable($name, $value); |
@@ -187,13 +187,13 @@ discard block |
||
| 187 | 187 | return $this; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * Sets an HTTP header to include in the request. |
|
| 192 | - * |
|
| 193 | - * @param string $name |
|
| 194 | - * @param string $value |
|
| 195 | - * @return RequestHelper |
|
| 196 | - */ |
|
| 190 | + /** |
|
| 191 | + * Sets an HTTP header to include in the request. |
|
| 192 | + * |
|
| 193 | + * @param string $name |
|
| 194 | + * @param string $value |
|
| 195 | + * @return RequestHelper |
|
| 196 | + */ |
|
| 197 | 197 | public function setHeader(string $name, string $value) : RequestHelper |
| 198 | 198 | { |
| 199 | 199 | $this->headers[$name] = $value; |
@@ -201,36 +201,36 @@ discard block |
||
| 201 | 201 | return $this; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Disables SSL certificate checking. |
|
| 206 | - * |
|
| 207 | - * @return RequestHelper |
|
| 208 | - */ |
|
| 204 | + /** |
|
| 205 | + * Disables SSL certificate checking. |
|
| 206 | + * |
|
| 207 | + * @return RequestHelper |
|
| 208 | + */ |
|
| 209 | 209 | public function disableSSLChecks() : RequestHelper |
| 210 | 210 | { |
| 211 | 211 | $this->verifySSL = false; |
| 212 | 212 | return $this; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * @var integer |
|
| 217 | - */ |
|
| 215 | + /** |
|
| 216 | + * @var integer |
|
| 217 | + */ |
|
| 218 | 218 | protected $contentLength = 0; |
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Sends the POST request to the destination, and returns |
|
| 222 | - * the response text. |
|
| 223 | - * |
|
| 224 | - * The response object is stored internally, so after calling |
|
| 225 | - * this method it may be retrieved at any moment using the |
|
| 226 | - * {@link getResponse()} method. |
|
| 227 | - * |
|
| 228 | - * @return string |
|
| 229 | - * @see RequestHelper::getResponse() |
|
| 230 | - * @throws RequestHelper_Exception |
|
| 231 | - * |
|
| 232 | - * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 233 | - */ |
|
| 220 | + /** |
|
| 221 | + * Sends the POST request to the destination, and returns |
|
| 222 | + * the response text. |
|
| 223 | + * |
|
| 224 | + * The response object is stored internally, so after calling |
|
| 225 | + * this method it may be retrieved at any moment using the |
|
| 226 | + * {@link getResponse()} method. |
|
| 227 | + * |
|
| 228 | + * @return string |
|
| 229 | + * @see RequestHelper::getResponse() |
|
| 230 | + * @throws RequestHelper_Exception |
|
| 231 | + * |
|
| 232 | + * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 233 | + */ |
|
| 234 | 234 | public function send() : string |
| 235 | 235 | { |
| 236 | 236 | $info = parseURL($this->destination); |
@@ -270,26 +270,26 @@ discard block |
||
| 270 | 270 | return $this->response->getResponseBody(); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * Retrieves the request's body content. This is an alias |
|
| 275 | - * for {@see RequestHelper::getMimeBody()}. |
|
| 276 | - * |
|
| 277 | - * @return string |
|
| 278 | - * @see RequestHelper::getMimeBody() |
|
| 279 | - */ |
|
| 273 | + /** |
|
| 274 | + * Retrieves the request's body content. This is an alias |
|
| 275 | + * for {@see RequestHelper::getMimeBody()}. |
|
| 276 | + * |
|
| 277 | + * @return string |
|
| 278 | + * @see RequestHelper::getMimeBody() |
|
| 279 | + */ |
|
| 280 | 280 | public function getBody() : string |
| 281 | 281 | { |
| 282 | 282 | return $this->getMimeBody(); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * Creates a new CURL resource configured according to the |
|
| 287 | - * request's settings. |
|
| 288 | - * |
|
| 289 | - * @param URLInfo $url |
|
| 290 | - * @throws RequestHelper_Exception |
|
| 291 | - * @return resource |
|
| 292 | - */ |
|
| 285 | + /** |
|
| 286 | + * Creates a new CURL resource configured according to the |
|
| 287 | + * request's settings. |
|
| 288 | + * |
|
| 289 | + * @param URLInfo $url |
|
| 290 | + * @throws RequestHelper_Exception |
|
| 291 | + * @return resource |
|
| 292 | + */ |
|
| 293 | 293 | protected function createCURL(URLInfo $url) |
| 294 | 294 | { |
| 295 | 295 | $ch = curl_init(); |
@@ -337,10 +337,10 @@ discard block |
||
| 337 | 337 | return $ch; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * @param resource $ch |
|
| 342 | - * @return bool Whether logging is enabled. |
|
| 343 | - */ |
|
| 340 | + /** |
|
| 341 | + * @param resource $ch |
|
| 342 | + * @return bool Whether logging is enabled. |
|
| 343 | + */ |
|
| 344 | 344 | protected function configureLogging($ch) : bool |
| 345 | 345 | { |
| 346 | 346 | if(empty($this->logfile)) |
@@ -367,13 +367,13 @@ discard block |
||
| 367 | 367 | return true; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - /** |
|
| 371 | - * Compiles the associative headers array into |
|
| 372 | - * the format understood by CURL, namely an indexed |
|
| 373 | - * array with one header string per entry. |
|
| 374 | - * |
|
| 375 | - * @return array |
|
| 376 | - */ |
|
| 370 | + /** |
|
| 371 | + * Compiles the associative headers array into |
|
| 372 | + * the format understood by CURL, namely an indexed |
|
| 373 | + * array with one header string per entry. |
|
| 374 | + * |
|
| 375 | + * @return array |
|
| 376 | + */ |
|
| 377 | 377 | protected function renderHeaders() : array |
| 378 | 378 | { |
| 379 | 379 | $result = array(); |
@@ -387,12 +387,12 @@ discard block |
||
| 387 | 387 | return $result; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - /** |
|
| 391 | - * Retrieves the raw response header, in the form of an indexed |
|
| 392 | - * array containing all response header lines. |
|
| 393 | - * |
|
| 394 | - * @return array |
|
| 395 | - */ |
|
| 390 | + /** |
|
| 391 | + * Retrieves the raw response header, in the form of an indexed |
|
| 392 | + * array containing all response header lines. |
|
| 393 | + * |
|
| 394 | + * @return array |
|
| 395 | + */ |
|
| 396 | 396 | public function getResponseHeader() : array |
| 397 | 397 | { |
| 398 | 398 | $response = $this->getResponse(); |
@@ -404,33 +404,33 @@ discard block |
||
| 404 | 404 | return array(); |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - /** |
|
| 408 | - * After calling the {@link send()} method, this may be used to |
|
| 409 | - * retrieve the response text from the POST request. |
|
| 410 | - * |
|
| 411 | - * @return RequestHelper_Response|NULL |
|
| 412 | - */ |
|
| 407 | + /** |
|
| 408 | + * After calling the {@link send()} method, this may be used to |
|
| 409 | + * retrieve the response text from the POST request. |
|
| 410 | + * |
|
| 411 | + * @return RequestHelper_Response|NULL |
|
| 412 | + */ |
|
| 413 | 413 | public function getResponse() : ?RequestHelper_Response |
| 414 | 414 | { |
| 415 | 415 | return $this->response; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - /** |
|
| 419 | - * Retrieves all headers set until now. |
|
| 420 | - * |
|
| 421 | - * @return array<string,string> |
|
| 422 | - */ |
|
| 418 | + /** |
|
| 419 | + * Retrieves all headers set until now. |
|
| 420 | + * |
|
| 421 | + * @return array<string,string> |
|
| 422 | + */ |
|
| 423 | 423 | public function getHeaders() : array |
| 424 | 424 | { |
| 425 | 425 | return $this->headers; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - /** |
|
| 429 | - * Retrieves the value of a header by its name. |
|
| 430 | - * |
|
| 431 | - * @param string $name |
|
| 432 | - * @return string The header value, or an empty string if not set. |
|
| 433 | - */ |
|
| 428 | + /** |
|
| 429 | + * Retrieves the value of a header by its name. |
|
| 430 | + * |
|
| 431 | + * @param string $name |
|
| 432 | + * @return string The header value, or an empty string if not set. |
|
| 433 | + */ |
|
| 434 | 434 | public function getHeader(string $name) : string |
| 435 | 435 | { |
| 436 | 436 | if(isset($this->headers[$name])) |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | if (!empty($text)) { |
| 245 | 245 | $fragment = $this->dom->createDocumentFragment(); |
| 246 | - if(!@$fragment->appendXML($text)) { |
|
| 246 | + if (!@$fragment->appendXML($text)) { |
|
| 247 | 247 | throw new XMLHelper_Exception( |
| 248 | 248 | 'Cannot append XML fragment', |
| 249 | 249 | sprintf( |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * @param array<string,mixed> $attributes |
| 286 | 286 | * @return DOMNode |
| 287 | 287 | */ |
| 288 | - public function createRoot(string $name, array $attributes=array()) |
|
| 288 | + public function createRoot(string $name, array $attributes = array()) |
|
| 289 | 289 | { |
| 290 | 290 | $root = $this->dom->appendChild($this->dom->createElement($name)); |
| 291 | 291 | $this->addAttributes($root, $attributes); |
@@ -311,8 +311,8 @@ discard block |
||
| 311 | 311 | $string = str_replace('<', 'LT_ESCAPE', $string); |
| 312 | 312 | $string = str_replace('>', 'GT_ESCAPE', $string); |
| 313 | 313 | |
| 314 | - $string = str_replace(' ',' ', $string); |
|
| 315 | - $string = str_replace('&','&', $string); |
|
| 314 | + $string = str_replace(' ', ' ', $string); |
|
| 315 | + $string = str_replace('&', '&', $string); |
|
| 316 | 316 | |
| 317 | 317 | return $string; |
| 318 | 318 | } |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | public static function downloadXML(string $xml, string $filename = 'download.xml') : void |
| 333 | 333 | { |
| 334 | - if(!headers_sent() && !self::$simulation) |
|
| 334 | + if (!headers_sent() && !self::$simulation) |
|
| 335 | 335 | { |
| 336 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
| 336 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | echo $xml; |
@@ -347,12 +347,12 @@ discard block |
||
| 347 | 347 | */ |
| 348 | 348 | public static function displayXML(string $xml) : void |
| 349 | 349 | { |
| 350 | - if(!headers_sent() && !self::$simulation) |
|
| 350 | + if (!headers_sent() && !self::$simulation) |
|
| 351 | 351 | { |
| 352 | 352 | header('Content-Type:text/xml; charset=utf-8'); |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - if(self::$simulation) |
|
| 355 | + if (self::$simulation) |
|
| 356 | 356 | { |
| 357 | 357 | $xml = '<pre>'.htmlspecialchars($xml).'</pre>'; |
| 358 | 358 | } |
@@ -370,16 +370,16 @@ discard block |
||
| 370 | 370 | * @param array<string,string> $customInfo Associative array with name => value pairs for custom tags to add to the output xml |
| 371 | 371 | * @see buildErrorXML() |
| 372 | 372 | */ |
| 373 | - public static function displayErrorXML($code, string $message, string $title, array $customInfo=array()) |
|
| 373 | + public static function displayErrorXML($code, string $message, string $title, array $customInfo = array()) |
|
| 374 | 374 | { |
| 375 | - if(!headers_sent() && !self::$simulation) { |
|
| 376 | - header('HTTP/1.1 400 Bad Request: ' . $title, true, 400); |
|
| 375 | + if (!headers_sent() && !self::$simulation) { |
|
| 376 | + header('HTTP/1.1 400 Bad Request: '.$title, true, 400); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | self::displayXML(self::buildErrorXML($code, $message, $title, $customInfo)); |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - public static function setSimulation(bool $simulate=true) : void |
|
| 382 | + public static function setSimulation(bool $simulate = true) : void |
|
| 383 | 383 | { |
| 384 | 384 | self::$simulation = $simulate; |
| 385 | 385 | } |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * @param array<string,string> $customInfo |
| 429 | 429 | * @return string |
| 430 | 430 | */ |
| 431 | - public static function buildErrorXML($code, string $message, string $title, array $customInfo=array()) |
|
| 431 | + public static function buildErrorXML($code, string $message, string $title, array $customInfo = array()) |
|
| 432 | 432 | { |
| 433 | 433 | $xml = new DOMDocument('1.0', 'UTF-8'); |
| 434 | 434 | $xml->formatOutput = true; |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | $helper->addTextTag($root, 'title', $title); |
| 443 | 443 | $helper->addTextTag($root, 'request_uri', $_SERVER['REQUEST_URI']); |
| 444 | 444 | |
| 445 | - foreach($customInfo as $name => $value) { |
|
| 445 | + foreach ($customInfo as $name => $value) { |
|
| 446 | 446 | $helper->addTextTag($root, $name, $value); |
| 447 | 447 | } |
| 448 | 448 | |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | public const ERROR_CANNOT_APPEND_FRAGMENT = 491001; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var boolean |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var boolean |
|
| 33 | + */ |
|
| 34 | 34 | private static $simulation = false; |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | private $dom; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Creates a new XMLHelper instance. |
|
| 43 | - * |
|
| 44 | - * @return XMLHelper |
|
| 45 | - */ |
|
| 41 | + /** |
|
| 42 | + * Creates a new XMLHelper instance. |
|
| 43 | + * |
|
| 44 | + * @return XMLHelper |
|
| 45 | + */ |
|
| 46 | 46 | public static function create() : XMLHelper |
| 47 | 47 | { |
| 48 | 48 | $dom = new DOMDocument('1.0', 'UTF-8'); |
@@ -51,72 +51,72 @@ discard block |
||
| 51 | 51 | return new XMLHelper($dom); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Creates a converter instance from an XML file. |
|
| 56 | - * @param string $xmlFile |
|
| 57 | - * @return XMLHelper_Converter |
|
| 58 | - */ |
|
| 54 | + /** |
|
| 55 | + * Creates a converter instance from an XML file. |
|
| 56 | + * @param string $xmlFile |
|
| 57 | + * @return XMLHelper_Converter |
|
| 58 | + */ |
|
| 59 | 59 | public static function convertFile(string $xmlFile) : XMLHelper_Converter |
| 60 | 60 | { |
| 61 | 61 | return XMLHelper_Converter::fromFile($xmlFile); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Creates a converter from an XML string. |
|
| 66 | - * @param string $xmlString |
|
| 67 | - * @return XMLHelper_Converter |
|
| 68 | - */ |
|
| 64 | + /** |
|
| 65 | + * Creates a converter from an XML string. |
|
| 66 | + * @param string $xmlString |
|
| 67 | + * @return XMLHelper_Converter |
|
| 68 | + */ |
|
| 69 | 69 | public static function convertString(string $xmlString) : XMLHelper_Converter |
| 70 | 70 | { |
| 71 | 71 | return XMLHelper_Converter::fromString($xmlString); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Creates a converter from a SimpleXMLElement instance. |
|
| 76 | - * @param SimpleXMLElement $element |
|
| 77 | - * @return XMLHelper_Converter |
|
| 78 | - */ |
|
| 74 | + /** |
|
| 75 | + * Creates a converter from a SimpleXMLElement instance. |
|
| 76 | + * @param SimpleXMLElement $element |
|
| 77 | + * @return XMLHelper_Converter |
|
| 78 | + */ |
|
| 79 | 79 | public static function convertElement(SimpleXMLElement $element) : XMLHelper_Converter |
| 80 | 80 | { |
| 81 | 81 | return XMLHelper_Converter::fromElement($element); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Creates a converter from a DOMElement instance. |
|
| 86 | - * @param DOMElement $element |
|
| 87 | - * @return XMLHelper_Converter |
|
| 88 | - */ |
|
| 84 | + /** |
|
| 85 | + * Creates a converter from a DOMElement instance. |
|
| 86 | + * @param DOMElement $element |
|
| 87 | + * @return XMLHelper_Converter |
|
| 88 | + */ |
|
| 89 | 89 | public static function convertDOMElement(DOMElement $element) : XMLHelper_Converter |
| 90 | 90 | { |
| 91 | 91 | return XMLHelper_Converter::fromDOMElement($element); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Creates a new helper using an existing DOMDocument object. |
|
| 96 | - * @param DOMDocument $dom |
|
| 97 | - */ |
|
| 94 | + /** |
|
| 95 | + * Creates a new helper using an existing DOMDocument object. |
|
| 96 | + * @param DOMDocument $dom |
|
| 97 | + */ |
|
| 98 | 98 | public function __construct(DOMDocument $dom) |
| 99 | 99 | { |
| 100 | 100 | $this->dom = $dom; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @return DOMDocument |
|
| 105 | - */ |
|
| 103 | + /** |
|
| 104 | + * @return DOMDocument |
|
| 105 | + */ |
|
| 106 | 106 | public function getDOM() : DOMDocument |
| 107 | 107 | { |
| 108 | 108 | return $this->dom; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Adds an attribute to an existing tag with |
|
| 113 | - * the specified value. |
|
| 114 | - * |
|
| 115 | - * @param DOMNode $parent |
|
| 116 | - * @param string $name |
|
| 117 | - * @param mixed $value |
|
| 118 | - * @return DOMNode |
|
| 119 | - */ |
|
| 111 | + /** |
|
| 112 | + * Adds an attribute to an existing tag with |
|
| 113 | + * the specified value. |
|
| 114 | + * |
|
| 115 | + * @param DOMNode $parent |
|
| 116 | + * @param string $name |
|
| 117 | + * @param mixed $value |
|
| 118 | + * @return DOMNode |
|
| 119 | + */ |
|
| 120 | 120 | public function addAttribute(DOMNode $parent, string $name, $value) |
| 121 | 121 | { |
| 122 | 122 | $node = $this->dom->createAttribute($name); |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | return $parent->appendChild($node); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Adds several attributes to the target node. |
|
| 131 | - * |
|
| 132 | - * @param DOMNode $parent |
|
| 133 | - * @param array<string,mixed> $attributes |
|
| 134 | - */ |
|
| 129 | + /** |
|
| 130 | + * Adds several attributes to the target node. |
|
| 131 | + * |
|
| 132 | + * @param DOMNode $parent |
|
| 133 | + * @param array<string,mixed> $attributes |
|
| 134 | + */ |
|
| 135 | 135 | public function addAttributes(DOMNode $parent, array $attributes) : void |
| 136 | 136 | { |
| 137 | 137 | foreach ($attributes as $name => $value) { |
@@ -139,14 +139,14 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Adds a tag without content. |
|
| 144 | - * |
|
| 145 | - * @param DOMNode $parent |
|
| 146 | - * @param string $name |
|
| 147 | - * @param integer $indent |
|
| 148 | - * @return DOMNode |
|
| 149 | - */ |
|
| 142 | + /** |
|
| 143 | + * Adds a tag without content. |
|
| 144 | + * |
|
| 145 | + * @param DOMNode $parent |
|
| 146 | + * @param string $name |
|
| 147 | + * @param integer $indent |
|
| 148 | + * @return DOMNode |
|
| 149 | + */ |
|
| 150 | 150 | public function addTag(DOMNode $parent, string $name, int $indent = 0) : DOMNode |
| 151 | 151 | { |
| 152 | 152 | if ($indent > 0) { |
@@ -168,17 +168,17 @@ discard block |
||
| 168 | 168 | $parent->appendChild($this->dom->createTextNode(str_repeat("\t", $amount))); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Adds a tag with textual content, like: |
|
| 173 | - * |
|
| 174 | - * <tagname>text</tagname> |
|
| 175 | - * |
|
| 176 | - * @param DOMNode $parent |
|
| 177 | - * @param string $name |
|
| 178 | - * @param string $text |
|
| 179 | - * @param integer $indent |
|
| 180 | - * @return DOMNode |
|
| 181 | - */ |
|
| 171 | + /** |
|
| 172 | + * Adds a tag with textual content, like: |
|
| 173 | + * |
|
| 174 | + * <tagname>text</tagname> |
|
| 175 | + * |
|
| 176 | + * @param DOMNode $parent |
|
| 177 | + * @param string $name |
|
| 178 | + * @param string $text |
|
| 179 | + * @param integer $indent |
|
| 180 | + * @return DOMNode |
|
| 181 | + */ |
|
| 182 | 182 | public function addTextTag(DOMNode $parent, string $name, string $text, int $indent = 0) : DOMNode |
| 183 | 183 | { |
| 184 | 184 | if ($indent > 0) { |
@@ -192,19 +192,19 @@ discard block |
||
| 192 | 192 | return $parent->appendChild($tag); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Adds a tag with textual content, like: |
|
| 197 | - * |
|
| 198 | - * <tagname>text</tagname> |
|
| 199 | - * |
|
| 200 | - * and removes <p> tags |
|
| 201 | - * |
|
| 202 | - * @param DOMNode $parent |
|
| 203 | - * @param string $name |
|
| 204 | - * @param string $text |
|
| 205 | - * @param integer $indent |
|
| 206 | - * @return DOMNode |
|
| 207 | - */ |
|
| 195 | + /** |
|
| 196 | + * Adds a tag with textual content, like: |
|
| 197 | + * |
|
| 198 | + * <tagname>text</tagname> |
|
| 199 | + * |
|
| 200 | + * and removes <p> tags |
|
| 201 | + * |
|
| 202 | + * @param DOMNode $parent |
|
| 203 | + * @param string $name |
|
| 204 | + * @param string $text |
|
| 205 | + * @param integer $indent |
|
| 206 | + * @return DOMNode |
|
| 207 | + */ |
|
| 208 | 208 | public function addEscapedTag(DOMNode $parent, string $name, string $text, int $indent = 0) |
| 209 | 209 | { |
| 210 | 210 | if ($indent > 0) { |
@@ -220,19 +220,19 @@ discard block |
||
| 220 | 220 | return $parent->appendChild($tag); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * Adds a tag with HTML content, like: |
|
| 225 | - * |
|
| 226 | - * <tagname><i>text</i></tagname> |
|
| 227 | - * |
|
| 228 | - * Tags will not be escaped. |
|
| 229 | - * |
|
| 230 | - * @param DOMNode $parent |
|
| 231 | - * @param string $name |
|
| 232 | - * @param string $text |
|
| 233 | - * @param integer $indent |
|
| 234 | - * @return DOMNode |
|
| 235 | - */ |
|
| 223 | + /** |
|
| 224 | + * Adds a tag with HTML content, like: |
|
| 225 | + * |
|
| 226 | + * <tagname><i>text</i></tagname> |
|
| 227 | + * |
|
| 228 | + * Tags will not be escaped. |
|
| 229 | + * |
|
| 230 | + * @param DOMNode $parent |
|
| 231 | + * @param string $name |
|
| 232 | + * @param string $text |
|
| 233 | + * @param integer $indent |
|
| 234 | + * @return DOMNode |
|
| 235 | + */ |
|
| 236 | 236 | public function addFragmentTag(DOMNode $parent, string $name, string $text, int $indent = 0) |
| 237 | 237 | { |
| 238 | 238 | if ($indent > 0) { |
@@ -260,16 +260,16 @@ discard block |
||
| 260 | 260 | return $parent->appendChild($tag); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Adds a tag with CDATA content, like: |
|
| 265 | - * |
|
| 266 | - * <tagname><![CDATA[value]]></tagname> |
|
| 267 | - * |
|
| 268 | - * @param DOMNode $parent |
|
| 269 | - * @param string $name |
|
| 270 | - * @param string $content |
|
| 271 | - * @return DOMNode |
|
| 272 | - */ |
|
| 263 | + /** |
|
| 264 | + * Adds a tag with CDATA content, like: |
|
| 265 | + * |
|
| 266 | + * <tagname><![CDATA[value]]></tagname> |
|
| 267 | + * |
|
| 268 | + * @param DOMNode $parent |
|
| 269 | + * @param string $name |
|
| 270 | + * @param string $content |
|
| 271 | + * @return DOMNode |
|
| 272 | + */ |
|
| 273 | 273 | public function addCDATATag(DOMNode $parent, string $name, string $content) : DOMNode |
| 274 | 274 | { |
| 275 | 275 | $tag = $this->dom->createElement($name); |
@@ -279,12 +279,12 @@ discard block |
||
| 279 | 279 | return $parent->appendChild($tag); |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Creates the root element of the document. |
|
| 284 | - * @param string $name |
|
| 285 | - * @param array<string,mixed> $attributes |
|
| 286 | - * @return DOMNode |
|
| 287 | - */ |
|
| 282 | + /** |
|
| 283 | + * Creates the root element of the document. |
|
| 284 | + * @param string $name |
|
| 285 | + * @param array<string,mixed> $attributes |
|
| 286 | + * @return DOMNode |
|
| 287 | + */ |
|
| 288 | 288 | public function createRoot(string $name, array $attributes=array()) |
| 289 | 289 | { |
| 290 | 290 | $root = $this->dom->appendChild($this->dom->createElement($name)); |
@@ -292,12 +292,12 @@ discard block |
||
| 292 | 292 | return $root; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * Escaped the string for use in XML. |
|
| 297 | - * |
|
| 298 | - * @param string $string |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 295 | + /** |
|
| 296 | + * Escaped the string for use in XML. |
|
| 297 | + * |
|
| 298 | + * @param string $string |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | 301 | public function escape(string $string) : string |
| 302 | 302 | { |
| 303 | 303 | $string = preg_replace('#<p>(.*)</p>#isUm', '$1', $string); |
@@ -317,18 +317,18 @@ discard block |
||
| 317 | 317 | return $string; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * Sends the specified XML string to the browser with |
|
| 322 | - * the correct headers to trigger a download of the XML |
|
| 323 | - * to a local file. |
|
| 324 | - * |
|
| 325 | - * NOTE: Ensure calling exit after this is done, and to |
|
| 326 | - * not send additional content, which would corrupt the |
|
| 327 | - * download. |
|
| 328 | - * |
|
| 329 | - * @param string $xml |
|
| 330 | - * @param string $filename |
|
| 331 | - */ |
|
| 320 | + /** |
|
| 321 | + * Sends the specified XML string to the browser with |
|
| 322 | + * the correct headers to trigger a download of the XML |
|
| 323 | + * to a local file. |
|
| 324 | + * |
|
| 325 | + * NOTE: Ensure calling exit after this is done, and to |
|
| 326 | + * not send additional content, which would corrupt the |
|
| 327 | + * download. |
|
| 328 | + * |
|
| 329 | + * @param string $xml |
|
| 330 | + * @param string $filename |
|
| 331 | + */ |
|
| 332 | 332 | public static function downloadXML(string $xml, string $filename = 'download.xml') : void |
| 333 | 333 | { |
| 334 | 334 | if(!headers_sent() && !self::$simulation) |
@@ -339,12 +339,12 @@ discard block |
||
| 339 | 339 | echo $xml; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * Sends the specified XML string to the browser with |
|
| 344 | - * the correct headers and terminates the request. |
|
| 345 | - * |
|
| 346 | - * @param string $xml |
|
| 347 | - */ |
|
| 342 | + /** |
|
| 343 | + * Sends the specified XML string to the browser with |
|
| 344 | + * the correct headers and terminates the request. |
|
| 345 | + * |
|
| 346 | + * @param string $xml |
|
| 347 | + */ |
|
| 348 | 348 | public static function displayXML(string $xml) : void |
| 349 | 349 | { |
| 350 | 350 | if(!headers_sent() && !self::$simulation) |
@@ -411,23 +411,23 @@ discard block |
||
| 411 | 411 | return $xml->saveXML(); |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * Creates XML markup to describe an application error |
|
| 416 | - * when using XML services. Creates XML with the |
|
| 417 | - * following structure: |
|
| 418 | - * |
|
| 419 | - * <error> |
|
| 420 | - * <id>99</id> |
|
| 421 | - * <message>Full error message text</message> |
|
| 422 | - * <title>Short error label</title> |
|
| 423 | - * </error> |
|
| 424 | - * |
|
| 425 | - * @param string|number $code |
|
| 426 | - * @param string $message |
|
| 427 | - * @param string $title |
|
| 428 | - * @param array<string,string> $customInfo |
|
| 429 | - * @return string |
|
| 430 | - */ |
|
| 414 | + /** |
|
| 415 | + * Creates XML markup to describe an application error |
|
| 416 | + * when using XML services. Creates XML with the |
|
| 417 | + * following structure: |
|
| 418 | + * |
|
| 419 | + * <error> |
|
| 420 | + * <id>99</id> |
|
| 421 | + * <message>Full error message text</message> |
|
| 422 | + * <title>Short error label</title> |
|
| 423 | + * </error> |
|
| 424 | + * |
|
| 425 | + * @param string|number $code |
|
| 426 | + * @param string $message |
|
| 427 | + * @param string $title |
|
| 428 | + * @param array<string,string> $customInfo |
|
| 429 | + * @return string |
|
| 430 | + */ |
|
| 431 | 431 | public static function buildErrorXML($code, string $message, string $title, array $customInfo=array()) |
| 432 | 432 | { |
| 433 | 433 | $xml = new DOMDocument('1.0', 'UTF-8'); |
@@ -460,31 +460,31 @@ discard block |
||
| 460 | 460 | return $this->dom->saveXML(); |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - /** |
|
| 464 | - * Creates a new SimpleXML helper instance: this |
|
| 465 | - * object is useful to work with loading XML strings |
|
| 466 | - * and files with easy access to any errors that |
|
| 467 | - * may occurr, since the simplexml functions can be |
|
| 468 | - * somewhat cryptic. |
|
| 469 | - * |
|
| 470 | - * @return XMLHelper_SimpleXML |
|
| 471 | - */ |
|
| 463 | + /** |
|
| 464 | + * Creates a new SimpleXML helper instance: this |
|
| 465 | + * object is useful to work with loading XML strings |
|
| 466 | + * and files with easy access to any errors that |
|
| 467 | + * may occurr, since the simplexml functions can be |
|
| 468 | + * somewhat cryptic. |
|
| 469 | + * |
|
| 470 | + * @return XMLHelper_SimpleXML |
|
| 471 | + */ |
|
| 472 | 472 | public static function createSimplexml() : XMLHelper_SimpleXML |
| 473 | 473 | { |
| 474 | 474 | return new XMLHelper_SimpleXML(); |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - /** |
|
| 478 | - * Converts a string to valid XML: can be a text only string |
|
| 479 | - * or an HTML string. Returns valid XML code. |
|
| 480 | - * |
|
| 481 | - * NOTE: The string may contain custom tags, which are |
|
| 482 | - * preserved. |
|
| 483 | - * |
|
| 484 | - * @param string $string |
|
| 485 | - * @throws XMLHelper_Exception |
|
| 486 | - * @return string |
|
| 487 | - */ |
|
| 477 | + /** |
|
| 478 | + * Converts a string to valid XML: can be a text only string |
|
| 479 | + * or an HTML string. Returns valid XML code. |
|
| 480 | + * |
|
| 481 | + * NOTE: The string may contain custom tags, which are |
|
| 482 | + * preserved. |
|
| 483 | + * |
|
| 484 | + * @param string $string |
|
| 485 | + * @throws XMLHelper_Exception |
|
| 486 | + * @return string |
|
| 487 | + */ |
|
| 488 | 488 | public static function string2xml(string $string) : string |
| 489 | 489 | { |
| 490 | 490 | return XMLHelper_HTMLLoader::loadFragment($string)->fragmentToXML(); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public static function json($subject) : string |
| 110 | 110 | { |
| 111 | - if(!is_string($subject)) |
|
| 111 | + if (!is_string($subject)) |
|
| 112 | 112 | { |
| 113 | 113 | $subject = json_encode($subject, JSON_PRETTY_PRINT); |
| 114 | 114 | } |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | * @param bool $formatSource Whether to format the source with indentation to make it readable. |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | - public static function xml(string $xml, bool $formatSource=false) : string |
|
| 128 | + public static function xml(string $xml, bool $formatSource = false) : string |
|
| 129 | 129 | { |
| 130 | - if($formatSource) |
|
| 130 | + if ($formatSource) |
|
| 131 | 131 | { |
| 132 | 132 | $dom = new DOMDocument(); |
| 133 | 133 | $dom->preserveWhiteSpace = false; |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | * @param bool $formatSource |
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | - public static function html(string $html, bool $formatSource=false) : string |
|
| 151 | + public static function html(string $html, bool $formatSource = false) : string |
|
| 152 | 152 | { |
| 153 | - if($formatSource) |
|
| 153 | + if ($formatSource) |
|
| 154 | 154 | { |
| 155 | 155 | $dom = new DOMDocument(); |
| 156 | 156 | $dom->preserveWhiteSpace = false; |
@@ -41,71 +41,71 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | class Highlighter |
| 43 | 43 | { |
| 44 | - /** |
|
| 45 | - * Creates a new GeSHi instance from a source code string. |
|
| 46 | - * |
|
| 47 | - * @param string $sourceCode |
|
| 48 | - * @param string $format |
|
| 49 | - * @return GeSHi |
|
| 50 | - */ |
|
| 44 | + /** |
|
| 45 | + * Creates a new GeSHi instance from a source code string. |
|
| 46 | + * |
|
| 47 | + * @param string $sourceCode |
|
| 48 | + * @param string $format |
|
| 49 | + * @return GeSHi |
|
| 50 | + */ |
|
| 51 | 51 | public static function fromString(string $sourceCode, string $format) : GeSHi |
| 52 | 52 | { |
| 53 | 53 | return new GeSHi($sourceCode, $format); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Creates a new GeSHi instance from the contents of a file. |
|
| 58 | - * |
|
| 59 | - * @param string $path |
|
| 60 | - * @param string $format |
|
| 61 | - * @return GeSHi |
|
| 62 | - */ |
|
| 56 | + /** |
|
| 57 | + * Creates a new GeSHi instance from the contents of a file. |
|
| 58 | + * |
|
| 59 | + * @param string $path |
|
| 60 | + * @param string $format |
|
| 61 | + * @return GeSHi |
|
| 62 | + */ |
|
| 63 | 63 | public static function fromFile(string $path, string $format) : GeSHi |
| 64 | 64 | { |
| 65 | 65 | return self::fromString(FileHelper::readContents($path), $format); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Parses and highlights the target string. |
|
| 70 | - * |
|
| 71 | - * @param string $sourceCode |
|
| 72 | - * @param string $format |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 68 | + /** |
|
| 69 | + * Parses and highlights the target string. |
|
| 70 | + * |
|
| 71 | + * @param string $sourceCode |
|
| 72 | + * @param string $format |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | 75 | public static function parseString(string $sourceCode, string $format) : string |
| 76 | 76 | { |
| 77 | 77 | return self::fromString($sourceCode, $format)->parse_code(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Parses and highlights the contents of the target file. |
|
| 82 | - * |
|
| 83 | - * @param string $path |
|
| 84 | - * @param string $format |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 80 | + /** |
|
| 81 | + * Parses and highlights the contents of the target file. |
|
| 82 | + * |
|
| 83 | + * @param string $path |
|
| 84 | + * @param string $format |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | 87 | public static function parseFile(string $path, string $format) : string |
| 88 | 88 | { |
| 89 | 89 | return self::fromFile($path, $format)->parse_code(); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Adds HTML syntax highlighting to the specified SQL string. |
|
| 94 | - * |
|
| 95 | - * @param string $sql |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 92 | + /** |
|
| 93 | + * Adds HTML syntax highlighting to the specified SQL string. |
|
| 94 | + * |
|
| 95 | + * @param string $sql |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | 98 | public static function sql(string $sql) : string |
| 99 | 99 | { |
| 100 | 100 | return self::parseString($sql, 'sql'); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Adds HTML syntax highlighting to a JSON string, or a data array/object. |
|
| 105 | - * |
|
| 106 | - * @param array<int|string,mixed>|object|string $subject A JSON string, or data array/object to convert to JSON to highlight. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 103 | + /** |
|
| 104 | + * Adds HTML syntax highlighting to a JSON string, or a data array/object. |
|
| 105 | + * |
|
| 106 | + * @param array<int|string,mixed>|object|string $subject A JSON string, or data array/object to convert to JSON to highlight. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | 109 | public static function json($subject) : string |
| 110 | 110 | { |
| 111 | 111 | if(!is_string($subject)) |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | return self::parseString($subject, 'javascript'); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Adds HTML syntax highlighting to the specified XML code. |
|
| 123 | - * |
|
| 124 | - * @param string $xml The XML to highlight. |
|
| 125 | - * @param bool $formatSource Whether to format the source with indentation to make it readable. |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 121 | + /** |
|
| 122 | + * Adds HTML syntax highlighting to the specified XML code. |
|
| 123 | + * |
|
| 124 | + * @param string $xml The XML to highlight. |
|
| 125 | + * @param bool $formatSource Whether to format the source with indentation to make it readable. |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | 128 | public static function xml(string $xml, bool $formatSource=false) : string |
| 129 | 129 | { |
| 130 | 130 | if($formatSource) |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | return self::parseString($xml, 'xml'); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Adds HTML syntax highlighting to the specified HTML code. |
|
| 146 | - * |
|
| 147 | - * @param string $html |
|
| 148 | - * @param bool $formatSource |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 144 | + /** |
|
| 145 | + * Adds HTML syntax highlighting to the specified HTML code. |
|
| 146 | + * |
|
| 147 | + * @param string $html |
|
| 148 | + * @param bool $formatSource |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | 151 | public static function html(string $html, bool $formatSource=false) : string |
| 152 | 152 | { |
| 153 | 153 | if($formatSource) |
@@ -164,27 +164,27 @@ discard block |
||
| 164 | 164 | return self::parseString($html, 'xml'); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Adds HTML syntax highlighting to a bit of PHP code. |
|
| 169 | - * |
|
| 170 | - * @param string $phpCode |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 167 | + /** |
|
| 168 | + * Adds HTML syntax highlighting to a bit of PHP code. |
|
| 169 | + * |
|
| 170 | + * @param string $phpCode |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | 173 | public static function php(string $phpCode) : string |
| 174 | 174 | { |
| 175 | 175 | return self::parseString($phpCode, 'php'); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Adds HTML syntax highlighting to an URL. |
|
| 180 | - * |
|
| 181 | - * NOTE: Includes the necessary CSS styles. When |
|
| 182 | - * highlighting several URLs in the same page, |
|
| 183 | - * prefer using the `parseURL` function instead. |
|
| 184 | - * |
|
| 185 | - * @param string $url |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 178 | + /** |
|
| 179 | + * Adds HTML syntax highlighting to an URL. |
|
| 180 | + * |
|
| 181 | + * NOTE: Includes the necessary CSS styles. When |
|
| 182 | + * highlighting several URLs in the same page, |
|
| 183 | + * prefer using the `parseURL` function instead. |
|
| 184 | + * |
|
| 185 | + * @param string $url |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | 188 | public static function url(string $url) : string |
| 189 | 189 | { |
| 190 | 190 | $info = parseURL($url); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private function initUnits() : void |
| 50 | 50 | { |
| 51 | - if(isset(self::$units)) |
|
| 51 | + if (isset(self::$units)) |
|
| 52 | 52 | { |
| 53 | 53 | return; |
| 54 | 54 | } |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | public function toString() : string |
| 91 | 91 | { |
| 92 | 92 | // specifically handle zero |
| 93 | - if($this->seconds <= 0) |
|
| 93 | + if ($this->seconds <= 0) |
|
| 94 | 94 | { |
| 95 | - return '0 ' . t('seconds'); |
|
| 95 | + return '0 '.t('seconds'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if($this->seconds < 1) |
|
| 98 | + if ($this->seconds < 1) |
|
| 99 | 99 | { |
| 100 | 100 | return t('less than a second'); |
| 101 | 101 | } |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $last = array_pop($tokens); |
| 106 | 106 | |
| 107 | - if(empty($tokens)) |
|
| 107 | + if (empty($tokens)) |
|
| 108 | 108 | { |
| 109 | 109 | return $last; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
|
| 112 | + return implode(', ', $tokens).' '.t('and').' '.$last; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -122,18 +122,18 @@ discard block |
||
| 122 | 122 | $seconds = $this->seconds; |
| 123 | 123 | $tokens = array(); |
| 124 | 124 | |
| 125 | - foreach(self::$units as $def) |
|
| 125 | + foreach (self::$units as $def) |
|
| 126 | 126 | { |
| 127 | 127 | $unitValue = intval($seconds / $def['value']); |
| 128 | 128 | |
| 129 | - if($unitValue <= 0) |
|
| 129 | + if ($unitValue <= 0) |
|
| 130 | 130 | { |
| 131 | 131 | continue; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $item = strval($unitValue) . ' '; |
|
| 134 | + $item = strval($unitValue).' '; |
|
| 135 | 135 | |
| 136 | - if(abs($unitValue) > 1) |
|
| 136 | + if (abs($unitValue) > 1) |
|
| 137 | 137 | { |
| 138 | 138 | $item .= $def['plural']; |
| 139 | 139 | } |
@@ -136,8 +136,7 @@ |
||
| 136 | 136 | if(abs($unitValue) > 1) |
| 137 | 137 | { |
| 138 | 138 | $item .= $def['plural']; |
| 139 | - } |
|
| 140 | - else |
|
| 139 | + } else |
|
| 141 | 140 | { |
| 142 | 141 | $item .= $def['singular']; |
| 143 | 142 | } |
@@ -23,19 +23,19 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class ConvertHelper_TimeConverter |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var float |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var float |
|
| 28 | + */ |
|
| 29 | 29 | private $seconds; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var array<int,array<string,string|int>>|NULL |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var array<int,array<string,string|int>>|NULL |
|
| 33 | + */ |
|
| 34 | 34 | private static $units; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param float $seconds |
|
| 38 | - */ |
|
| 36 | + /** |
|
| 37 | + * @param float $seconds |
|
| 38 | + */ |
|
| 39 | 39 | public function __construct($seconds) |
| 40 | 40 | { |
| 41 | 41 | $this->seconds = $seconds; |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | $this->initUnits(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Creates the list of units once per request as needed. |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * Creates the list of units once per request as needed. |
|
| 48 | + */ |
|
| 49 | 49 | private function initUnits() : void |
| 50 | 50 | { |
| 51 | 51 | if(isset(self::$units)) |
@@ -112,11 +112,11 @@ discard block |
||
| 112 | 112 | return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Resolves the list of converted units. |
|
| 117 | - * |
|
| 118 | - * @return string[] |
|
| 119 | - */ |
|
| 115 | + /** |
|
| 116 | + * Resolves the list of converted units. |
|
| 117 | + * |
|
| 118 | + * @return string[] |
|
| 119 | + */ |
|
| 120 | 120 | private function resolveTokens() : array |
| 121 | 121 | { |
| 122 | 122 | $seconds = $this->seconds; |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | 'fragment' |
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | - foreach($parts as $part) |
|
| 80 | + foreach ($parts as $part) |
|
| 81 | 81 | { |
| 82 | 82 | $method = 'render_'.$part; |
| 83 | 83 | $result[] = (string)$this->$method(); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | protected function render_scheme() : string |
| 90 | 90 | { |
| 91 | - if(!$this->info->hasScheme()) { |
|
| 91 | + if (!$this->info->hasScheme()) { |
|
| 92 | 92 | return ''; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | protected function render_username() : string |
| 105 | 105 | { |
| 106 | - if(!$this->info->hasUsername()) { |
|
| 106 | + if (!$this->info->hasUsername()) { |
|
| 107 | 107 | return ''; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | protected function render_host() : string |
| 121 | 121 | { |
| 122 | - if(!$this->info->hasHost()) { |
|
| 122 | + if (!$this->info->hasHost()) { |
|
| 123 | 123 | return ''; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | protected function render_port() : string |
| 133 | 133 | { |
| 134 | - if(!$this->info->hasPort()) { |
|
| 134 | + if (!$this->info->hasPort()) { |
|
| 135 | 135 | return ''; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | protected function render_path() : string |
| 146 | 146 | { |
| 147 | - if(!$this->info->hasPath()) { |
|
| 147 | + if (!$this->info->hasPath()) { |
|
| 148 | 148 | return ''; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | $previous = $this->info->isParamExclusionEnabled(); |
| 171 | 171 | |
| 172 | - if($previous) |
|
| 172 | + if ($previous) |
|
| 173 | 173 | { |
| 174 | 174 | $this->info->setParamExclusion(false); |
| 175 | 175 | } |
@@ -185,19 +185,19 @@ discard block |
||
| 185 | 185 | { |
| 186 | 186 | $params = $this->resolveParams(); |
| 187 | 187 | |
| 188 | - if(empty($params)) { |
|
| 188 | + if (empty($params)) { |
|
| 189 | 189 | return ''; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $tokens = array(); |
| 193 | 193 | $excluded = array(); |
| 194 | 194 | |
| 195 | - if($this->info->isParamExclusionEnabled()) |
|
| 195 | + if ($this->info->isParamExclusionEnabled()) |
|
| 196 | 196 | { |
| 197 | 197 | $excluded = $this->info->getExcludedParams(); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - foreach($params as $param => $value) |
|
| 200 | + foreach ($params as $param => $value) |
|
| 201 | 201 | { |
| 202 | 202 | // If the parameter is numeric, it will automatically |
| 203 | 203 | // be an integer, so we need the conversion here. |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | $tag = $this->resolveTag($excluded, $param); |
| 220 | 220 | |
| 221 | - if(!empty($tag)) |
|
| 221 | + if (!empty($tag)) |
|
| 222 | 222 | { |
| 223 | 223 | $tokens[] = sprintf($tag, $parts); |
| 224 | 224 | } |
@@ -232,13 +232,13 @@ discard block |
||
| 232 | 232 | protected function resolveTag(array $excluded, string $paramName) : string |
| 233 | 233 | { |
| 234 | 234 | // regular, non-excluded parameter |
| 235 | - if(!isset($excluded[$paramName])) |
|
| 235 | + if (!isset($excluded[$paramName])) |
|
| 236 | 236 | { |
| 237 | 237 | return '<span class="link-param">%s</span>'; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // highlight excluded parameters is disabled, ignore this parameter |
| 241 | - if(!$this->info->isHighlightExcludeEnabled()) |
|
| 241 | + if (!$this->info->isHighlightExcludeEnabled()) |
|
| 242 | 242 | { |
| 243 | 243 | return ''; |
| 244 | 244 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | protected function render_fragment() : string |
| 256 | 256 | { |
| 257 | - if(!$this->info->hasFragment()) { |
|
| 257 | + if (!$this->info->hasFragment()) { |
|
| 258 | 258 | return ''; |
| 259 | 259 | } |
| 260 | 260 | |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | { |
| 270 | 270 | $cssFolder = realpath(__DIR__.'/../../css'); |
| 271 | 271 | |
| 272 | - if($cssFolder === false) { |
|
| 272 | + if ($cssFolder === false) { |
|
| 273 | 273 | throw new BaseException( |
| 274 | 274 | 'Cannot find package CSS folder.', |
| 275 | 275 | null, |
@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class URLInfo_Highlighter |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var URLInfo |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var URLInfo |
|
| 25 | + */ |
|
| 26 | 26 | protected $info; |
| 27 | 27 | |
| 28 | 28 | public function __construct(URLInfo $info) |
@@ -158,13 +158,13 @@ discard block |
||
| 158 | 158 | ); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Fetches all parameters in the URL, regardless of |
|
| 163 | - * whether parameter exclusion is enabled, so they |
|
| 164 | - * can be highlighted is need be. |
|
| 165 | - * |
|
| 166 | - * @return array<string,string> |
|
| 167 | - */ |
|
| 161 | + /** |
|
| 162 | + * Fetches all parameters in the URL, regardless of |
|
| 163 | + * whether parameter exclusion is enabled, so they |
|
| 164 | + * can be highlighted is need be. |
|
| 165 | + * |
|
| 166 | + * @return array<string,string> |
|
| 167 | + */ |
|
| 168 | 168 | protected function resolveParams() : array |
| 169 | 169 | { |
| 170 | 170 | $previous = $this->info->isParamExclusionEnabled(); |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | $autoload = $root.'/vendor/autoload.php'; |
| 16 | 16 | |
| 17 | 17 | // we need the autoloader to be present |
| 18 | - if($autoload === false) |
|
| 18 | + if ($autoload === false) |
|
| 19 | 19 | { |
| 20 | 20 | die('<b>ERROR:</b> Autoloader not present. Run composer update first.'); |
| 21 | 21 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public static function detect(string $subjectString) : ?ConvertHelper_EOL |
| 123 | 123 | { |
| 124 | - if(empty($subjectString)) { |
|
| 124 | + if (empty($subjectString)) { |
|
| 125 | 125 | return null; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -129,18 +129,18 @@ discard block |
||
| 129 | 129 | $results = array(); |
| 130 | 130 | $chars = self::getEOLChars(); |
| 131 | 131 | |
| 132 | - foreach($chars as $def) |
|
| 132 | + foreach ($chars as $def) |
|
| 133 | 133 | { |
| 134 | 134 | $amount = substr_count($subjectString, $def['char']); |
| 135 | 135 | |
| 136 | - if($amount > $max) |
|
| 136 | + if ($amount > $max) |
|
| 137 | 137 | { |
| 138 | 138 | $max = $amount; |
| 139 | 139 | $results[] = $def; |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if(empty($results)) { |
|
| 143 | + if (empty($results)) { |
|
| 144 | 144 | return null; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public static function getEOLChars() : array |
| 158 | 158 | { |
| 159 | - if(isset(self::$eolChars)) { |
|
| 159 | + if (isset(self::$eolChars)) { |
|
| 160 | 160 | return self::$eolChars; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | public const TYPE_LF = 'LF'; |
| 30 | 30 | public const TYPE_CR = 'CR'; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $char; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | 40 | protected $type; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $description; |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -56,33 +56,33 @@ discard block |
||
| 56 | 56 | $this->description = $description; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * The actual EOL character. |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 59 | + /** |
|
| 60 | + * The actual EOL character. |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | 63 | public function getCharacter() : string |
| 64 | 64 | { |
| 65 | 65 | return $this->char; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * A more detailed, human readable description of the character. |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 68 | + /** |
|
| 69 | + * A more detailed, human readable description of the character. |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | 72 | public function getDescription() : string |
| 73 | 73 | { |
| 74 | 74 | return $this->description; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * The EOL character type, e.g. "CR+LF", "CR"... |
|
| 79 | - * @return string |
|
| 80 | - * |
|
| 81 | - * @see ConvertHelper_EOL::TYPE_CR |
|
| 82 | - * @see ConvertHelper_EOL::TYPE_CRLF |
|
| 83 | - * @see ConvertHelper_EOL::TYPE_LF |
|
| 84 | - * @see ConvertHelper_EOL::TYPE_LFCR |
|
| 85 | - */ |
|
| 77 | + /** |
|
| 78 | + * The EOL character type, e.g. "CR+LF", "CR"... |
|
| 79 | + * @return string |
|
| 80 | + * |
|
| 81 | + * @see ConvertHelper_EOL::TYPE_CR |
|
| 82 | + * @see ConvertHelper_EOL::TYPE_CRLF |
|
| 83 | + * @see ConvertHelper_EOL::TYPE_LF |
|
| 84 | + * @see ConvertHelper_EOL::TYPE_LFCR |
|
| 85 | + */ |
|
| 86 | 86 | public function getType() : string |
| 87 | 87 | { |
| 88 | 88 | return $this->type; |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | * @param bool $forceNew |
| 13 | 13 | * @return NumberInfo |
| 14 | 14 | */ |
| 15 | -function parseNumber($value, bool $forceNew=false) |
|
| 15 | +function parseNumber($value, bool $forceNew = false) |
|
| 16 | 16 | { |
| 17 | - if($value instanceof NumberInfo && $forceNew !== true) { |
|
| 17 | + if ($value instanceof NumberInfo && $forceNew !== true) { |
|
| 18 | 18 | return $value; |
| 19 | 19 | } |
| 20 | 20 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $args = func_get_args(); |
| 96 | 96 | |
| 97 | 97 | // is the localization package installed? |
| 98 | - if(function_exists('\AppLocalize\t')) |
|
| 98 | + if (function_exists('\AppLocalize\t')) |
|
| 99 | 99 | { |
| 100 | 100 | return call_user_func_array('\AppLocalize\t', $args); |
| 101 | 101 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param bool $initial The initial boolean value to use. |
| 111 | 111 | * @return Value_Bool |
| 112 | 112 | */ |
| 113 | -function valBool(bool $initial=false) : Value_Bool |
|
| 113 | +function valBool(bool $initial = false) : Value_Bool |
|
| 114 | 114 | { |
| 115 | 115 | return new Value_Bool($initial); |
| 116 | 116 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param bool $initial |
| 124 | 124 | * @return Value_Bool_True |
| 125 | 125 | */ |
| 126 | -function valBoolTrue(bool $initial=false) : Value_Bool_True |
|
| 126 | +function valBoolTrue(bool $initial = false) : Value_Bool_True |
|
| 127 | 127 | { |
| 128 | 128 | return new Value_Bool_True($initial); |
| 129 | 129 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @param bool $initial |
| 137 | 137 | * @return Value_Bool_False |
| 138 | 138 | */ |
| 139 | -function valBoolFalse(bool $initial=true) : Value_Bool_False |
|
| 139 | +function valBoolFalse(bool $initial = true) : Value_Bool_False |
|
| 140 | 140 | { |
| 141 | 141 | return new Value_Bool_False($initial); |
| 142 | 142 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | function init() |
| 169 | 169 | { |
| 170 | - if(!class_exists('\AppLocalize\Localization')) { |
|
| 170 | + if (!class_exists('\AppLocalize\Localization')) { |
|
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |