@@ -32,7 +32,9 @@ |
||
| 32 | 32 | |
| 33 | 33 | $location = $this->response->getLocation()->get(); |
| 34 | 34 | |
| 35 | - if (empty($location)) throw new Exception("Invalid location, cannot redirect"); |
|
| 35 | + if (empty($location)) { |
|
| 36 | + throw new Exception("Invalid location, cannot redirect"); |
|
| 37 | + } |
|
| 36 | 38 | |
| 37 | 39 | $this->response->getHeaders()->set("Location", $location); |
| 38 | 40 | |
@@ -33,7 +33,9 @@ |
||
| 33 | 33 | // An Allow Header should be provided from DispatcherException |
| 34 | 34 | $allow = $this->response->getHeaders()->get('Allow'); |
| 35 | 35 | |
| 36 | - if (is_null($allow)) throw new Exception("Missing Allow header"); |
|
| 36 | + if (is_null($allow)) { |
|
| 37 | + throw new Exception("Missing Allow header"); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | parent::consolidate(); |
| 39 | 41 | |
@@ -159,14 +159,24 @@ |
||
| 159 | 159 | |
| 160 | 160 | public function import($data) { |
| 161 | 161 | |
| 162 | - if (isset($data->headers)) $this->setHeaders($data->headers); |
|
| 163 | - if (isset($data->status)) $this->setStatus($data->status); |
|
| 164 | - if (isset($data->content)) $this->setContent($data->content); |
|
| 165 | - if (isset($data->location)) $this->setLocation($data->location); |
|
| 162 | + if (isset($data->headers)) { |
|
| 163 | + $this->setHeaders($data->headers); |
|
| 164 | + } |
|
| 165 | + if (isset($data->status)) { |
|
| 166 | + $this->setStatus($data->status); |
|
| 167 | + } |
|
| 168 | + if (isset($data->content)) { |
|
| 169 | + $this->setContent($data->content); |
|
| 170 | + } |
|
| 171 | + if (isset($data->location)) { |
|
| 172 | + $this->setLocation($data->location); |
|
| 173 | + } |
|
| 166 | 174 | |
| 167 | 175 | if (isset($data->cookies) && is_array($data->cookies)) { |
| 168 | 176 | $cookies = $this->getCookies(); |
| 169 | - foreach ($data->cookies as $name => $cookie) $cookies->add($cookie); |
|
| 177 | + foreach ($data->cookies as $name => $cookie) { |
|
| 178 | + $cookies->add($cookie); |
|
| 179 | + } |
|
| 170 | 180 | } |
| 171 | 181 | |
| 172 | 182 | } |
@@ -229,7 +229,7 @@ |
||
| 229 | 229 | ) { |
| 230 | 230 | |
| 231 | 231 | $headers = $this->getHeaders(); |
| 232 | - $timestamp = (int) $this->getTime()->format('U')+$ttl; |
|
| 232 | + $timestamp = (int)$this->getTime()->format('U')+$ttl; |
|
| 233 | 233 | |
| 234 | 234 | if ($ttl > 0) { |
| 235 | 235 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | $events->emit($this->createServiceSpecializedEvents('dispatcher.route')); |
| 174 | 174 | $events->emit($this->createServiceSpecializedEvents('dispatcher.route.'.$route_type)); |
| 175 | 175 | |
| 176 | - if ( $route_type == 'ROUTE' ) { |
|
| 176 | + if ($route_type == 'ROUTE') { |
|
| 177 | 177 | $logger->debug("Route leads to service $route_service"); |
| 178 | 178 | $events->emit($this->createServiceSpecializedEvents('dispatcher.route.'.$route_service)); |
| 179 | 179 | } |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | $params = $route->getParameter('headers'); |
| 231 | 231 | |
| 232 | - if ( !empty($params) && is_array($params) ) { |
|
| 233 | - foreach($params as $name => $value) { |
|
| 232 | + if (!empty($params) && is_array($params)) { |
|
| 233 | + foreach ($params as $name => $value) { |
|
| 234 | 234 | $this->getResponse()->getHeaders()->set($name, $value); |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -246,11 +246,11 @@ discard block |
||
| 246 | 246 | $code = $route->getRedirectCode(); |
| 247 | 247 | |
| 248 | 248 | $location = $route->getRedirectLocation(); |
| 249 | - $uri = empty($location) ? (string) $this->getRequest()->getUri() : $location; |
|
| 249 | + $uri = empty($location) ? (string)$this->getRequest()->getUri() : $location; |
|
| 250 | 250 | |
| 251 | 251 | $message = $route->getRedirectMessage(); |
| 252 | 252 | |
| 253 | - if ( $route->getRedirectType() == Route::REDIRECT_REFRESH ) { |
|
| 253 | + if ($route->getRedirectType() == Route::REDIRECT_REFRESH) { |
|
| 254 | 254 | |
| 255 | 255 | $output = empty($message) ? |
| 256 | 256 | "Please follow <a href=\"$location\">this link</a>" |
@@ -262,10 +262,10 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | } else { |
| 264 | 264 | |
| 265 | - if ( !empty($code) ) { |
|
| 265 | + if (!empty($code)) { |
|
| 266 | 266 | $status->set($code); |
| 267 | - } else if ( $this->getRequest()->getVersion() == 'HTTP/1.1' ) { |
|
| 268 | - $status->set( (string) $this->getRequest()->getMethod() !== 'GET' ? 303 : 307); |
|
| 267 | + } else if ($this->getRequest()->getVersion() == 'HTTP/1.1') { |
|
| 268 | + $status->set((string)$this->getRequest()->getMethod() !== 'GET' ? 303 : 307); |
|
| 269 | 269 | } else { |
| 270 | 270 | $status->set(302); |
| 271 | 271 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Types of route that this table will accept |
| 42 | 42 | * @var array |
| 43 | 43 | */ |
| 44 | - const ALLOWED_ROUTES = [ "ROUTE", "REDIRECT", "ERROR" ]; |
|
| 44 | + const ALLOWED_ROUTES = ["ROUTE", "REDIRECT", "ERROR"]; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Current repository of routes |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | $type = strtoupper($type); |
| 92 | 92 | |
| 93 | - if ( !in_array($type, self::ALLOWED_ROUTES) ) { |
|
| 93 | + if (!in_array($type, self::ALLOWED_ROUTES)) { |
|
| 94 | 94 | |
| 95 | 95 | $this->getLogger()->error("Invalid route definition - unknown type $type for route $route)"); |
| 96 | 96 | |
| 97 | - } else if ( $type == 'ROUTE' && empty($class) ) { |
|
| 97 | + } else if ($type == 'ROUTE' && empty($class)) { |
|
| 98 | 98 | |
| 99 | 99 | $this->getLogger()->error("Invalid route definition - missing class for route $route)"); |
| 100 | 100 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | $routeData = $this->get($route); |
| 104 | 104 | |
| 105 | - if ( !is_null($routeData) ) { |
|
| 105 | + if (!is_null($routeData)) { |
|
| 106 | 106 | |
| 107 | 107 | $this->updateRoute($routeData, $type, $class, $parameters); |
| 108 | 108 | |
@@ -237,13 +237,13 @@ discard block |
||
| 237 | 237 | ->setClassName($class) |
| 238 | 238 | ->setParameters($parameters); |
| 239 | 239 | |
| 240 | - if ( !empty($parameters['redirect-code']) ) $route->setRedirectCode($parameters['redirect-code']); |
|
| 241 | - if ( !empty($parameters['redirect-location']) ) $route->setRedirectLocation($parameters['redirect-location']); |
|
| 242 | - if ( !empty($parameters['redirect-message']) ) $route->setRedirectLocation($parameters['redirect-message']); |
|
| 243 | - if ( !empty($parameters['redirect-type']) ) $route->setRedirectType($parameters['redirect-type']); |
|
| 240 | + if (!empty($parameters['redirect-code'])) $route->setRedirectCode($parameters['redirect-code']); |
|
| 241 | + if (!empty($parameters['redirect-location'])) $route->setRedirectLocation($parameters['redirect-location']); |
|
| 242 | + if (!empty($parameters['redirect-message'])) $route->setRedirectLocation($parameters['redirect-message']); |
|
| 243 | + if (!empty($parameters['redirect-type'])) $route->setRedirectType($parameters['redirect-type']); |
|
| 244 | 244 | |
| 245 | - if ( !empty($parameters['error-code']) ) $route->setErrorCode($parameters['error-code']); |
|
| 246 | - if ( !empty($parameters['error-message']) ) $route->setErrorMessage($parameters['error-message']); |
|
| 245 | + if (!empty($parameters['error-code'])) $route->setErrorCode($parameters['error-code']); |
|
| 246 | + if (!empty($parameters['error-message'])) $route->setErrorMessage($parameters['error-message']); |
|
| 247 | 247 | |
| 248 | 248 | } |
| 249 | 249 | |
@@ -237,19 +237,33 @@ discard block |
||
| 237 | 237 | ->setClassName($class) |
| 238 | 238 | ->setParameters($parameters); |
| 239 | 239 | |
| 240 | - if ( !empty($parameters['redirect-code']) ) $route->setRedirectCode($parameters['redirect-code']); |
|
| 241 | - if ( !empty($parameters['redirect-location']) ) $route->setRedirectLocation($parameters['redirect-location']); |
|
| 242 | - if ( !empty($parameters['redirect-message']) ) $route->setRedirectLocation($parameters['redirect-message']); |
|
| 243 | - if ( !empty($parameters['redirect-type']) ) $route->setRedirectType($parameters['redirect-type']); |
|
| 240 | + if ( !empty($parameters['redirect-code']) ) { |
|
| 241 | + $route->setRedirectCode($parameters['redirect-code']); |
|
| 242 | + } |
|
| 243 | + if ( !empty($parameters['redirect-location']) ) { |
|
| 244 | + $route->setRedirectLocation($parameters['redirect-location']); |
|
| 245 | + } |
|
| 246 | + if ( !empty($parameters['redirect-message']) ) { |
|
| 247 | + $route->setRedirectLocation($parameters['redirect-message']); |
|
| 248 | + } |
|
| 249 | + if ( !empty($parameters['redirect-type']) ) { |
|
| 250 | + $route->setRedirectType($parameters['redirect-type']); |
|
| 251 | + } |
|
| 244 | 252 | |
| 245 | - if ( !empty($parameters['error-code']) ) $route->setErrorCode($parameters['error-code']); |
|
| 246 | - if ( !empty($parameters['error-message']) ) $route->setErrorMessage($parameters['error-message']); |
|
| 253 | + if ( !empty($parameters['error-code']) ) { |
|
| 254 | + $route->setErrorCode($parameters['error-code']); |
|
| 255 | + } |
|
| 256 | + if ( !empty($parameters['error-message']) ) { |
|
| 257 | + $route->setErrorMessage($parameters['error-message']); |
|
| 258 | + } |
|
| 247 | 259 | |
| 248 | 260 | } |
| 249 | 261 | |
| 250 | 262 | private function readCache() { |
| 251 | 263 | |
| 252 | - if ($this->configuration->get('routing-table-cache') !== true) return; |
|
| 264 | + if ($this->configuration->get('routing-table-cache') !== true) { |
|
| 265 | + return; |
|
| 266 | + } |
|
| 253 | 267 | |
| 254 | 268 | $data = $this->cache->read(); |
| 255 | 269 | |
@@ -269,7 +283,9 @@ discard block |
||
| 269 | 283 | |
| 270 | 284 | private function dumpCache() { |
| 271 | 285 | |
| 272 | - if ($this->configuration->get('routing-table-cache') !== true) return; |
|
| 286 | + if ($this->configuration->get('routing-table-cache') !== true) { |
|
| 287 | + return; |
|
| 288 | + } |
|
| 273 | 289 | |
| 274 | 290 | $ttl = $this->configuration->get('routing-table-ttl'); |
| 275 | 291 | |