@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | * Set $header with a $value. If value is null, only $header will be used |
| 58 | 58 | * |
| 59 | 59 | * @param string $header Header name |
| 60 | - * @param mixed $value Header value (if not included in $header) |
|
| 61 | - * @return Object $this |
|
| 60 | + * @param string $value Header value (if not included in $header) |
|
| 61 | + * @return Header $this |
|
| 62 | 62 | */ |
| 63 | 63 | final public function set($header, $value=null) { |
| 64 | 64 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | /** |
| 87 | 87 | * Free recorded headers (re-init array) |
| 88 | 88 | * |
| 89 | - * @return Object $this |
|
| 89 | + * @return Header $this |
|
| 90 | 90 | */ |
| 91 | 91 | final public function free() { |
| 92 | 92 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * Shortcut to set client cache headers |
| 232 | 232 | * |
| 233 | 233 | * @param integer $ttl Cache time to live |
| 234 | - * @return Object $this |
|
| 234 | + * @return Header $this |
|
| 235 | 235 | */ |
| 236 | 236 | public function setClientCache($ttl) { |
| 237 | 237 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | * |
| 256 | 256 | * @param string $type Content type |
| 257 | 257 | * @param string $charset Charset |
| 258 | - * @return Object $this |
|
| 258 | + * @return Header $this |
|
| 259 | 259 | */ |
| 260 | 260 | public function setContentType($type, $charset=null) { |
| 261 | 261 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param string $time Dispatcher time |
| 49 | 49 | */ |
| 50 | - final public function __construct($time=false) { |
|
| 50 | + final public function __construct($time = false) { |
|
| 51 | 51 | |
| 52 | 52 | $this->current_time = $time !== false ? $time : microtime(true); |
| 53 | 53 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param mixed $value Header value (if not included in $header) |
| 61 | 61 | * @return Object $this |
| 62 | 62 | */ |
| 63 | - final public function set($header, $value=null) { |
|
| 63 | + final public function set($header, $value = null) { |
|
| 64 | 64 | |
| 65 | 65 | $this->headers[$header] = $value; |
| 66 | 66 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | final public function get($header) { |
| 79 | 79 | |
| 80 | - if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; |
|
| 80 | + if (array_key_exists($header, $this->headers)) return $this->headers[$header]; |
|
| 81 | 81 | |
| 82 | 82 | else return null; |
| 83 | 83 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param integer $contentLength Content length |
| 114 | 114 | * @param string $value (optional) value (see method description) |
| 115 | 115 | */ |
| 116 | - final public function compose($status, $contentLength=0, $value=false) { |
|
| 116 | + final public function compose($status, $contentLength = 0, $value = false) { |
|
| 117 | 117 | |
| 118 | 118 | switch ($status) { |
| 119 | 119 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | header($_SERVER["SERVER_PROTOCOL"].' 204 No Content'); |
| 147 | 147 | header('Status: 204 No Content'); |
| 148 | - header('Content-Length: 0',true); |
|
| 148 | + header('Content-Length: 0', true); |
|
| 149 | 149 | |
| 150 | 150 | $this->processExtraHeaders($this->headers); |
| 151 | 151 | |
@@ -157,13 +157,13 @@ discard block |
||
| 157 | 157 | case 303: //See Other |
| 158 | 158 | case 307: //Temporary Redirect |
| 159 | 159 | |
| 160 | - header("Location: ".$value,true,$status); |
|
| 160 | + header("Location: ".$value, true, $status); |
|
| 161 | 161 | |
| 162 | 162 | break; |
| 163 | 163 | |
| 164 | 164 | case 304: //Not Modified |
| 165 | 165 | |
| 166 | - if ( $value === false ) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
|
| 166 | + if ($value === false) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
|
| 167 | 167 | else header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304); |
| 168 | 168 | |
| 169 | 169 | if ($contentLength !== 0) header('Content-Length: '.$contentLength); //is it needed? |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | case 405: //Not allowed |
| 199 | 199 | |
| 200 | - header('Allow: ' . $value, true, 405); |
|
| 200 | + header('Allow: '.$value, true, 405); |
|
| 201 | 201 | |
| 202 | 202 | break; |
| 203 | 203 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | case 501: //Not implemented |
| 211 | 211 | |
| 212 | - header('Allow: ' . $value, true, 501); |
|
| 212 | + header('Allow: '.$value, true, 501); |
|
| 213 | 213 | |
| 214 | 214 | break; |
| 215 | 215 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
| 219 | 219 | header('Status: 503 Service Temporarily Unavailable'); |
| 220 | - if ( $value !== false AND @is_int($value) ) { |
|
| 220 | + if ($value !== false AND @is_int($value)) { |
|
| 221 | 221 | header('Retry-After: '.$value); |
| 222 | 222 | } |
| 223 | 223 | |
@@ -237,13 +237,13 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | $ttl = filter_var($ttl, FILTER_VALIDATE_INT); |
| 239 | 239 | |
| 240 | - if ( $ttl > 0 ) { |
|
| 241 | - $this->set("Cache-Control","max-age=".$ttl.", must-revalidate"); |
|
| 242 | - $this->set("Expires",gmdate("D, d M Y H:i:s", (int)$this->current_time + $ttl)." GMT"); |
|
| 240 | + if ($ttl > 0) { |
|
| 241 | + $this->set("Cache-Control", "max-age=".$ttl.", must-revalidate"); |
|
| 242 | + $this->set("Expires", gmdate("D, d M Y H:i:s", (int)$this->current_time+$ttl)." GMT"); |
|
| 243 | 243 | } |
| 244 | 244 | else { |
| 245 | - $this->set("Cache-Control","no-cache, must-revalidate"); |
|
| 246 | - $this->set("Expires","Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 245 | + $this->set("Cache-Control", "no-cache, must-revalidate"); |
|
| 246 | + $this->set("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | return $this; |
@@ -257,11 +257,11 @@ discard block |
||
| 257 | 257 | * @param string $charset Charset |
| 258 | 258 | * @return Object $this |
| 259 | 259 | */ |
| 260 | - public function setContentType($type, $charset=null) { |
|
| 260 | + public function setContentType($type, $charset = null) { |
|
| 261 | 261 | |
| 262 | 262 | |
| 263 | - if ( is_null($charset) ) $this->set("Content-type",strtolower($type)); |
|
| 264 | - else $this->set("Content-type",strtolower($type)."; charset=".$charset); |
|
| 263 | + if (is_null($charset)) $this->set("Content-type", strtolower($type)); |
|
| 264 | + else $this->set("Content-type", strtolower($type)."; charset=".$charset); |
|
| 265 | 265 | |
| 266 | 266 | return $this; |
| 267 | 267 | |
@@ -298,9 +298,9 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | private function processExtraHeaders($headers) { |
| 300 | 300 | |
| 301 | - foreach ( $headers as $header => $value ) { |
|
| 301 | + foreach ($headers as $header => $value) { |
|
| 302 | 302 | |
| 303 | - if ( is_null($value) ) header($header, true); |
|
| 303 | + if (is_null($value)) header($header, true); |
|
| 304 | 304 | else header($header.": ".$value, true); |
| 305 | 305 | |
| 306 | 306 | } |
@@ -77,9 +77,11 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | final public function get($header) { |
| 79 | 79 | |
| 80 | - if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; |
|
| 81 | - |
|
| 82 | - else return null; |
|
| 80 | + if ( array_key_exists($header, $this->headers) ) { |
|
| 81 | + return $this->headers[$header]; |
|
| 82 | + } else { |
|
| 83 | + return null; |
|
| 84 | + } |
|
| 83 | 85 | |
| 84 | 86 | } |
| 85 | 87 | |
@@ -163,10 +165,16 @@ discard block |
||
| 163 | 165 | |
| 164 | 166 | case 304: //Not Modified |
| 165 | 167 | |
| 166 | - if ( $value === false ) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
|
| 167 | - else header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304); |
|
| 168 | + if ( $value === false ) { |
|
| 169 | + header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
|
| 170 | + } else { |
|
| 171 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304); |
|
| 172 | + } |
|
| 168 | 173 | |
| 169 | - if ($contentLength !== 0) header('Content-Length: '.$contentLength); //is it needed? |
|
| 174 | + if ($contentLength !== 0) { |
|
| 175 | + header('Content-Length: '.$contentLength); |
|
| 176 | + } |
|
| 177 | + //is it needed? |
|
| 170 | 178 | |
| 171 | 179 | $this->processExtraHeaders($this->headers); |
| 172 | 180 | |
@@ -240,8 +248,7 @@ discard block |
||
| 240 | 248 | if ( $ttl > 0 ) { |
| 241 | 249 | $this->set("Cache-Control","max-age=".$ttl.", must-revalidate"); |
| 242 | 250 | $this->set("Expires",gmdate("D, d M Y H:i:s", (int)$this->current_time + $ttl)." GMT"); |
| 243 | - } |
|
| 244 | - else { |
|
| 251 | + } else { |
|
| 245 | 252 | $this->set("Cache-Control","no-cache, must-revalidate"); |
| 246 | 253 | $this->set("Expires","Mon, 26 Jul 1997 05:00:00 GMT"); |
| 247 | 254 | } |
@@ -260,8 +267,11 @@ discard block |
||
| 260 | 267 | public function setContentType($type, $charset=null) { |
| 261 | 268 | |
| 262 | 269 | |
| 263 | - if ( is_null($charset) ) $this->set("Content-type",strtolower($type)); |
|
| 264 | - else $this->set("Content-type",strtolower($type)."; charset=".$charset); |
|
| 270 | + if ( is_null($charset) ) { |
|
| 271 | + $this->set("Content-type",strtolower($type)); |
|
| 272 | + } else { |
|
| 273 | + $this->set("Content-type",strtolower($type)."; charset=".$charset); |
|
| 274 | + } |
|
| 265 | 275 | |
| 266 | 276 | return $this; |
| 267 | 277 | |
@@ -276,13 +286,15 @@ discard block |
||
| 276 | 286 | |
| 277 | 287 | $headers = ''; |
| 278 | 288 | |
| 279 | - if (function_exists('getallheaders')) $headers = getallheaders(); |
|
| 280 | - |
|
| 281 | - else { |
|
| 289 | + if (function_exists('getallheaders')) { |
|
| 290 | + $headers = getallheaders(); |
|
| 291 | + } else { |
|
| 282 | 292 | |
| 283 | 293 | foreach ($_SERVER as $name => $value) { |
| 284 | 294 | |
| 285 | - if (substr($name, 0, 5) == 'HTTP_') $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
| 295 | + if (substr($name, 0, 5) == 'HTTP_') { |
|
| 296 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
| 297 | + } |
|
| 286 | 298 | } |
| 287 | 299 | |
| 288 | 300 | } |
@@ -300,8 +312,11 @@ discard block |
||
| 300 | 312 | |
| 301 | 313 | foreach ( $headers as $header => $value ) { |
| 302 | 314 | |
| 303 | - if ( is_null($value) ) header($header, true); |
|
| 304 | - else header($header.": ".$value, true); |
|
| 315 | + if ( is_null($value) ) { |
|
| 316 | + header($header, true); |
|
| 317 | + } else { |
|
| 318 | + header($header.": ".$value, true); |
|
| 319 | + } |
|
| 305 | 320 | |
| 306 | 321 | } |
| 307 | 322 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @param string $service The service name |
| 62 | 62 | * |
| 63 | - * @return Object $this |
|
| 63 | + * @return ObjectRoute $this |
|
| 64 | 64 | */ |
| 65 | 65 | public function setService($service) { |
| 66 | 66 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @param string $type |
| 87 | 87 | * |
| 88 | - * @return Object $this |
|
| 88 | + * @return ObjectRoute $this |
|
| 89 | 89 | */ |
| 90 | 90 | public function setType($type) { |
| 91 | 91 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @param string $target |
| 115 | 115 | * |
| 116 | - * @return Object $this |
|
| 116 | + * @return ObjectRoute $this |
|
| 117 | 117 | */ |
| 118 | 118 | public function setTarget($target) { |
| 119 | 119 | |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @param string $header Header name |
| 240 | 240 | * @param string $value Header content (optional) |
| 241 | 241 | * |
| 242 | - * @return ObjectRequest $this |
|
| 242 | + * @return ObjectRoute $this |
|
| 243 | 243 | */ |
| 244 | 244 | public function setHeader($header, $value=null) { |
| 245 | 245 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * |
| 291 | 291 | * @param array $headers Headers array |
| 292 | 292 | * |
| 293 | - * @return ObjectRequest $this |
|
| 293 | + * @return ObjectRoute $this |
|
| 294 | 294 | */ |
| 295 | 295 | public function setHeaders($headers) { |
| 296 | 296 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | /** |
| 304 | 304 | * Unset headers |
| 305 | 305 | * |
| 306 | - * @return ObjectRequest $this |
|
| 306 | + * @return ObjectRoute $this |
|
| 307 | 307 | */ |
| 308 | 308 | public function unsetHeaders() { |
| 309 | 309 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | /** |
| 328 | 328 | * Set extra parameter |
| 329 | 329 | * |
| 330 | - * @return ObjectRequest $this |
|
| 330 | + * @return ObjectRoute $this |
|
| 331 | 331 | */ |
| 332 | 332 | public function setParameter($parameter, $value=null) { |
| 333 | 333 | |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | private $parameters = array(); |
| 49 | 49 | |
| 50 | - private $supported_route_types = array("ROUTE","REDIRECT","ERROR"); |
|
| 50 | + private $supported_route_types = array("ROUTE", "REDIRECT", "ERROR"); |
|
| 51 | 51 | |
| 52 | - private $supported_redirect_codes = array(201,301,302,303,307); |
|
| 52 | + private $supported_redirect_codes = array(201, 301, 302, 303, 307); |
|
| 53 | 53 | |
| 54 | - private $supported_error_codes = array(400,403,404,405,500,501,503); |
|
| 54 | + private $supported_error_codes = array(400, 403, 404, 405, 500, 501, 503); |
|
| 55 | 55 | |
| 56 | - private $supported_cache_modes = array("SERVER","CLIENT","BOTH"); |
|
| 56 | + private $supported_cache_modes = array("SERVER", "CLIENT", "BOTH"); |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Set service name |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * |
| 242 | 242 | * @return ObjectRequest $this |
| 243 | 243 | */ |
| 244 | - public function setHeader($header, $value=null) { |
|
| 244 | + public function setHeader($header, $value = null) { |
|
| 245 | 245 | |
| 246 | 246 | $this->headers[$header] = $value; |
| 247 | 247 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function unsetHeader($header) { |
| 260 | 260 | |
| 261 | - if ( isset($this->headers[$header]) ) { |
|
| 261 | + if (isset($this->headers[$header])) { |
|
| 262 | 262 | |
| 263 | 263 | unset($this->headers[$header]); |
| 264 | 264 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | public function getHeader($header) { |
| 281 | 281 | |
| 282 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 282 | + if (isset($this->headers[$header])) return $this->headers[$header]; |
|
| 283 | 283 | |
| 284 | 284 | return null; |
| 285 | 285 | |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @return ObjectRequest $this |
| 331 | 331 | */ |
| 332 | - public function setParameter($parameter, $value=null) { |
|
| 332 | + public function setParameter($parameter, $value = null) { |
|
| 333 | 333 | |
| 334 | 334 | $this->parameters[$parameter] = $value; |
| 335 | 335 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | public function getParameter($parameter) { |
| 346 | 346 | |
| 347 | - if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter]; |
|
| 347 | + if (isset($this->parameters[$parameter])) return $this->parameters[$parameter]; |
|
| 348 | 348 | |
| 349 | 349 | else return null; |
| 350 | 350 | |
@@ -186,8 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | $this->cache = false; |
| 188 | 188 | |
| 189 | - } |
|
| 190 | - else { |
|
| 189 | + } else { |
|
| 191 | 190 | |
| 192 | 191 | $cache = strtoupper($cache); |
| 193 | 192 | |
@@ -279,7 +278,9 @@ discard block |
||
| 279 | 278 | */ |
| 280 | 279 | public function getHeader($header) { |
| 281 | 280 | |
| 282 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 281 | + if ( isset($this->headers[$header]) ) { |
|
| 282 | + return $this->headers[$header]; |
|
| 283 | + } |
|
| 283 | 284 | |
| 284 | 285 | return null; |
| 285 | 286 | |
@@ -344,9 +345,11 @@ discard block |
||
| 344 | 345 | */ |
| 345 | 346 | public function getParameter($parameter) { |
| 346 | 347 | |
| 347 | - if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter]; |
|
| 348 | - |
|
| 349 | - else return null; |
|
| 348 | + if ( isset($this->parameters[$parameter]) ) { |
|
| 349 | + return $this->parameters[$parameter]; |
|
| 350 | + } else { |
|
| 351 | + return null; |
|
| 352 | + } |
|
| 350 | 353 | |
| 351 | 354 | } |
| 352 | 355 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @param array $attributes array og attributes that service expects |
| 261 | 261 | * @param array $parameters array of parameters that service expects |
| 262 | 262 | * |
| 263 | - * @return Object $this |
|
| 263 | + * @return Service $this |
|
| 264 | 264 | */ |
| 265 | 265 | final public function expects($method, $attributes, $parameters=array()) { |
| 266 | 266 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @param array $attributes array og attributes that service likes |
| 281 | 281 | * @param array $parameters array of parameters that service likes |
| 282 | 282 | * |
| 283 | - * @return Object $this |
|
| 283 | + * @return Service $this |
|
| 284 | 284 | */ |
| 285 | 285 | final public function likes($method, $attributes, $parameters=array()) { |
| 286 | 286 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * |
| 307 | 307 | * @param string $methods HTTP methods, comma separated |
| 308 | 308 | * |
| 309 | - * @return Object $this |
|
| 309 | + * @return Service $this |
|
| 310 | 310 | */ |
| 311 | 311 | final public function setSupportedMethods($methods) { |
| 312 | 312 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * Set service content type |
| 332 | 332 | * |
| 333 | 333 | * @param string $type Content Type |
| 334 | - * @return Object $this |
|
| 334 | + * @return Service $this |
|
| 335 | 335 | */ |
| 336 | 336 | final public function setContentType($type) { |
| 337 | 337 | |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | * |
| 358 | 358 | * @param string $charset Charset |
| 359 | 359 | * |
| 360 | - * @return Object $this |
|
| 360 | + * @return Service $this |
|
| 361 | 361 | */ |
| 362 | 362 | final public function setCharset($charset) { |
| 363 | 363 | |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | * Set success status code |
| 383 | 383 | * |
| 384 | 384 | * @param integer $code HTTP status code (in case of success) |
| 385 | - * @return Object $this |
|
| 385 | + * @return Service $this |
|
| 386 | 386 | */ |
| 387 | 387 | final public function setStatusCode($code) { |
| 388 | 388 | |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | * @param string $header Header name |
| 434 | 434 | * @param string $value Header content (optional) |
| 435 | 435 | * |
| 436 | - * @return Object $this |
|
| 436 | + * @return Service $this |
|
| 437 | 437 | */ |
| 438 | 438 | final public function setHeader($header, $value=null) { |
| 439 | 439 | |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | * |
| 485 | 485 | * @param array $headers Headers array |
| 486 | 486 | * |
| 487 | - * @return Object $this |
|
| 487 | + * @return Service $this |
|
| 488 | 488 | */ |
| 489 | 489 | final public function setHeaders($headers) { |
| 490 | 490 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | /** |
| 498 | 498 | * Unset headers |
| 499 | 499 | * |
| 500 | - * @return Object $this |
|
| 500 | + * @return Service $this |
|
| 501 | 501 | */ |
| 502 | 502 | final public function unsetHeaders() { |
| 503 | 503 | |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | /** |
| 522 | 522 | * Get service-supported HTTP methods |
| 523 | 523 | * |
| 524 | - * @return array Headers array |
|
| 524 | + * @return string Headers array |
|
| 525 | 525 | */ |
| 526 | 526 | final public function getSupportedMethods() { |
| 527 | 527 | |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | /** |
| 556 | 556 | * Return the callable class method that reflect the requested one |
| 557 | 557 | * |
| 558 | - * @return array Headers array |
|
| 558 | + * @return string Headers array |
|
| 559 | 559 | */ |
| 560 | 560 | final public function getCallableMethod($method) { |
| 561 | 561 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @var array |
| 155 | 155 | */ |
| 156 | - private $supported_success_codes = array(200,202,204); |
|
| 156 | + private $supported_success_codes = array(200, 202, 204); |
|
| 157 | 157 | |
| 158 | 158 | /*************** HTTP METHODS IMPLEMENTATIONS **************/ |
| 159 | 159 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | * @return Object $this |
| 250 | 250 | */ |
| 251 | - final public function expects($method, $attributes, $parameters=array()) { |
|
| 251 | + final public function expects($method, $attributes, $parameters = array()) { |
|
| 252 | 252 | |
| 253 | 253 | $method = strtoupper($method); |
| 254 | 254 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return Object $this |
| 270 | 270 | */ |
| 271 | - final public function likes($method, $attributes, $parameters=array()) { |
|
| 271 | + final public function likes($method, $attributes, $parameters = array()) { |
|
| 272 | 272 | |
| 273 | 273 | $method = strtoupper($method); |
| 274 | 274 | |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | * |
| 422 | 422 | * @return Object $this |
| 423 | 423 | */ |
| 424 | - final public function setHeader($header, $value=null) { |
|
| 424 | + final public function setHeader($header, $value = null) { |
|
| 425 | 425 | |
| 426 | 426 | $this->headers[$header] = $value; |
| 427 | 427 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | */ |
| 439 | 439 | final public function unsetHeader($header) { |
| 440 | 440 | |
| 441 | - if ( isset($this->headers[$header]) ) { |
|
| 441 | + if (isset($this->headers[$header])) { |
|
| 442 | 442 | |
| 443 | 443 | unset($this->headers[$header]); |
| 444 | 444 | |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | */ |
| 460 | 460 | final public function getHeader($header) { |
| 461 | 461 | |
| 462 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 462 | + if (isset($this->headers[$header])) return $this->headers[$header]; |
|
| 463 | 463 | |
| 464 | 464 | return null; |
| 465 | 465 | |
@@ -522,15 +522,15 @@ discard block |
||
| 522 | 522 | */ |
| 523 | 523 | final public function getImplementedMethods() { |
| 524 | 524 | |
| 525 | - if ( method_exists($this, 'any') ) return explode(",",$this->supported_http_methods); |
|
| 525 | + if (method_exists($this, 'any')) return explode(",", $this->supported_http_methods); |
|
| 526 | 526 | |
| 527 | - $supported_methods = explode(',',$this->supported_http_methods); |
|
| 527 | + $supported_methods = explode(',', $this->supported_http_methods); |
|
| 528 | 528 | |
| 529 | 529 | $implemented_methods = array(); |
| 530 | 530 | |
| 531 | - foreach ( $supported_methods as $method ) { |
|
| 531 | + foreach ($supported_methods as $method) { |
|
| 532 | 532 | |
| 533 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method); |
|
| 533 | + if (method_exists($this, strtolower($method))) array_push($implemented_methods, $method); |
|
| 534 | 534 | |
| 535 | 535 | } |
| 536 | 536 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | final public function getCallableMethod($method) { |
| 547 | 547 | |
| 548 | - if ( method_exists($this, strtolower($method)) ) return strtolower($method); |
|
| 548 | + if (method_exists($this, strtolower($method))) return strtolower($method); |
|
| 549 | 549 | |
| 550 | 550 | else return "any"; |
| 551 | 551 | |
@@ -562,9 +562,9 @@ discard block |
||
| 562 | 562 | |
| 563 | 563 | return array( |
| 564 | 564 | |
| 565 | - ( sizeof($this->expected_attributes[$method]) == 0 AND sizeof($this->expected_attributes["ANY"]) != 0 ) ? $this->expected_attributes["ANY"] : $this->expected_attributes[$method], |
|
| 565 | + (sizeof($this->expected_attributes[$method]) == 0 AND sizeof($this->expected_attributes["ANY"]) != 0) ? $this->expected_attributes["ANY"] : $this->expected_attributes[$method], |
|
| 566 | 566 | |
| 567 | - ( sizeof($this->expected_parameters[$method]) == 0 AND sizeof($this->expected_parameters["ANY"]) != 0 ) ? $this->expected_parameters["ANY"] : $this->expected_parameters[$method] |
|
| 567 | + (sizeof($this->expected_parameters[$method]) == 0 AND sizeof($this->expected_parameters["ANY"]) != 0) ? $this->expected_parameters["ANY"] : $this->expected_parameters[$method] |
|
| 568 | 568 | |
| 569 | 569 | ); |
| 570 | 570 | |
@@ -581,9 +581,9 @@ discard block |
||
| 581 | 581 | |
| 582 | 582 | return array( |
| 583 | 583 | |
| 584 | - ( sizeof($this->liked_attributes[$method]) == 0 AND sizeof($this->liked_attributes["ANY"]) != 0 ) ? $this->liked_attributes["ANY"] : $this->liked_attributes[$method], |
|
| 584 | + (sizeof($this->liked_attributes[$method]) == 0 AND sizeof($this->liked_attributes["ANY"]) != 0) ? $this->liked_attributes["ANY"] : $this->liked_attributes[$method], |
|
| 585 | 585 | |
| 586 | - ( sizeof($this->liked_parameters[$method]) == 0 AND sizeof($this->liked_parameters["ANY"]) != 0 ) ? $this->liked_parameters["ANY"] : $this->liked_parameters[$method] |
|
| 586 | + (sizeof($this->liked_parameters[$method]) == 0 AND sizeof($this->liked_parameters["ANY"]) != 0) ? $this->liked_parameters["ANY"] : $this->liked_parameters[$method] |
|
| 587 | 587 | |
| 588 | 588 | ); |
| 589 | 589 | |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | */ |
| 620 | 620 | final public function getAttribute($attribute) { |
| 621 | 621 | |
| 622 | - if ( isset($this->attributes[$attribute]) ) return $this->attributes[$attribute]; |
|
| 622 | + if (isset($this->attributes[$attribute])) return $this->attributes[$attribute]; |
|
| 623 | 623 | |
| 624 | 624 | return null; |
| 625 | 625 | |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | * |
| 651 | 651 | * @return array |
| 652 | 652 | */ |
| 653 | - final public function getParameters($raw=false) { |
|
| 653 | + final public function getParameters($raw = false) { |
|
| 654 | 654 | |
| 655 | 655 | return $raw ? $this->raw_parameters : $this->parameters; |
| 656 | 656 | |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | */ |
| 666 | 666 | final public function getParameter($parameter) { |
| 667 | 667 | |
| 668 | - if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter]; |
|
| 668 | + if (isset($this->parameters[$parameter])) return $this->parameters[$parameter]; |
|
| 669 | 669 | |
| 670 | 670 | return null; |
| 671 | 671 | |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | */ |
| 691 | 691 | final public function getRequestHeader($header) { |
| 692 | 692 | |
| 693 | - if ( isset($this->request_headers[$header]) ) return $this->request_headers[$header]; |
|
| 693 | + if (isset($this->request_headers[$header])) return $this->request_headers[$header]; |
|
| 694 | 694 | |
| 695 | 695 | return null; |
| 696 | 696 | |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | |
| 709 | 709 | private function methodsToArray() { |
| 710 | 710 | |
| 711 | - $methods = explode(",",$this->supported_http_methods); |
|
| 711 | + $methods = explode(",", $this->supported_http_methods); |
|
| 712 | 712 | |
| 713 | 713 | $methods_array = array(); |
| 714 | 714 | |
@@ -459,7 +459,9 @@ discard block |
||
| 459 | 459 | */ |
| 460 | 460 | final public function getHeader($header) { |
| 461 | 461 | |
| 462 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 462 | + if ( isset($this->headers[$header]) ) { |
|
| 463 | + return $this->headers[$header]; |
|
| 464 | + } |
|
| 463 | 465 | |
| 464 | 466 | return null; |
| 465 | 467 | |
@@ -522,7 +524,9 @@ discard block |
||
| 522 | 524 | */ |
| 523 | 525 | final public function getImplementedMethods() { |
| 524 | 526 | |
| 525 | - if ( method_exists($this, 'any') ) return explode(",",$this->supported_http_methods); |
|
| 527 | + if ( method_exists($this, 'any') ) { |
|
| 528 | + return explode(",",$this->supported_http_methods); |
|
| 529 | + } |
|
| 526 | 530 | |
| 527 | 531 | $supported_methods = explode(',',$this->supported_http_methods); |
| 528 | 532 | |
@@ -530,7 +534,9 @@ discard block |
||
| 530 | 534 | |
| 531 | 535 | foreach ( $supported_methods as $method ) { |
| 532 | 536 | |
| 533 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method); |
|
| 537 | + if ( method_exists($this, strtolower($method)) ) { |
|
| 538 | + array_push($implemented_methods,$method); |
|
| 539 | + } |
|
| 534 | 540 | |
| 535 | 541 | } |
| 536 | 542 | |
@@ -545,9 +551,11 @@ discard block |
||
| 545 | 551 | */ |
| 546 | 552 | final public function getCallableMethod($method) { |
| 547 | 553 | |
| 548 | - if ( method_exists($this, strtolower($method)) ) return strtolower($method); |
|
| 549 | - |
|
| 550 | - else return "any"; |
|
| 554 | + if ( method_exists($this, strtolower($method)) ) { |
|
| 555 | + return strtolower($method); |
|
| 556 | + } else { |
|
| 557 | + return "any"; |
|
| 558 | + } |
|
| 551 | 559 | |
| 552 | 560 | } |
| 553 | 561 | |
@@ -619,7 +627,9 @@ discard block |
||
| 619 | 627 | */ |
| 620 | 628 | final public function getAttribute($attribute) { |
| 621 | 629 | |
| 622 | - if ( isset($this->attributes[$attribute]) ) return $this->attributes[$attribute]; |
|
| 630 | + if ( isset($this->attributes[$attribute]) ) { |
|
| 631 | + return $this->attributes[$attribute]; |
|
| 632 | + } |
|
| 623 | 633 | |
| 624 | 634 | return null; |
| 625 | 635 | |
@@ -665,7 +675,9 @@ discard block |
||
| 665 | 675 | */ |
| 666 | 676 | final public function getParameter($parameter) { |
| 667 | 677 | |
| 668 | - if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter]; |
|
| 678 | + if ( isset($this->parameters[$parameter]) ) { |
|
| 679 | + return $this->parameters[$parameter]; |
|
| 680 | + } |
|
| 669 | 681 | |
| 670 | 682 | return null; |
| 671 | 683 | |
@@ -690,7 +702,9 @@ discard block |
||
| 690 | 702 | */ |
| 691 | 703 | final public function getRequestHeader($header) { |
| 692 | 704 | |
| 693 | - if ( isset($this->request_headers[$header]) ) return $this->request_headers[$header]; |
|
| 705 | + if ( isset($this->request_headers[$header]) ) { |
|
| 706 | + return $this->request_headers[$header]; |
|
| 707 | + } |
|
| 694 | 708 | |
| 695 | 709 | return null; |
| 696 | 710 | |
@@ -712,7 +726,9 @@ discard block |
||
| 712 | 726 | |
| 713 | 727 | $methods_array = array(); |
| 714 | 728 | |
| 715 | - foreach ($methods as $method) $methods_array[$method] = array(); |
|
| 729 | + foreach ($methods as $method) { |
|
| 730 | + $methods_array[$method] = array(); |
|
| 731 | + } |
|
| 716 | 732 | |
| 717 | 733 | $methods_array['ANY'] = array(); |
| 718 | 734 | |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return string JSON encoded data |
| 39 | 39 | */ |
| 40 | - final public function toJson($data, $flags=null) { |
|
| 40 | + final public function toJson($data, $flags = null) { |
|
| 41 | 41 | |
| 42 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for JSON serialization"); |
|
| 42 | + if (!(is_array($data) OR is_object($data))) throw new Exception("Invalid data for JSON serialization"); |
|
| 43 | 43 | |
| 44 | 44 | return json_encode($data, $flags); |
| 45 | 45 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return string XML encoded data |
| 57 | 57 | */ |
| 58 | - final public function toXml($data, $prettify=false) { |
|
| 58 | + final public function toXml($data, $prettify = false) { |
|
| 59 | 59 | |
| 60 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization"); |
|
| 60 | + if (!(is_array($data) OR is_object($data))) throw new Exception("Invalid data for XML serialization"); |
|
| 61 | 61 | |
| 62 | - if ( is_object($data) ) $data = $this->objectToArray($data); |
|
| 62 | + if (is_object($data)) $data = $this->objectToArray($data); |
|
| 63 | 63 | |
| 64 | 64 | $xmlEngine = new XML(); |
| 65 | 65 | |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | final public function toYaml($data) { |
| 105 | 105 | |
| 106 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization"); |
|
| 106 | + if (!(is_array($data) OR is_object($data))) throw new Exception("Invalid data for XML serialization"); |
|
| 107 | 107 | |
| 108 | - if ( is_object($data) ) $data = $this->objectToArray($data); |
|
| 108 | + if (is_object($data)) $data = $this->objectToArray($data); |
|
| 109 | 109 | |
| 110 | 110 | return \Spyc::YAMLDump($data); |
| 111 | 111 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | $indent = ''; |
| 149 | 149 | |
| 150 | - $xmlString = str_replace("\n","",$xmlString); |
|
| 150 | + $xmlString = str_replace("\n", "", $xmlString); |
|
| 151 | 151 | $xmlString = trim(preg_replace("/<\?[^>]+>/", "", $xmlString)); |
| 152 | 152 | $xmlString = preg_replace("/>([\s]+)<\//", "></", $xmlString); |
| 153 | 153 | $xmlString = str_replace(">", ">\n", $xmlString); |
@@ -156,23 +156,23 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | $_xmlString = ''; |
| 158 | 158 | |
| 159 | - foreach($xmlStringArray as $k=>$tag){ |
|
| 159 | + foreach ($xmlStringArray as $k=>$tag) { |
|
| 160 | 160 | |
| 161 | 161 | if ($tag == "") continue; |
| 162 | 162 | |
| 163 | - if ($tag[0]=="<" AND $tag[1] != "/") { |
|
| 163 | + if ($tag[0] == "<" AND $tag[1] != "/") { |
|
| 164 | 164 | |
| 165 | 165 | $_xmlString .= $indent.$tag."\n"; |
| 166 | 166 | $indent .= ' '; |
| 167 | 167 | |
| 168 | - } elseif($tag[0]=="<" AND $tag[1] == "/") { |
|
| 168 | + } elseif ($tag[0] == "<" AND $tag[1] == "/") { |
|
| 169 | 169 | |
| 170 | - $indent = substr($indent,0,strlen($indent)-2); |
|
| 171 | - $_xmlString .= (substr($_xmlString,strlen($_xmlString)-1)==">" || substr($_xmlString,strlen($_xmlString)-1)=="\n" ? $indent : '').$tag."\n"; |
|
| 170 | + $indent = substr($indent, 0, strlen($indent)-2); |
|
| 171 | + $_xmlString .= (substr($_xmlString, strlen($_xmlString)-1) == ">" || substr($_xmlString, strlen($_xmlString)-1) == "\n" ? $indent : '').$tag."\n"; |
|
| 172 | 172 | |
| 173 | 173 | } else { |
| 174 | 174 | |
| 175 | - $_xmlString = substr($_xmlString,0,strlen($_xmlString)-1); |
|
| 175 | + $_xmlString = substr($_xmlString, 0, strlen($_xmlString)-1); |
|
| 176 | 176 | $_xmlString .= $tag; |
| 177 | 177 | |
| 178 | 178 | } |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | private function objectToArray($stdObj) { |
| 193 | 193 | |
| 194 | - if(is_object($stdObj)) { |
|
| 194 | + if (is_object($stdObj)) { |
|
| 195 | 195 | |
| 196 | 196 | $array = array(); |
| 197 | 197 | |
| 198 | - foreach($stdObj as $key=>$val){ |
|
| 198 | + foreach ($stdObj as $key=>$val) { |
|
| 199 | 199 | |
| 200 | 200 | $array[$key] = objectToArray($val); |
| 201 | 201 | |
@@ -39,7 +39,9 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | final public function toJson($data, $flags=null) { |
| 41 | 41 | |
| 42 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for JSON serialization"); |
|
| 42 | + if ( !( is_array($data) OR is_object($data) ) ) { |
|
| 43 | + throw new Exception("Invalid data for JSON serialization"); |
|
| 44 | + } |
|
| 43 | 45 | |
| 44 | 46 | return json_encode($data, $flags); |
| 45 | 47 | |
@@ -57,9 +59,13 @@ discard block |
||
| 57 | 59 | */ |
| 58 | 60 | final public function toXml($data, $prettify=false) { |
| 59 | 61 | |
| 60 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization"); |
|
| 62 | + if ( !( is_array($data) OR is_object($data) ) ) { |
|
| 63 | + throw new Exception("Invalid data for XML serialization"); |
|
| 64 | + } |
|
| 61 | 65 | |
| 62 | - if ( is_object($data) ) $data = $this->objectToArray($data); |
|
| 66 | + if ( is_object($data) ) { |
|
| 67 | + $data = $this->objectToArray($data); |
|
| 68 | + } |
|
| 63 | 69 | |
| 64 | 70 | $xmlEngine = new XML(); |
| 65 | 71 | |
@@ -103,9 +109,13 @@ discard block |
||
| 103 | 109 | */ |
| 104 | 110 | final public function toYaml($data) { |
| 105 | 111 | |
| 106 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization"); |
|
| 112 | + if ( !( is_array($data) OR is_object($data) ) ) { |
|
| 113 | + throw new Exception("Invalid data for XML serialization"); |
|
| 114 | + } |
|
| 107 | 115 | |
| 108 | - if ( is_object($data) ) $data = $this->objectToArray($data); |
|
| 116 | + if ( is_object($data) ) { |
|
| 117 | + $data = $this->objectToArray($data); |
|
| 118 | + } |
|
| 109 | 119 | |
| 110 | 120 | return \Spyc::YAMLDump($data); |
| 111 | 121 | |
@@ -158,7 +168,9 @@ discard block |
||
| 158 | 168 | |
| 159 | 169 | foreach($xmlStringArray as $k=>$tag){ |
| 160 | 170 | |
| 161 | - if ($tag == "") continue; |
|
| 171 | + if ($tag == "") { |
|
| 172 | + continue; |
|
| 173 | + } |
|
| 162 | 174 | |
| 163 | 175 | if ($tag[0]=="<" AND $tag[1] != "/") { |
| 164 | 176 | |
@@ -203,9 +215,9 @@ discard block |
||
| 203 | 215 | |
| 204 | 216 | return $array; |
| 205 | 217 | |
| 218 | + } else { |
|
| 219 | + return $stdObj; |
|
| 206 | 220 | } |
| 207 | - |
|
| 208 | - else return $stdObj; |
|
| 209 | 221 | |
| 210 | 222 | } |
| 211 | 223 | |
@@ -189,7 +189,7 @@ |
||
| 189 | 189 | "bestbefore"=> $best_before, |
| 190 | 190 | //"content" => $u_data["cache_content"] |
| 191 | 191 | "object" => $u_data |
| 192 | - ); |
|
| 192 | + ); |
|
| 193 | 193 | |
| 194 | 194 | } |
| 195 | 195 | |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $cacheTag = md5($request) . ".cache"; |
|
| 108 | + $cacheTag = md5($request).".cache"; |
|
| 109 | 109 | |
| 110 | - $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag; |
|
| 110 | + $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag; |
|
| 111 | 111 | |
| 112 | 112 | $f_data = serialize($data); |
| 113 | 113 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @return array An array containing maxage, bestbefore, object (data) |
| 140 | 140 | */ |
| 141 | - final public function get($request, $ttl=DISPATCHER_CACHE_TTL) { |
|
| 141 | + final public function get($request, $ttl = DISPATCHER_CACHE_TTL) { |
|
| 142 | 142 | |
| 143 | 143 | if (!DISPATCHER_CACHE_ENABLED) { |
| 144 | 144 | |
@@ -148,19 +148,19 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - $last_time_limit = (int)$this->current_time - $ttl; |
|
| 151 | + $last_time_limit = (int)$this->current_time-$ttl; |
|
| 152 | 152 | |
| 153 | - $cacheTag = md5($request) . ".cache"; |
|
| 153 | + $cacheTag = md5($request).".cache"; |
|
| 154 | 154 | |
| 155 | - $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag; |
|
| 155 | + $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag; |
|
| 156 | 156 | |
| 157 | 157 | $cache_time = @filemtime($cacheFile); |
| 158 | 158 | |
| 159 | 159 | if (is_readable($cacheFile) AND $cache_time >= $last_time_limit) { |
| 160 | 160 | |
| 161 | - $max_age = $cache_time + $ttl - (int)$this->current_time; |
|
| 161 | + $max_age = $cache_time+$ttl-(int)$this->current_time; |
|
| 162 | 162 | |
| 163 | - $best_before = gmdate("D, d M Y H:i:s", $cache_time + $ttl) . " GMT"; |
|
| 163 | + $best_before = gmdate("D, d M Y H:i:s", $cache_time+$ttl)." GMT"; |
|
| 164 | 164 | |
| 165 | 165 | $data = file_get_contents($cacheFile); |
| 166 | 166 | |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @return bool |
| 206 | 206 | */ |
| 207 | - public function purge($request=null) { |
|
| 207 | + public function purge($request = null) { |
|
| 208 | 208 | |
| 209 | - if ( is_null($request) ) { |
|
| 209 | + if (is_null($request)) { |
|
| 210 | 210 | |
| 211 | 211 | $this->logger->info('Purging whole cache'); |
| 212 | 212 | |
| 213 | 213 | $cache_files_number = 0; |
| 214 | 214 | |
| 215 | 215 | $cache_path = opendir($this->cache_path); |
| 216 | - if ( $cache_path === false ) { |
|
| 216 | + if ($cache_path === false) { |
|
| 217 | 217 | |
| 218 | 218 | $this->logger->error('Unable to open cache folder', array( |
| 219 | 219 | 'CACHEFOLDER' => $this->cache_path |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - while( false !== ( $cache_file = readdir($cache_path) ) ) { |
|
| 226 | + while (false !== ($cache_file = readdir($cache_path))) { |
|
| 227 | 227 | |
| 228 | - if ( pathinfo($cache_file, PATHINFO_EXTENSION) == "cache" ) { |
|
| 229 | - if ( unlink( $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cache_file ) == false ) return false; |
|
| 228 | + if (pathinfo($cache_file, PATHINFO_EXTENSION) == "cache") { |
|
| 229 | + if (unlink($this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cache_file) == false) return false; |
|
| 230 | 230 | else $cache_files_number++; |
| 231 | 231 | } |
| 232 | 232 | else continue; |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | 'REQUEST' => $request |
| 243 | 243 | )); |
| 244 | 244 | |
| 245 | - $cacheTag = md5($request) . ".cache"; |
|
| 245 | + $cacheTag = md5($request).".cache"; |
|
| 246 | 246 | |
| 247 | - $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag; |
|
| 247 | + $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag; |
|
| 248 | 248 | |
| 249 | - if ( is_readable($cacheFile) ) { |
|
| 249 | + if (is_readable($cacheFile)) { |
|
| 250 | 250 | |
| 251 | 251 | $unlink = unlink($cacheFile); |
| 252 | 252 | $cache_files_number = $unlink ? 1 : false; |
@@ -95,8 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | return false; |
| 97 | 97 | |
| 98 | - } |
|
| 99 | - else { |
|
| 98 | + } else { |
|
| 100 | 99 | |
| 101 | 100 | $this->logger->error('Empty data, nothign to cache'); |
| 102 | 101 | |
@@ -120,8 +119,7 @@ discard block |
||
| 120 | 119 | |
| 121 | 120 | if ($this->fail_silently) { |
| 122 | 121 | return false; |
| 123 | - } |
|
| 124 | - else { |
|
| 122 | + } else { |
|
| 125 | 123 | throw new IOException("Error writing to cache"); |
| 126 | 124 | } |
| 127 | 125 | } |
@@ -176,8 +174,7 @@ discard block |
||
| 176 | 174 | |
| 177 | 175 | return false; |
| 178 | 176 | |
| 179 | - } |
|
| 180 | - else { |
|
| 177 | + } else { |
|
| 181 | 178 | |
| 182 | 179 | throw new IOException("Error reading from cache"); |
| 183 | 180 | |
@@ -191,10 +188,10 @@ discard block |
||
| 191 | 188 | "object" => $u_data |
| 192 | 189 | ); |
| 193 | 190 | |
| 191 | + } else { |
|
| 192 | + return false; |
|
| 194 | 193 | } |
| 195 | 194 | |
| 196 | - else return false; |
|
| 197 | - |
|
| 198 | 195 | } |
| 199 | 196 | |
| 200 | 197 | /** |
@@ -226,17 +223,20 @@ discard block |
||
| 226 | 223 | while( false !== ( $cache_file = readdir($cache_path) ) ) { |
| 227 | 224 | |
| 228 | 225 | if ( pathinfo($cache_file, PATHINFO_EXTENSION) == "cache" ) { |
| 229 | - if ( unlink( $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cache_file ) == false ) return false; |
|
| 230 | - else $cache_files_number++; |
|
| 226 | + if ( unlink( $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cache_file ) == false ) { |
|
| 227 | + return false; |
|
| 228 | + } else { |
|
| 229 | + $cache_files_number++; |
|
| 230 | + } |
|
| 231 | + } else { |
|
| 232 | + continue; |
|
| 231 | 233 | } |
| 232 | - else continue; |
|
| 233 | 234 | |
| 234 | 235 | } |
| 235 | 236 | |
| 236 | 237 | closedir($cache_path); |
| 237 | 238 | |
| 238 | - } |
|
| 239 | - else { |
|
| 239 | + } else { |
|
| 240 | 240 | |
| 241 | 241 | $this->logger->info('Purging request cache', array( |
| 242 | 242 | 'REQUEST' => $request |
@@ -251,8 +251,9 @@ discard block |
||
| 251 | 251 | $unlink = unlink($cacheFile); |
| 252 | 252 | $cache_files_number = $unlink ? 1 : false; |
| 253 | 253 | |
| 254 | + } else { |
|
| 255 | + $cache_files_number = 0; |
|
| 254 | 256 | } |
| 255 | - else $cache_files_number = 0; |
|
| 256 | 257 | |
| 257 | 258 | } |
| 258 | 259 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @var array |
| 50 | 50 | */ |
| 51 | - private $supported_route_types = array("ROUTE","REDIRECT","ERROR"); |
|
| 51 | + private $supported_route_types = array("ROUTE", "REDIRECT", "ERROR"); |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Object constructor. |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return Object $this |
| 79 | 79 | */ |
| 80 | - public function setRoute($service, $type, $target, $parameters=array()) { |
|
| 80 | + public function setRoute($service, $type, $target, $parameters = array()) { |
|
| 81 | 81 | |
| 82 | 82 | $this->table[$service] = array( |
| 83 | 83 | "type" => $type, |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function unsetRoute($service) { |
| 100 | 100 | |
| 101 | - if ( isset($this->table[$service]) ) { |
|
| 101 | + if (isset($this->table[$service])) { |
|
| 102 | 102 | |
| 103 | 103 | unset($this->table[$service]); |
| 104 | 104 | |
@@ -121,17 +121,17 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | // If service is null, route to landing or (if not specified) to default route |
| 123 | 123 | |
| 124 | - if ( empty($service) ) return $this->routeToLanding(); |
|
| 124 | + if (empty($service)) return $this->routeToLanding(); |
|
| 125 | 125 | |
| 126 | 126 | // If service is in table, check if it is routable (in case of "ROUTE" route). |
| 127 | 127 | // If true, route request |
| 128 | 128 | // If false, return a 500 error |
| 129 | 129 | |
| 130 | - if ( isset($this->table[$service]) ) { |
|
| 130 | + if (isset($this->table[$service])) { |
|
| 131 | 131 | |
| 132 | - if ( $this->table[$service]["type"] == "ROUTE" ) { |
|
| 132 | + if ($this->table[$service]["type"] == "ROUTE") { |
|
| 133 | 133 | |
| 134 | - if ( $this->routable($this->table[$service]["target"]) ) return $this->table[$service]; |
|
| 134 | + if ($this->routable($this->table[$service]["target"])) return $this->table[$service]; |
|
| 135 | 135 | |
| 136 | 136 | else return $this->routeToNowhere(); |
| 137 | 137 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | // If autoroute is enabled, try to match service name with a service file. |
| 145 | 145 | // If true, try to route request |
| 146 | 146 | |
| 147 | - else if ( defined('DISPATCHER_AUTO_ROUTE') && DISPATCHER_AUTO_ROUTE === true AND $this->routable($service.".php", true) ) { |
|
| 147 | + else if (defined('DISPATCHER_AUTO_ROUTE') && DISPATCHER_AUTO_ROUTE === true AND $this->routable($service.".php", true)) { |
|
| 148 | 148 | |
| 149 | 149 | return array( |
| 150 | 150 | "type" => "ROUTE", |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @return bool |
| 180 | 180 | */ |
| 181 | - private function routable($target, $relative=false) { |
|
| 181 | + private function routable($target, $relative = false) { |
|
| 182 | 182 | |
| 183 | - if ( $relative ) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false; |
|
| 183 | + if ($relative) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false; |
|
| 184 | 184 | |
| 185 | 185 | else return is_readable($target) ? true : false; |
| 186 | 186 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | private function routeToLanding() { |
| 195 | 195 | |
| 196 | - if ( isset($this->table[""]) ) { |
|
| 196 | + if (isset($this->table[""])) { |
|
| 197 | 197 | |
| 198 | 198 | return $this->table[""]; |
| 199 | 199 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | private function routeToDefault() { |
| 212 | 212 | |
| 213 | - if ( isset($this->table["default"]) ) { |
|
| 213 | + if (isset($this->table["default"])) { |
|
| 214 | 214 | |
| 215 | 215 | return $this->table["default"]; |
| 216 | 216 | |
@@ -121,7 +121,9 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | // If service is null, route to landing or (if not specified) to default route |
| 123 | 123 | |
| 124 | - if ( empty($service) ) return $this->routeToLanding(); |
|
| 124 | + if ( empty($service) ) { |
|
| 125 | + return $this->routeToLanding(); |
|
| 126 | + } |
|
| 125 | 127 | |
| 126 | 128 | // If service is in table, check if it is routable (in case of "ROUTE" route). |
| 127 | 129 | // If true, route request |
@@ -131,14 +133,16 @@ discard block |
||
| 131 | 133 | |
| 132 | 134 | if ( $this->table[$service]["type"] == "ROUTE" ) { |
| 133 | 135 | |
| 134 | - if ( $this->routable($this->table[$service]["target"]) ) return $this->table[$service]; |
|
| 135 | - |
|
| 136 | - else return $this->routeToNowhere(); |
|
| 136 | + if ( $this->routable($this->table[$service]["target"]) ) { |
|
| 137 | + return $this->table[$service]; |
|
| 138 | + } else { |
|
| 139 | + return $this->routeToNowhere(); |
|
| 140 | + } |
|
| 137 | 141 | |
| 142 | + } else { |
|
| 143 | + return $this->table[$service]; |
|
| 138 | 144 | } |
| 139 | 145 | |
| 140 | - else return $this->table[$service]; |
|
| 141 | - |
|
| 142 | 146 | } |
| 143 | 147 | |
| 144 | 148 | // If autoroute is enabled, try to match service name with a service file. |
@@ -156,7 +160,9 @@ discard block |
||
| 156 | 160 | |
| 157 | 161 | // If a route cannot be traced, emit a 404 - not found - response |
| 158 | 162 | |
| 159 | - else return $this->routeToNotfound(); |
|
| 163 | + else { |
|
| 164 | + return $this->routeToNotfound(); |
|
| 165 | + } |
|
| 160 | 166 | |
| 161 | 167 | } |
| 162 | 168 | |
@@ -180,9 +186,11 @@ discard block |
||
| 180 | 186 | */ |
| 181 | 187 | private function routable($target, $relative=false) { |
| 182 | 188 | |
| 183 | - if ( $relative ) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false; |
|
| 184 | - |
|
| 185 | - else return is_readable($target) ? true : false; |
|
| 189 | + if ( $relative ) { |
|
| 190 | + return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false; |
|
| 191 | + } else { |
|
| 192 | + return is_readable($target) ? true : false; |
|
| 193 | + } |
|
| 186 | 194 | |
| 187 | 195 | } |
| 188 | 196 | |
@@ -197,10 +205,10 @@ discard block |
||
| 197 | 205 | |
| 198 | 206 | return $this->table[""]; |
| 199 | 207 | |
| 208 | + } else { |
|
| 209 | + return $this->routeToDefault(); |
|
| 200 | 210 | } |
| 201 | 211 | |
| 202 | - else return $this->routeToDefault(); |
|
| 203 | - |
|
| 204 | 212 | } |
| 205 | 213 | |
| 206 | 214 | /** |
@@ -214,10 +222,10 @@ discard block |
||
| 214 | 222 | |
| 215 | 223 | return $this->table["default"]; |
| 216 | 224 | |
| 225 | + } else { |
|
| 226 | + return $this->routeToNotfound(); |
|
| 217 | 227 | } |
| 218 | 228 | |
| 219 | - else return $this->routeToNotfound(); |
|
| 220 | - |
|
| 221 | 229 | } |
| 222 | 230 | |
| 223 | 231 | /** |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | * |
| 164 | 164 | * @return Object $this |
| 165 | 165 | */ |
| 166 | - public function setAttribute($name=null, $value) { |
|
| 166 | + public function setAttribute($name = null, $value) { |
|
| 167 | 167 | |
| 168 | - if ( is_null($name) ) array_push($this->attributes, $value); |
|
| 168 | + if (is_null($name)) array_push($this->attributes, $value); |
|
| 169 | 169 | |
| 170 | 170 | else $this->attributes[$name] = $value; |
| 171 | 171 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function unsetAttribute($attribute) { |
| 184 | 184 | |
| 185 | - if ( array_key_exists($attribute, $this->attributes) ) { |
|
| 185 | + if (array_key_exists($attribute, $this->attributes)) { |
|
| 186 | 186 | |
| 187 | 187 | unset($this->attributes[$attribute]); |
| 188 | 188 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | */ |
| 204 | 204 | public function getAttribute($attribute) { |
| 205 | 205 | |
| 206 | - if ( array_key_exists($attribute, $this->attributes) ) { |
|
| 206 | + if (array_key_exists($attribute, $this->attributes)) { |
|
| 207 | 207 | |
| 208 | 208 | return $this->attributes[$attribute]; |
| 209 | 209 | |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | public function unsetParameter($parameter) { |
| 279 | 279 | |
| 280 | - if ( array_key_exists($parameter, $this->parameters) ) { |
|
| 280 | + if (array_key_exists($parameter, $this->parameters)) { |
|
| 281 | 281 | |
| 282 | 282 | unset($this->parameters[$parameter]); |
| 283 | 283 | |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function getParameter($parameter) { |
| 300 | 300 | |
| 301 | - if ( array_key_exists($parameter, $this->parameters) ) { |
|
| 301 | + if (array_key_exists($parameter, $this->parameters)) { |
|
| 302 | 302 | |
| 303 | 303 | return $this->parameters[$parameter]; |
| 304 | 304 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * |
| 380 | 380 | * @return ObjectRequest $this |
| 381 | 381 | */ |
| 382 | - public function setHeader($header, $value=null) { |
|
| 382 | + public function setHeader($header, $value = null) { |
|
| 383 | 383 | |
| 384 | 384 | $this->headers[$header] = $value; |
| 385 | 385 | |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | */ |
| 397 | 397 | public function unsetHeader($header) { |
| 398 | 398 | |
| 399 | - if ( isset($this->headers[$header]) ) { |
|
| 399 | + if (isset($this->headers[$header])) { |
|
| 400 | 400 | |
| 401 | 401 | unset($this->headers[$header]); |
| 402 | 402 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | public function getHeader($header) { |
| 419 | 419 | |
| 420 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 420 | + if (isset($this->headers[$header])) return $this->headers[$header]; |
|
| 421 | 421 | |
| 422 | 422 | return null; |
| 423 | 423 | |
@@ -165,9 +165,11 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function setAttribute($name=null, $value) { |
| 167 | 167 | |
| 168 | - if ( is_null($name) ) array_push($this->attributes, $value); |
|
| 169 | - |
|
| 170 | - else $this->attributes[$name] = $value; |
|
| 168 | + if ( is_null($name) ) { |
|
| 169 | + array_push($this->attributes, $value); |
|
| 170 | + } else { |
|
| 171 | + $this->attributes[$name] = $value; |
|
| 172 | + } |
|
| 171 | 173 | |
| 172 | 174 | return $this; |
| 173 | 175 | |
@@ -417,7 +419,9 @@ discard block |
||
| 417 | 419 | */ |
| 418 | 420 | public function getHeader($header) { |
| 419 | 421 | |
| 420 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 422 | + if ( isset($this->headers[$header]) ) { |
|
| 423 | + return $this->headers[$header]; |
|
| 424 | + } |
|
| 421 | 425 | |
| 422 | 426 | return null; |
| 423 | 427 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | private $code = 307; |
| 31 | 31 | |
| 32 | - private $supported_redirect_codes = array(201,301,302,303,307); |
|
| 32 | + private $supported_redirect_codes = array(201, 301, 302, 303, 307); |
|
| 33 | 33 | |
| 34 | 34 | private $location = null; |
| 35 | 35 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @return ObjectRequest $this |
| 137 | 137 | */ |
| 138 | - public function setHeader($header, $value=null) { |
|
| 138 | + public function setHeader($header, $value = null) { |
|
| 139 | 139 | |
| 140 | 140 | $this->headers[$header] = $value; |
| 141 | 141 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function unsetHeader($header) { |
| 154 | 154 | |
| 155 | - if ( isset($this->headers[$header]) ) { |
|
| 155 | + if (isset($this->headers[$header])) { |
|
| 156 | 156 | |
| 157 | 157 | unset($this->headers[$header]); |
| 158 | 158 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function getHeader($header) { |
| 175 | 175 | |
| 176 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 176 | + if (isset($this->headers[$header])) return $this->headers[$header]; |
|
| 177 | 177 | |
| 178 | 178 | return null; |
| 179 | 179 | |
@@ -175,7 +175,9 @@ |
||
| 175 | 175 | */ |
| 176 | 176 | public function getHeader($header) { |
| 177 | 177 | |
| 178 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 178 | + if ( isset($this->headers[$header]) ) { |
|
| 179 | + return $this->headers[$header]; |
|
| 180 | + } |
|
| 179 | 181 | |
| 180 | 182 | return null; |
| 181 | 183 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private $charset = DISPATCHER_DEFAULT_ENCODING; |
| 39 | 39 | |
| 40 | - private $supported_success_codes = array(200,202,204); |
|
| 40 | + private $supported_success_codes = array(200, 202, 204); |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Set service name |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return ObjectRequest $this |
| 139 | 139 | */ |
| 140 | - public function setHeader($header, $value=null) { |
|
| 140 | + public function setHeader($header, $value = null) { |
|
| 141 | 141 | |
| 142 | 142 | $this->headers[$header] = $value; |
| 143 | 143 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function unsetHeader($header) { |
| 156 | 156 | |
| 157 | - if ( isset($this->headers[$header]) ) { |
|
| 157 | + if (isset($this->headers[$header])) { |
|
| 158 | 158 | |
| 159 | 159 | unset($this->headers[$header]); |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function getHeader($header) { |
| 177 | 177 | |
| 178 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 178 | + if (isset($this->headers[$header])) return $this->headers[$header]; |
|
| 179 | 179 | |
| 180 | 180 | return null; |
| 181 | 181 | |
@@ -175,7 +175,9 @@ |
||
| 175 | 175 | */ |
| 176 | 176 | public function getHeader($header) { |
| 177 | 177 | |
| 178 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 178 | + if ( isset($this->headers[$header]) ) { |
|
| 179 | + return $this->headers[$header]; |
|
| 180 | + } |
|
| 179 | 181 | |
| 180 | 182 | return null; |
| 181 | 183 | |