@@ -24,19 +24,19 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | use Traits_Optionable; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @see https://gist.github.com/gruber/249502 |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @see https://gist.github.com/gruber/249502 |
|
| 29 | + */ |
|
| 30 | 30 | const REGEX_URL = '#(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#i'; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $subject; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string[] |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var string[] |
|
| 39 | + */ |
|
| 40 | 40 | protected $schemes = array( |
| 41 | 41 | 'http', |
| 42 | 42 | 'https', |
@@ -62,49 +62,49 @@ discard block |
||
| 62 | 62 | ); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Whether to enable sorting the URLs alphabetically (disabled by default). |
|
| 67 | - * |
|
| 68 | - * @param bool $enabled |
|
| 69 | - * @return ConvertHelper_URLFinder |
|
| 70 | - */ |
|
| 65 | + /** |
|
| 66 | + * Whether to enable sorting the URLs alphabetically (disabled by default). |
|
| 67 | + * |
|
| 68 | + * @param bool $enabled |
|
| 69 | + * @return ConvertHelper_URLFinder |
|
| 70 | + */ |
|
| 71 | 71 | public function enableSorting(bool $enabled=true) : ConvertHelper_URLFinder |
| 72 | 72 | { |
| 73 | 73 | $this->setOption('sorting', $enabled); |
| 74 | 74 | return $this; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Whether to include email addresses in the search. |
|
| 79 | - * This is only relevant when using the getURLs() |
|
| 80 | - * method. |
|
| 81 | - * |
|
| 82 | - * @param bool $include |
|
| 83 | - * @return ConvertHelper_URLFinder |
|
| 84 | - */ |
|
| 77 | + /** |
|
| 78 | + * Whether to include email addresses in the search. |
|
| 79 | + * This is only relevant when using the getURLs() |
|
| 80 | + * method. |
|
| 81 | + * |
|
| 82 | + * @param bool $include |
|
| 83 | + * @return ConvertHelper_URLFinder |
|
| 84 | + */ |
|
| 85 | 85 | public function includeEmails(bool $include=true) : ConvertHelper_URLFinder |
| 86 | 86 | { |
| 87 | 87 | $this->setOption('include-emails', $include); |
| 88 | 88 | return $this; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Whether to omit the mailto: that is automatically added to all email addresses. |
|
| 93 | - * |
|
| 94 | - * @param bool $omit |
|
| 95 | - * @return ConvertHelper_URLFinder |
|
| 96 | - */ |
|
| 91 | + /** |
|
| 92 | + * Whether to omit the mailto: that is automatically added to all email addresses. |
|
| 93 | + * |
|
| 94 | + * @param bool $omit |
|
| 95 | + * @return ConvertHelper_URLFinder |
|
| 96 | + */ |
|
| 97 | 97 | public function omitMailto(bool $omit=true) : ConvertHelper_URLFinder |
| 98 | 98 | { |
| 99 | 99 | $this->setOption('omit-mailto', $omit); |
| 100 | 100 | return $this; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Prepares the subject string by adding a newline before all URL schemes, |
|
| 105 | - * to make it possible to parse even lists of links separated by commas or |
|
| 106 | - * the like (http://domain.com,http://domain2.com). |
|
| 107 | - */ |
|
| 103 | + /** |
|
| 104 | + * Prepares the subject string by adding a newline before all URL schemes, |
|
| 105 | + * to make it possible to parse even lists of links separated by commas or |
|
| 106 | + * the like (http://domain.com,http://domain2.com). |
|
| 107 | + */ |
|
| 108 | 108 | private function prepareSubject() : void |
| 109 | 109 | { |
| 110 | 110 | $replaces = array(); |
@@ -117,11 +117,11 @@ discard block |
||
| 117 | 117 | $this->subject = str_replace(array_keys($replaces), array_values($replaces), $this->subject); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Fetches all URLs that can be found in the subject string. |
|
| 122 | - * |
|
| 123 | - * @return string[] |
|
| 124 | - */ |
|
| 120 | + /** |
|
| 121 | + * Fetches all URLs that can be found in the subject string. |
|
| 122 | + * |
|
| 123 | + * @return string[] |
|
| 124 | + */ |
|
| 125 | 125 | public function getURLs() : array |
| 126 | 126 | { |
| 127 | 127 | $this->prepareSubject(); |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | return $result; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Retrieves all email addresses from the subject string. |
|
| 159 | - * |
|
| 160 | - * @return string[] |
|
| 161 | - * |
|
| 162 | - * @see omitMailto() |
|
| 163 | - */ |
|
| 157 | + /** |
|
| 158 | + * Retrieves all email addresses from the subject string. |
|
| 159 | + * |
|
| 160 | + * @return string[] |
|
| 161 | + * |
|
| 162 | + * @see omitMailto() |
|
| 163 | + */ |
|
| 164 | 164 | public function getEmails() : array |
| 165 | 165 | { |
| 166 | 166 | $matches = array(); |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | return 'mailto:'; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Retrieves all URLs as URLInfo instances. |
|
| 199 | - * |
|
| 200 | - * @return URLInfo[] |
|
| 201 | - */ |
|
| 197 | + /** |
|
| 198 | + * Retrieves all URLs as URLInfo instances. |
|
| 199 | + * |
|
| 200 | + * @return URLInfo[] |
|
| 201 | + */ |
|
| 202 | 202 | public function getInfos() |
| 203 | 203 | { |
| 204 | 204 | $urls = $this->getURLs(); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @param bool $enabled |
| 69 | 69 | * @return ConvertHelper_URLFinder |
| 70 | 70 | */ |
| 71 | - public function enableSorting(bool $enabled=true) : ConvertHelper_URLFinder |
|
| 71 | + public function enableSorting(bool $enabled = true) : ConvertHelper_URLFinder |
|
| 72 | 72 | { |
| 73 | 73 | $this->setOption('sorting', $enabled); |
| 74 | 74 | return $this; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param bool $include |
| 83 | 83 | * @return ConvertHelper_URLFinder |
| 84 | 84 | */ |
| 85 | - public function includeEmails(bool $include=true) : ConvertHelper_URLFinder |
|
| 85 | + public function includeEmails(bool $include = true) : ConvertHelper_URLFinder |
|
| 86 | 86 | { |
| 87 | 87 | $this->setOption('include-emails', $include); |
| 88 | 88 | return $this; |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param bool $omit |
| 95 | 95 | * @return ConvertHelper_URLFinder |
| 96 | 96 | */ |
| 97 | - public function omitMailto(bool $omit=true) : ConvertHelper_URLFinder |
|
| 97 | + public function omitMailto(bool $omit = true) : ConvertHelper_URLFinder |
|
| 98 | 98 | { |
| 99 | 99 | $this->setOption('omit-mailto', $omit); |
| 100 | 100 | return $this; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | $replaces = array(); |
| 111 | 111 | |
| 112 | - foreach($this->schemes as $scheme) |
|
| 112 | + foreach ($this->schemes as $scheme) |
|
| 113 | 113 | { |
| 114 | 114 | $replaces[$scheme.':'] = PHP_EOL.$scheme.':'; |
| 115 | 115 | } |
@@ -131,20 +131,20 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | $result = array(); |
| 133 | 133 | |
| 134 | - foreach($matches[0] as $match) |
|
| 134 | + foreach ($matches[0] as $match) |
|
| 135 | 135 | { |
| 136 | - if(strstr($match, '://') && !in_array($match, $result)) |
|
| 136 | + if (strstr($match, '://') && !in_array($match, $result)) |
|
| 137 | 137 | { |
| 138 | 138 | $result[] = $match; |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if($this->getBoolOption('include-emails')) |
|
| 142 | + if ($this->getBoolOption('include-emails')) |
|
| 143 | 143 | { |
| 144 | 144 | $result = array_merge($result, $this->getEmails()); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if($this->getBoolOption('sorting')) |
|
| 147 | + if ($this->getBoolOption('sorting')) |
|
| 148 | 148 | { |
| 149 | 149 | usort($result, function(string $a, string $b) { |
| 150 | 150 | return strnatcasecmp($a, $b); |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | $result = array(); |
| 170 | 170 | $prefix = $this->getEmailPrefix(); |
| 171 | 171 | |
| 172 | - foreach($matches[0] as $email) |
|
| 172 | + foreach ($matches[0] as $email) |
|
| 173 | 173 | { |
| 174 | 174 | $result[] = $prefix.$email; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - if($this->getBoolOption('sorting')) |
|
| 177 | + if ($this->getBoolOption('sorting')) |
|
| 178 | 178 | { |
| 179 | 179 | usort($result, function(string $a, string $b) { |
| 180 | 180 | return strnatcasecmp($a, $b); |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | private function getEmailPrefix() : string |
| 188 | 188 | { |
| 189 | - if($this->getBoolOption('omit-mailto')) |
|
| 189 | + if ($this->getBoolOption('omit-mailto')) |
|
| 190 | 190 | { |
| 191 | 191 | return ''; |
| 192 | 192 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | $result = array(); |
| 207 | 207 | |
| 208 | - foreach($urls as $url) |
|
| 208 | + foreach ($urls as $url) |
|
| 209 | 209 | { |
| 210 | 210 | $result[] = parseURL($url); |
| 211 | 211 | } |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | protected static $instance; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $baseURL = ''; |
| 46 | 46 | |
| 47 | 47 | public function __construct() |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | $this->init(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Can be extended in a subclass, to avoid |
|
| 56 | - * redefining the constructor. |
|
| 57 | - */ |
|
| 54 | + /** |
|
| 55 | + * Can be extended in a subclass, to avoid |
|
| 56 | + * redefining the constructor. |
|
| 57 | + */ |
|
| 58 | 58 | protected function init() |
| 59 | 59 | { |
| 60 | 60 | |
@@ -126,30 +126,30 @@ discard block |
||
| 126 | 126 | return $this->buildURL($params, $dispatcher); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Retrieves the name of the current dispatcher script / page. |
|
| 131 | - * This is made to be extended and implemented in a subclass. |
|
| 132 | - * |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 129 | + /** |
|
| 130 | + * Retrieves the name of the current dispatcher script / page. |
|
| 131 | + * This is made to be extended and implemented in a subclass. |
|
| 132 | + * |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | 135 | public function getDispatcher() : string |
| 136 | 136 | { |
| 137 | 137 | return ''; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Filters and retrieves the current request variables |
|
| 142 | - * to be used to build an URL to refresh the current page. |
|
| 143 | - * |
|
| 144 | - * For further customization options, use the |
|
| 145 | - * {@see Request::createRefreshParams()} method. |
|
| 146 | - * |
|
| 147 | - * @param array<string,mixed> $params Key => value pairs of parameters to always include in the result. |
|
| 148 | - * @param string[] $exclude Names of parameters to exclude from the result. |
|
| 149 | - * @return array<string,mixed> |
|
| 150 | - * |
|
| 151 | - * @see Request::createRefreshParams() |
|
| 152 | - */ |
|
| 140 | + /** |
|
| 141 | + * Filters and retrieves the current request variables |
|
| 142 | + * to be used to build an URL to refresh the current page. |
|
| 143 | + * |
|
| 144 | + * For further customization options, use the |
|
| 145 | + * {@see Request::createRefreshParams()} method. |
|
| 146 | + * |
|
| 147 | + * @param array<string,mixed> $params Key => value pairs of parameters to always include in the result. |
|
| 148 | + * @param string[] $exclude Names of parameters to exclude from the result. |
|
| 149 | + * @return array<string,mixed> |
|
| 150 | + * |
|
| 151 | + * @see Request::createRefreshParams() |
|
| 152 | + */ |
|
| 153 | 153 | public function getRefreshParams(array $params = array(), array $exclude = array()) |
| 154 | 154 | { |
| 155 | 155 | return $this->createRefreshParams() |
@@ -158,13 +158,13 @@ discard block |
||
| 158 | 158 | ->getParams(); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Creates an instance of the helper that can be used to |
|
| 163 | - * retrieve the request's parameters collection, with the |
|
| 164 | - * possiblity to exlude and override some by rules. |
|
| 165 | - * |
|
| 166 | - * @return Request_RefreshParams |
|
| 167 | - */ |
|
| 161 | + /** |
|
| 162 | + * Creates an instance of the helper that can be used to |
|
| 163 | + * retrieve the request's parameters collection, with the |
|
| 164 | + * possiblity to exlude and override some by rules. |
|
| 165 | + * |
|
| 166 | + * @return Request_RefreshParams |
|
| 167 | + */ |
|
| 168 | 168 | public function createRefreshParams() : Request_RefreshParams |
| 169 | 169 | { |
| 170 | 170 | return new Request_RefreshParams(); |
@@ -197,10 +197,10 @@ discard block |
||
| 197 | 197 | return $url; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * Retrieves the base URL of the application. |
|
| 202 | - * @return string |
|
| 203 | - */ |
|
| 200 | + /** |
|
| 201 | + * Retrieves the base URL of the application. |
|
| 202 | + * @return string |
|
| 203 | + */ |
|
| 204 | 204 | public function getBaseURL() : string |
| 205 | 205 | { |
| 206 | 206 | return $this->baseURL; |
@@ -230,13 +230,13 @@ discard block |
||
| 230 | 230 | return $this->knownParams[$name]; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Retrieves a previously registered parameter instance. |
|
| 235 | - * |
|
| 236 | - * @param string $name |
|
| 237 | - * @throws Request_Exception |
|
| 238 | - * @return Request_Param |
|
| 239 | - */ |
|
| 233 | + /** |
|
| 234 | + * Retrieves a previously registered parameter instance. |
|
| 235 | + * |
|
| 236 | + * @param string $name |
|
| 237 | + * @throws Request_Exception |
|
| 238 | + * @return Request_Param |
|
| 239 | + */ |
|
| 240 | 240 | public function getRegisteredParam(string $name) : Request_Param |
| 241 | 241 | { |
| 242 | 242 | if(isset($this->knownParams[$name])) { |
@@ -253,48 +253,48 @@ discard block |
||
| 253 | 253 | ); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Checks whether a parameter with the specified name |
|
| 258 | - * has been registered. |
|
| 259 | - * |
|
| 260 | - * @param string $name |
|
| 261 | - * @return bool |
|
| 262 | - */ |
|
| 256 | + /** |
|
| 257 | + * Checks whether a parameter with the specified name |
|
| 258 | + * has been registered. |
|
| 259 | + * |
|
| 260 | + * @param string $name |
|
| 261 | + * @return bool |
|
| 262 | + */ |
|
| 263 | 263 | public function hasRegisteredParam(string $name) : bool |
| 264 | 264 | { |
| 265 | 265 | return isset($this->knownParams[$name]); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Retrieves an indexed array with accept mime types |
|
| 270 | - * that the client sent, in the order of preference |
|
| 271 | - * the client specified. |
|
| 272 | - * |
|
| 273 | - * Example: |
|
| 274 | - * |
|
| 275 | - * array( |
|
| 276 | - * 'text/html', |
|
| 277 | - * 'application/xhtml+xml', |
|
| 278 | - * 'image/webp' |
|
| 279 | - * ... |
|
| 280 | - * ) |
|
| 281 | - * |
|
| 282 | - * @return array |
|
| 283 | - * @see Request::parseAcceptHeaders() |
|
| 284 | - */ |
|
| 268 | + /** |
|
| 269 | + * Retrieves an indexed array with accept mime types |
|
| 270 | + * that the client sent, in the order of preference |
|
| 271 | + * the client specified. |
|
| 272 | + * |
|
| 273 | + * Example: |
|
| 274 | + * |
|
| 275 | + * array( |
|
| 276 | + * 'text/html', |
|
| 277 | + * 'application/xhtml+xml', |
|
| 278 | + * 'image/webp' |
|
| 279 | + * ... |
|
| 280 | + * ) |
|
| 281 | + * |
|
| 282 | + * @return array |
|
| 283 | + * @see Request::parseAcceptHeaders() |
|
| 284 | + */ |
|
| 285 | 285 | public static function getAcceptHeaders() : array |
| 286 | 286 | { |
| 287 | 287 | return self::parseAcceptHeaders()->getMimeStrings(); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Returns an instance of the accept headers parser, |
|
| 292 | - * to access information on the browser's accepted |
|
| 293 | - * mime types. |
|
| 294 | - * |
|
| 295 | - * @return Request_AcceptHeaders |
|
| 296 | - * @see Request::getAcceptHeaders() |
|
| 297 | - */ |
|
| 290 | + /** |
|
| 291 | + * Returns an instance of the accept headers parser, |
|
| 292 | + * to access information on the browser's accepted |
|
| 293 | + * mime types. |
|
| 294 | + * |
|
| 295 | + * @return Request_AcceptHeaders |
|
| 296 | + * @see Request::getAcceptHeaders() |
|
| 297 | + */ |
|
| 298 | 298 | public static function parseAcceptHeaders() : Request_AcceptHeaders |
| 299 | 299 | { |
| 300 | 300 | static $accept; |
@@ -342,14 +342,14 @@ discard block |
||
| 342 | 342 | return false; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - /** |
|
| 346 | - * Removes a single parameter from the request. |
|
| 347 | - * If the parameter has been registered, also |
|
| 348 | - * removes the registration info. |
|
| 349 | - * |
|
| 350 | - * @param string $name |
|
| 351 | - * @return Request |
|
| 352 | - */ |
|
| 345 | + /** |
|
| 346 | + * Removes a single parameter from the request. |
|
| 347 | + * If the parameter has been registered, also |
|
| 348 | + * removes the registration info. |
|
| 349 | + * |
|
| 350 | + * @param string $name |
|
| 351 | + * @return Request |
|
| 352 | + */ |
|
| 353 | 353 | public function removeParam(string $name) : Request |
| 354 | 354 | { |
| 355 | 355 | if(isset($_REQUEST[$name])) { |
@@ -363,12 +363,12 @@ discard block |
||
| 363 | 363 | return $this; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * Removes several parameters from the request. |
|
| 368 | - * |
|
| 369 | - * @param string[] $names |
|
| 370 | - * @return Request |
|
| 371 | - */ |
|
| 366 | + /** |
|
| 367 | + * Removes several parameters from the request. |
|
| 368 | + * |
|
| 369 | + * @param string[] $names |
|
| 370 | + * @return Request |
|
| 371 | + */ |
|
| 372 | 372 | public function removeParams(array $names) : Request |
| 373 | 373 | { |
| 374 | 374 | foreach($names as $name) { |
@@ -435,18 +435,18 @@ discard block |
||
| 435 | 435 | return $val; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - /** |
|
| 439 | - * Treats the request parameter as a JSON string, and |
|
| 440 | - * if it exists and contains valid JSON, returns the |
|
| 441 | - * decoded JSON value as an array (default). |
|
| 442 | - * |
|
| 443 | - * @param string $name |
|
| 444 | - * @param bool $assoc |
|
| 445 | - * @return array|object |
|
| 446 | - * |
|
| 447 | - * @see Request::getJSONAssoc() |
|
| 448 | - * @see Request::getJSONObject() |
|
| 449 | - */ |
|
| 438 | + /** |
|
| 439 | + * Treats the request parameter as a JSON string, and |
|
| 440 | + * if it exists and contains valid JSON, returns the |
|
| 441 | + * decoded JSON value as an array (default). |
|
| 442 | + * |
|
| 443 | + * @param string $name |
|
| 444 | + * @param bool $assoc |
|
| 445 | + * @return array|object |
|
| 446 | + * |
|
| 447 | + * @see Request::getJSONAssoc() |
|
| 448 | + * @see Request::getJSONObject() |
|
| 449 | + */ |
|
| 450 | 450 | public function getJSON(string $name, bool $assoc=true) |
| 451 | 451 | { |
| 452 | 452 | $value = $this->getParam($name); |
@@ -471,13 +471,13 @@ discard block |
||
| 471 | 471 | return new \stdClass(); |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - /** |
|
| 475 | - * Like {@link Request::getJSON()}, but omitting the second |
|
| 476 | - * parameter. Use this for more readable code. |
|
| 477 | - * |
|
| 478 | - * @param string $name |
|
| 479 | - * @return array |
|
| 480 | - */ |
|
| 474 | + /** |
|
| 475 | + * Like {@link Request::getJSON()}, but omitting the second |
|
| 476 | + * parameter. Use this for more readable code. |
|
| 477 | + * |
|
| 478 | + * @param string $name |
|
| 479 | + * @return array |
|
| 480 | + */ |
|
| 481 | 481 | public function getJSONAssoc(string $name) : array |
| 482 | 482 | { |
| 483 | 483 | $result = $this->getJSON($name); |
@@ -488,13 +488,13 @@ discard block |
||
| 488 | 488 | return array(); |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | - /** |
|
| 492 | - * Like {@link Request::getJSON()}, but omitting the second |
|
| 493 | - * parameter. Use this for more readable code. |
|
| 494 | - * |
|
| 495 | - * @param string $name |
|
| 496 | - * @return object |
|
| 497 | - */ |
|
| 491 | + /** |
|
| 492 | + * Like {@link Request::getJSON()}, but omitting the second |
|
| 493 | + * parameter. Use this for more readable code. |
|
| 494 | + * |
|
| 495 | + * @param string $name |
|
| 496 | + * @return object |
|
| 497 | + */ |
|
| 498 | 498 | public function getJSONObject(string $name) : object |
| 499 | 499 | { |
| 500 | 500 | $result = $this->getJSON($name, false); |
@@ -505,12 +505,12 @@ discard block |
||
| 505 | 505 | return new \stdClass(); |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - /** |
|
| 509 | - * Sends a JSON response with the correct headers. |
|
| 510 | - * |
|
| 511 | - * @param array|string $data |
|
| 512 | - * @param bool $exit Whether to exit the script afterwards. |
|
| 513 | - */ |
|
| 508 | + /** |
|
| 509 | + * Sends a JSON response with the correct headers. |
|
| 510 | + * |
|
| 511 | + * @param array|string $data |
|
| 512 | + * @param bool $exit Whether to exit the script afterwards. |
|
| 513 | + */ |
|
| 514 | 514 | public static function sendJSON($data, bool $exit=true) |
| 515 | 515 | { |
| 516 | 516 | $payload = $data; |
@@ -530,12 +530,12 @@ discard block |
||
| 530 | 530 | } |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | - /** |
|
| 534 | - * Sends HTML to the browser with the correct headers. |
|
| 535 | - * |
|
| 536 | - * @param string $html |
|
| 537 | - * @param bool $exit Whether to exit the script afterwards. |
|
| 538 | - */ |
|
| 533 | + /** |
|
| 534 | + * Sends HTML to the browser with the correct headers. |
|
| 535 | + * |
|
| 536 | + * @param string $html |
|
| 537 | + * @param bool $exit Whether to exit the script afterwards. |
|
| 538 | + */ |
|
| 539 | 539 | public static function sendHTML(string $html, bool $exit=true) |
| 540 | 540 | { |
| 541 | 541 | header('Cache-Control: no-cache, must-revalidate'); |
@@ -550,16 +550,16 @@ discard block |
||
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - /** |
|
| 554 | - * Creates a new instance of the URL comparer, which can check |
|
| 555 | - * whether the specified URLs match, regardless of the order in |
|
| 556 | - * which the query parameters are, if any. |
|
| 557 | - * |
|
| 558 | - * @param string $sourceURL |
|
| 559 | - * @param string $targetURL |
|
| 560 | - * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
| 561 | - * @return Request_URLComparer |
|
| 562 | - */ |
|
| 553 | + /** |
|
| 554 | + * Creates a new instance of the URL comparer, which can check |
|
| 555 | + * whether the specified URLs match, regardless of the order in |
|
| 556 | + * which the query parameters are, if any. |
|
| 557 | + * |
|
| 558 | + * @param string $sourceURL |
|
| 559 | + * @param string $targetURL |
|
| 560 | + * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
| 561 | + * @return Request_URLComparer |
|
| 562 | + */ |
|
| 563 | 563 | public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
| 564 | 564 | { |
| 565 | 565 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
@@ -568,10 +568,10 @@ discard block |
||
| 568 | 568 | return $comparer; |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | - /** |
|
| 572 | - * Retrieves the full URL that was used to access the current page. |
|
| 573 | - * @return string |
|
| 574 | - */ |
|
| 571 | + /** |
|
| 572 | + * Retrieves the full URL that was used to access the current page. |
|
| 573 | + * @return string |
|
| 574 | + */ |
|
| 575 | 575 | public function getCurrentURL() : string |
| 576 | 576 | { |
| 577 | 577 | return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | public function getParam($name, $default = null) |
| 91 | 91 | { |
| 92 | 92 | $value = $default; |
| 93 | - if(isset($_REQUEST[$name])) { |
|
| 93 | + if (isset($_REQUEST[$name])) { |
|
| 94 | 94 | $value = $_REQUEST[$name]; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if(isset($this->knownParams[$name])) { |
|
| 97 | + if (isset($this->knownParams[$name])) { |
|
| 98 | 98 | $value = $this->knownParams[$name]->validate($value); |
| 99 | 99 | } |
| 100 | 100 | |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | * @param string $dispatcher Relative path to script to use for the URL. Append trailing slash if needed. |
| 186 | 186 | * @return string |
| 187 | 187 | */ |
| 188 | - public function buildURL($params = array(), string $dispatcher='') |
|
| 188 | + public function buildURL($params = array(), string $dispatcher = '') |
|
| 189 | 189 | { |
| 190 | - $url = rtrim($this->getBaseURL(), '/') . '/' . $dispatcher; |
|
| 190 | + $url = rtrim($this->getBaseURL(), '/').'/'.$dispatcher; |
|
| 191 | 191 | |
| 192 | 192 | // append any leftover parameters to the end of the URL |
| 193 | 193 | if (!empty($params)) { |
| 194 | - $url .= '?' . http_build_query($params, '', '&'); |
|
| 194 | + $url .= '?'.http_build_query($params, '', '&'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return $url; |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function registerParam($name) |
| 224 | 224 | { |
| 225 | - if(!isset($this->knownParams[$name])) { |
|
| 225 | + if (!isset($this->knownParams[$name])) { |
|
| 226 | 226 | $param = new Request_Param($this, $name); |
| 227 | 227 | $this->knownParams[$name] = $param; |
| 228 | 228 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | */ |
| 240 | 240 | public function getRegisteredParam(string $name) : Request_Param |
| 241 | 241 | { |
| 242 | - if(isset($this->knownParams[$name])) { |
|
| 242 | + if (isset($this->knownParams[$name])) { |
|
| 243 | 243 | return $this->knownParams[$name]; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | { |
| 300 | 300 | static $accept; |
| 301 | 301 | |
| 302 | - if(!isset($accept)) { |
|
| 302 | + if (!isset($accept)) { |
|
| 303 | 303 | $accept = new Request_AcceptHeaders(); |
| 304 | 304 | } |
| 305 | 305 | |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | { |
| 319 | 319 | $_REQUEST[$name] = $value; |
| 320 | 320 | |
| 321 | - if(isset($this->knownParams[$name])) { |
|
| 321 | + if (isset($this->knownParams[$name])) { |
|
| 322 | 322 | unset($this->knownParams[$name]); |
| 323 | 323 | } |
| 324 | 324 | |
@@ -352,11 +352,11 @@ discard block |
||
| 352 | 352 | */ |
| 353 | 353 | public function removeParam(string $name) : Request |
| 354 | 354 | { |
| 355 | - if(isset($_REQUEST[$name])) { |
|
| 355 | + if (isset($_REQUEST[$name])) { |
|
| 356 | 356 | unset($_REQUEST[$name]); |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - if(isset($this->knownParams[$name])) { |
|
| 359 | + if (isset($this->knownParams[$name])) { |
|
| 360 | 360 | unset($this->knownParams[$name]); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | public function removeParams(array $names) : Request |
| 373 | 373 | { |
| 374 | - foreach($names as $name) { |
|
| 374 | + foreach ($names as $name) { |
|
| 375 | 375 | $this->removeParam($name); |
| 376 | 376 | } |
| 377 | 377 | |
@@ -387,10 +387,10 @@ discard block |
||
| 387 | 387 | * @param string $name |
| 388 | 388 | * @return bool |
| 389 | 389 | */ |
| 390 | - public function getBool($name, $default=false) |
|
| 390 | + public function getBool($name, $default = false) |
|
| 391 | 391 | { |
| 392 | 392 | $value = $this->getParam($name, $default); |
| 393 | - if(ConvertHelper::isBoolean($value)) { |
|
| 393 | + if (ConvertHelper::isBoolean($value)) { |
|
| 394 | 394 | return ConvertHelper::string2bool($value); |
| 395 | 395 | } |
| 396 | 396 | |
@@ -399,11 +399,11 @@ discard block |
||
| 399 | 399 | |
| 400 | 400 | public function validate() |
| 401 | 401 | { |
| 402 | - foreach($this->knownParams as $param) |
|
| 402 | + foreach ($this->knownParams as $param) |
|
| 403 | 403 | { |
| 404 | 404 | $name = $param->getName(); |
| 405 | 405 | |
| 406 | - if($param->isRequired() && !$this->hasParam($name)) |
|
| 406 | + if ($param->isRequired() && !$this->hasParam($name)) |
|
| 407 | 407 | { |
| 408 | 408 | throw new Request_Exception( |
| 409 | 409 | 'Missing request parameter '.$name, |
@@ -425,10 +425,10 @@ discard block |
||
| 425 | 425 | * @param mixed $default |
| 426 | 426 | * @return string |
| 427 | 427 | */ |
| 428 | - public function getFilteredParam($name, $default=null) |
|
| 428 | + public function getFilteredParam($name, $default = null) |
|
| 429 | 429 | { |
| 430 | 430 | $val = $this->getParam($name, $default); |
| 431 | - if(is_string($val)) { |
|
| 431 | + if (is_string($val)) { |
|
| 432 | 432 | $val = htmlspecialchars(trim(strip_tags($val)), ENT_QUOTES, 'UTF-8'); |
| 433 | 433 | } |
| 434 | 434 | |
@@ -447,24 +447,24 @@ discard block |
||
| 447 | 447 | * @see Request::getJSONAssoc() |
| 448 | 448 | * @see Request::getJSONObject() |
| 449 | 449 | */ |
| 450 | - public function getJSON(string $name, bool $assoc=true) |
|
| 450 | + public function getJSON(string $name, bool $assoc = true) |
|
| 451 | 451 | { |
| 452 | 452 | $value = $this->getParam($name); |
| 453 | 453 | |
| 454 | - if(!empty($value) && is_string($value)) |
|
| 454 | + if (!empty($value) && is_string($value)) |
|
| 455 | 455 | { |
| 456 | 456 | $data = json_decode($value, $assoc); |
| 457 | 457 | |
| 458 | - if($assoc && is_array($data)) { |
|
| 458 | + if ($assoc && is_array($data)) { |
|
| 459 | 459 | return $data; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - if(is_object($data)) { |
|
| 462 | + if (is_object($data)) { |
|
| 463 | 463 | return $data; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - if($assoc) { |
|
| 467 | + if ($assoc) { |
|
| 468 | 468 | return array(); |
| 469 | 469 | } |
| 470 | 470 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | public function getJSONAssoc(string $name) : array |
| 482 | 482 | { |
| 483 | 483 | $result = $this->getJSON($name); |
| 484 | - if(is_array($result)) { |
|
| 484 | + if (is_array($result)) { |
|
| 485 | 485 | return $result; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | public function getJSONObject(string $name) : object |
| 499 | 499 | { |
| 500 | 500 | $result = $this->getJSON($name, false); |
| 501 | - if(is_object($result)) { |
|
| 501 | + if (is_object($result)) { |
|
| 502 | 502 | return $result; |
| 503 | 503 | } |
| 504 | 504 | |
@@ -511,10 +511,10 @@ discard block |
||
| 511 | 511 | * @param array|string $data |
| 512 | 512 | * @param bool $exit Whether to exit the script afterwards. |
| 513 | 513 | */ |
| 514 | - public static function sendJSON($data, bool $exit=true) |
|
| 514 | + public static function sendJSON($data, bool $exit = true) |
|
| 515 | 515 | { |
| 516 | 516 | $payload = $data; |
| 517 | - if(!is_string($payload)) { |
|
| 517 | + if (!is_string($payload)) { |
|
| 518 | 518 | $payload = json_encode($payload); |
| 519 | 519 | } |
| 520 | 520 | |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | |
| 525 | 525 | echo $payload; |
| 526 | 526 | |
| 527 | - if($exit) |
|
| 527 | + if ($exit) |
|
| 528 | 528 | { |
| 529 | 529 | exit; |
| 530 | 530 | } |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | * @param string $html |
| 537 | 537 | * @param bool $exit Whether to exit the script afterwards. |
| 538 | 538 | */ |
| 539 | - public static function sendHTML(string $html, bool $exit=true) |
|
| 539 | + public static function sendHTML(string $html, bool $exit = true) |
|
| 540 | 540 | { |
| 541 | 541 | header('Cache-Control: no-cache, must-revalidate'); |
| 542 | 542 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | echo $html; |
| 546 | 546 | |
| 547 | - if($exit) |
|
| 547 | + if ($exit) |
|
| 548 | 548 | { |
| 549 | 549 | exit; |
| 550 | 550 | } |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
| 561 | 561 | * @return Request_URLComparer |
| 562 | 562 | */ |
| 563 | - public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
|
| 563 | + public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams = array()) : Request_URLComparer |
|
| 564 | 564 | { |
| 565 | 565 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
| 566 | 566 | $comparer->addLimitParams($limitParams); |
@@ -19,9 +19,9 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Request_RefreshParams_Exclude_Name extends Request_RefreshParams_Exclude |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | 25 | private $name; |
| 26 | 26 | |
| 27 | 27 | public function __construct(string $paramName) |
@@ -22,9 +22,9 @@ |
||
| 22 | 22 | { |
| 23 | 23 | const ERROR_INVALID_CALLBACK = 62101; |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var callable |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var callable |
|
| 27 | + */ |
|
| 28 | 28 | private $callback; |
| 29 | 29 | |
| 30 | 30 | public function __construct($callback) |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | public function __construct($callback) |
| 31 | 31 | { |
| 32 | - if(!is_callable($callback)) |
|
| 32 | + if (!is_callable($callback)) |
|
| 33 | 33 | { |
| 34 | 34 | throw new Request_Exception( |
| 35 | 35 | 'Invalid exclusion callback', |
@@ -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 | const ERROR_CURL_INIT_FAILED = 17903; |
| 33 | 33 | 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; |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | return $this->eol; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Sets the timeout for the request, in seconds. If the request |
|
| 117 | - * takes longer, it will be cancelled and an exception triggered. |
|
| 118 | - * |
|
| 119 | - * @param int $seconds |
|
| 120 | - * @return RequestHelper |
|
| 121 | - */ |
|
| 115 | + /** |
|
| 116 | + * Sets the timeout for the request, in seconds. If the request |
|
| 117 | + * takes longer, it will be cancelled and an exception triggered. |
|
| 118 | + * |
|
| 119 | + * @param int $seconds |
|
| 120 | + * @return RequestHelper |
|
| 121 | + */ |
|
| 122 | 122 | public function setTimeout(int $seconds) : RequestHelper |
| 123 | 123 | { |
| 124 | 124 | $this->timeout = $seconds; |
@@ -131,13 +131,13 @@ discard block |
||
| 131 | 131 | return $this->timeout; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Enables verbose logging of the CURL request, which |
|
| 136 | - * is then redirected to the target file. |
|
| 137 | - * |
|
| 138 | - * @param string $targetFile |
|
| 139 | - * @return RequestHelper |
|
| 140 | - */ |
|
| 134 | + /** |
|
| 135 | + * Enables verbose logging of the CURL request, which |
|
| 136 | + * is then redirected to the target file. |
|
| 137 | + * |
|
| 138 | + * @param string $targetFile |
|
| 139 | + * @return RequestHelper |
|
| 140 | + */ |
|
| 141 | 141 | public function enableLogging(string $targetFile) : RequestHelper |
| 142 | 142 | { |
| 143 | 143 | $this->logfile = $targetFile; |
@@ -145,15 +145,15 @@ discard block |
||
| 145 | 145 | return $this; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Adds a file to be sent with the request. |
|
| 150 | - * |
|
| 151 | - * @param string $varName The variable name to send the file in |
|
| 152 | - * @param string $fileName The name of the file as it should be received at the destination |
|
| 153 | - * @param string $content The raw content of the file |
|
| 154 | - * @param string $contentType The content type, use the constants to specify this |
|
| 155 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 156 | - */ |
|
| 148 | + /** |
|
| 149 | + * Adds a file to be sent with the request. |
|
| 150 | + * |
|
| 151 | + * @param string $varName The variable name to send the file in |
|
| 152 | + * @param string $fileName The name of the file as it should be received at the destination |
|
| 153 | + * @param string $content The raw content of the file |
|
| 154 | + * @param string $contentType The content type, use the constants to specify this |
|
| 155 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 156 | + */ |
|
| 157 | 157 | public function addFile(string $varName, string $fileName, string $content, string $contentType = '', string $encoding = '') : RequestHelper |
| 158 | 158 | { |
| 159 | 159 | $this->boundaries->addFile($varName, $fileName, $content, $contentType, $encoding); |
@@ -161,13 +161,13 @@ discard block |
||
| 161 | 161 | return $this; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Adds arbitrary content. |
|
| 166 | - * |
|
| 167 | - * @param string $varName The variable name to send the content in. |
|
| 168 | - * @param string $content |
|
| 169 | - * @param string $contentType |
|
| 170 | - */ |
|
| 164 | + /** |
|
| 165 | + * Adds arbitrary content. |
|
| 166 | + * |
|
| 167 | + * @param string $varName The variable name to send the content in. |
|
| 168 | + * @param string $content |
|
| 169 | + * @param string $contentType |
|
| 170 | + */ |
|
| 171 | 171 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper |
| 172 | 172 | { |
| 173 | 173 | $this->boundaries->addContent($varName, $content, $contentType); |
@@ -175,13 +175,13 @@ discard block |
||
| 175 | 175 | return $this; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Adds a variable to be sent with the request. If it |
|
| 180 | - * already exists, its value is overwritten. |
|
| 181 | - * |
|
| 182 | - * @param string $name |
|
| 183 | - * @param string $value |
|
| 184 | - */ |
|
| 178 | + /** |
|
| 179 | + * Adds a variable to be sent with the request. If it |
|
| 180 | + * already exists, its value is overwritten. |
|
| 181 | + * |
|
| 182 | + * @param string $name |
|
| 183 | + * @param string $value |
|
| 184 | + */ |
|
| 185 | 185 | public function addVariable(string $name, string $value) : RequestHelper |
| 186 | 186 | { |
| 187 | 187 | $this->boundaries->addVariable($name, $value); |
@@ -189,13 +189,13 @@ discard block |
||
| 189 | 189 | return $this; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Sets an HTTP header to include in the request. |
|
| 194 | - * |
|
| 195 | - * @param string $name |
|
| 196 | - * @param string $value |
|
| 197 | - * @return RequestHelper |
|
| 198 | - */ |
|
| 192 | + /** |
|
| 193 | + * Sets an HTTP header to include in the request. |
|
| 194 | + * |
|
| 195 | + * @param string $name |
|
| 196 | + * @param string $value |
|
| 197 | + * @return RequestHelper |
|
| 198 | + */ |
|
| 199 | 199 | public function setHeader(string $name, string $value) : RequestHelper |
| 200 | 200 | { |
| 201 | 201 | $this->headers[$name] = $value; |
@@ -203,36 +203,36 @@ discard block |
||
| 203 | 203 | return $this; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Disables SSL certificate checking. |
|
| 208 | - * |
|
| 209 | - * @return RequestHelper |
|
| 210 | - */ |
|
| 206 | + /** |
|
| 207 | + * Disables SSL certificate checking. |
|
| 208 | + * |
|
| 209 | + * @return RequestHelper |
|
| 210 | + */ |
|
| 211 | 211 | public function disableSSLChecks() : RequestHelper |
| 212 | 212 | { |
| 213 | 213 | $this->verifySSL = false; |
| 214 | 214 | return $this; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * @var integer |
|
| 219 | - */ |
|
| 217 | + /** |
|
| 218 | + * @var integer |
|
| 219 | + */ |
|
| 220 | 220 | protected $contentLength = 0; |
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Sends the POST request to the destination, and returns |
|
| 224 | - * the response text. |
|
| 225 | - * |
|
| 226 | - * The response object is stored internally, so after calling |
|
| 227 | - * this method it may be retrieved at any moment using the |
|
| 228 | - * {@link getResponse()} method. |
|
| 229 | - * |
|
| 230 | - * @return string |
|
| 231 | - * @see RequestHelper::getResponse() |
|
| 232 | - * @throws RequestHelper_Exception |
|
| 233 | - * |
|
| 234 | - * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 235 | - */ |
|
| 222 | + /** |
|
| 223 | + * Sends the POST request to the destination, and returns |
|
| 224 | + * the response text. |
|
| 225 | + * |
|
| 226 | + * The response object is stored internally, so after calling |
|
| 227 | + * this method it may be retrieved at any moment using the |
|
| 228 | + * {@link getResponse()} method. |
|
| 229 | + * |
|
| 230 | + * @return string |
|
| 231 | + * @see RequestHelper::getResponse() |
|
| 232 | + * @throws RequestHelper_Exception |
|
| 233 | + * |
|
| 234 | + * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 235 | + */ |
|
| 236 | 236 | public function send() : string |
| 237 | 237 | { |
| 238 | 238 | $info = parseURL($this->destination); |
@@ -272,26 +272,26 @@ discard block |
||
| 272 | 272 | return $this->response->getResponseBody(); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Retrieves the request's body content. This is an alias |
|
| 277 | - * for {@see RequestHelper::getMimeBody()}. |
|
| 278 | - * |
|
| 279 | - * @return string |
|
| 280 | - * @see RequestHelper::getMimeBody() |
|
| 281 | - */ |
|
| 275 | + /** |
|
| 276 | + * Retrieves the request's body content. This is an alias |
|
| 277 | + * for {@see RequestHelper::getMimeBody()}. |
|
| 278 | + * |
|
| 279 | + * @return string |
|
| 280 | + * @see RequestHelper::getMimeBody() |
|
| 281 | + */ |
|
| 282 | 282 | public function getBody() : string |
| 283 | 283 | { |
| 284 | 284 | return $this->getMimeBody(); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * Creates a new CURL resource configured according to the |
|
| 289 | - * request's settings. |
|
| 290 | - * |
|
| 291 | - * @param URLInfo $url |
|
| 292 | - * @throws RequestHelper_Exception |
|
| 293 | - * @return resource |
|
| 294 | - */ |
|
| 287 | + /** |
|
| 288 | + * Creates a new CURL resource configured according to the |
|
| 289 | + * request's settings. |
|
| 290 | + * |
|
| 291 | + * @param URLInfo $url |
|
| 292 | + * @throws RequestHelper_Exception |
|
| 293 | + * @return resource |
|
| 294 | + */ |
|
| 295 | 295 | protected function createCURL(URLInfo $url) |
| 296 | 296 | { |
| 297 | 297 | $ch = curl_init(); |
@@ -339,10 +339,10 @@ discard block |
||
| 339 | 339 | return $ch; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * @param resource $ch |
|
| 344 | - * @return bool Whether logging is enabled. |
|
| 345 | - */ |
|
| 342 | + /** |
|
| 343 | + * @param resource $ch |
|
| 344 | + * @return bool Whether logging is enabled. |
|
| 345 | + */ |
|
| 346 | 346 | protected function configureLogging($ch) : bool |
| 347 | 347 | { |
| 348 | 348 | if(empty($this->logfile)) |
@@ -369,13 +369,13 @@ discard block |
||
| 369 | 369 | return true; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - /** |
|
| 373 | - * Compiles the associative headers array into |
|
| 374 | - * the format understood by CURL, namely an indexed |
|
| 375 | - * array with one header string per entry. |
|
| 376 | - * |
|
| 377 | - * @return array |
|
| 378 | - */ |
|
| 372 | + /** |
|
| 373 | + * Compiles the associative headers array into |
|
| 374 | + * the format understood by CURL, namely an indexed |
|
| 375 | + * array with one header string per entry. |
|
| 376 | + * |
|
| 377 | + * @return array |
|
| 378 | + */ |
|
| 379 | 379 | protected function renderHeaders() : array |
| 380 | 380 | { |
| 381 | 381 | $result = array(); |
@@ -389,12 +389,12 @@ discard block |
||
| 389 | 389 | return $result; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - /** |
|
| 393 | - * Retrieves the raw response header, in the form of an indexed |
|
| 394 | - * array containing all response header lines. |
|
| 395 | - * |
|
| 396 | - * @return array |
|
| 397 | - */ |
|
| 392 | + /** |
|
| 393 | + * Retrieves the raw response header, in the form of an indexed |
|
| 394 | + * array containing all response header lines. |
|
| 395 | + * |
|
| 396 | + * @return array |
|
| 397 | + */ |
|
| 398 | 398 | public function getResponseHeader() : array |
| 399 | 399 | { |
| 400 | 400 | $response = $this->getResponse(); |
@@ -406,33 +406,33 @@ discard block |
||
| 406 | 406 | return array(); |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - /** |
|
| 410 | - * After calling the {@link send()} method, this may be used to |
|
| 411 | - * retrieve the response text from the POST request. |
|
| 412 | - * |
|
| 413 | - * @return RequestHelper_Response|NULL |
|
| 414 | - */ |
|
| 409 | + /** |
|
| 410 | + * After calling the {@link send()} method, this may be used to |
|
| 411 | + * retrieve the response text from the POST request. |
|
| 412 | + * |
|
| 413 | + * @return RequestHelper_Response|NULL |
|
| 414 | + */ |
|
| 415 | 415 | public function getResponse() : ?RequestHelper_Response |
| 416 | 416 | { |
| 417 | 417 | return $this->response; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - /** |
|
| 421 | - * Retrieves all headers set until now. |
|
| 422 | - * |
|
| 423 | - * @return array<string,string> |
|
| 424 | - */ |
|
| 420 | + /** |
|
| 421 | + * Retrieves all headers set until now. |
|
| 422 | + * |
|
| 423 | + * @return array<string,string> |
|
| 424 | + */ |
|
| 425 | 425 | public function getHeaders() : array |
| 426 | 426 | { |
| 427 | 427 | return $this->headers; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - /** |
|
| 431 | - * Retrieves the value of a header by its name. |
|
| 432 | - * |
|
| 433 | - * @param string $name |
|
| 434 | - * @return string The header value, or an empty string if not set. |
|
| 435 | - */ |
|
| 430 | + /** |
|
| 431 | + * Retrieves the value of a header by its name. |
|
| 432 | + * |
|
| 433 | + * @param string $name |
|
| 434 | + * @return string The header value, or an empty string if not set. |
|
| 435 | + */ |
|
| 436 | 436 | public function getHeader(string $name) : string |
| 437 | 437 | { |
| 438 | 438 | if(isset($this->headers[$name])) |
@@ -25,17 +25,17 @@ |
||
| 25 | 25 | * |
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | - function render() : string; |
|
| 28 | + function render() : string; |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Converts the string builder to a string. |
| 32 | 32 | * |
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | - function __toString(); |
|
| 35 | + function __toString(); |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Renders the string and echos it. |
| 39 | 39 | */ |
| 40 | - function display() : void; |
|
| 40 | + function display() : void; |
|
| 41 | 41 | } |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | 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(); |
@@ -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 | |
@@ -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|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|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); |
@@ -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; |