@@ -207,6 +207,9 @@ |
||
| 207 | 207 | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | + /** |
|
| 211 | + * @param string $name |
|
| 212 | + */ |
|
| 210 | 213 | private function createServiceSpecializedEvents($name) { |
| 211 | 214 | |
| 212 | 215 | $this->logger->debug("Emitting $name service-event"); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | // init core components |
| 80 | 80 | // create new configuration object and merge configuration |
| 81 | - $configuration_object = new Configuration( DefaultConfiguration::get() ); |
|
| 81 | + $configuration_object = new Configuration(DefaultConfiguration::get()); |
|
| 82 | 82 | $configuration_object->merge($configuration); |
| 83 | 83 | |
| 84 | 84 | $logger = is_null($logger) ? LogManager::createFromConfiguration($configuration_object)->getLogger() : $logger; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | } catch (Exception $e) { |
| 104 | 104 | |
| 105 | - $this->logger->critical($e->getMessage(),$e->getTrace()); |
|
| 105 | + $this->logger->critical($e->getMessage(), $e->getTrace()); |
|
| 106 | 106 | |
| 107 | 107 | throw $e; |
| 108 | 108 | |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | $logger->debug("Starting to dispatch."); |
| 123 | 123 | |
| 124 | 124 | $logger->debug("Emitting global dispatcher event."); |
| 125 | - $events->emit( new DispatcherEvent($this) ); |
|
| 125 | + $events->emit(new DispatcherEvent($this)); |
|
| 126 | 126 | |
| 127 | - if ( $configuration->get('enabled') === false ) { |
|
| 127 | + if ($configuration->get('enabled') === false) { |
|
| 128 | 128 | |
| 129 | 129 | $logger->debug("Dispatcher disabled, shutting down gracefully."); |
| 130 | 130 | |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $cache = new ServerCache($this->getCache()); |
| 142 | 142 | |
| 143 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.request') ); |
|
| 144 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()) ); |
|
| 145 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.request.#') ); |
|
| 143 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.request')); |
|
| 144 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get())); |
|
| 145 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.request.#')); |
|
| 146 | 146 | |
| 147 | - if ( $cache->read($this->request, $this->response) ) { |
|
| 147 | + if ($cache->read($this->request, $this->response)) { |
|
| 148 | 148 | // we have a cache! |
| 149 | 149 | // shutdown immediately |
| 150 | 150 | return $this->shutdown(); |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | $logger->debug("Route acquired, type $route_type directed to $route_service"); |
| 172 | 172 | |
| 173 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.route') ); |
|
| 174 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.route.'.$route_type) ); |
|
| 175 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.route.'.$route_service) ); |
|
| 176 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.route.#') ); |
|
| 173 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.route')); |
|
| 174 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.route.'.$route_type)); |
|
| 175 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.route.'.$route_service)); |
|
| 176 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.route.#')); |
|
| 177 | 177 | |
| 178 | 178 | // translate route to service |
| 179 | 179 | $logger->debug("Running $route_service service"); |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | $params = $route->getParameter('headers'); |
| 203 | 203 | |
| 204 | - if ( !empty($params) && is_array($params) ) { |
|
| 205 | - foreach($params as $name => $value) $this->getResponse()->getHeaders()->set($name, $value); |
|
| 204 | + if (!empty($params) && is_array($params)) { |
|
| 205 | + foreach ($params as $name => $value) $this->getResponse()->getHeaders()->set($name, $value); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | } |
@@ -247,9 +247,9 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | $response->consolidate($request, $this->route); |
| 249 | 249 | |
| 250 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.response') ); |
|
| 251 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.response.' . $response->getStatus()->get()) ); |
|
| 252 | - $events->emit( $this->createServiceSpecializedEvents('dispatcher.response.#') ); |
|
| 250 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.response')); |
|
| 251 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.response.'.$response->getStatus()->get())); |
|
| 252 | + $events->emit($this->createServiceSpecializedEvents('dispatcher.response.#')); |
|
| 253 | 253 | |
| 254 | 254 | $this->logger->debug("Composing return value"); |
| 255 | 255 | |
@@ -202,7 +202,9 @@ |
||
| 202 | 202 | $params = $route->getParameter('headers'); |
| 203 | 203 | |
| 204 | 204 | if ( !empty($params) && is_array($params) ) { |
| 205 | - foreach($params as $name => $value) $this->getResponse()->getHeaders()->set($name, $value); |
|
| 205 | + foreach($params as $name => $value) { |
|
| 206 | + $this->getResponse()->getHeaders()->set($name, $value); |
|
| 207 | + } |
|
| 206 | 208 | } |
| 207 | 209 | |
| 208 | 210 | } |
@@ -95,6 +95,9 @@ |
||
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | + /** |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 98 | 101 | public function getContent() { |
| 99 | 102 | |
| 100 | 103 | return $this->content; |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | use TimingTrait; |
| 37 | 37 | |
| 38 | - const NO_CONTENT_STATUSES = [100,101,102,204,304]; |
|
| 38 | + const NO_CONTENT_STATUSES = [100, 101, 102, 204, 304]; |
|
| 39 | 39 | |
| 40 | 40 | const CACHEABLE_METHODS = ['GET', 'HEAD', 'POST', 'PUT']; |
| 41 | 41 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | public function export() { |
| 139 | 139 | |
| 140 | - return (object) [ |
|
| 140 | + return (object)[ |
|
| 141 | 141 | 'headers' => $this->getHeaders(), |
| 142 | 142 | 'cookies' => $this->getCookies()->getAll(), |
| 143 | 143 | 'status' => $this->getStatus(), |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | public function import($data) { |
| 151 | 151 | |
| 152 | - if ( isset($data->headers) ) $this->setHeaders($data->headers); |
|
| 153 | - if ( isset($data->status) ) $this->setStatus($data->status); |
|
| 154 | - if ( isset($data->content) ) $this->setContent($data->content); |
|
| 155 | - if ( isset($data->location) ) $this->setLocation($data->location); |
|
| 152 | + if (isset($data->headers)) $this->setHeaders($data->headers); |
|
| 153 | + if (isset($data->status)) $this->setStatus($data->status); |
|
| 154 | + if (isset($data->content)) $this->setContent($data->content); |
|
| 155 | + if (isset($data->location)) $this->setLocation($data->location); |
|
| 156 | 156 | |
| 157 | - if ( isset($data->cookies) && is_array($data->cookies) ) { |
|
| 157 | + if (isset($data->cookies) && is_array($data->cookies)) { |
|
| 158 | 158 | $cookies = $this->getCookies(); |
| 159 | 159 | foreach ($data->cookies as $name => $cookie) $cookies->add($cookie); |
| 160 | 160 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | $output_class_name = "\\Comodojo\\Dispatcher\\Response\\Preprocessor\\Status".$status; |
| 169 | 169 | |
| 170 | 170 | // @TODO: this condition will be removed when all preprocessors ready |
| 171 | - if ( class_exists($output_class_name) ) { |
|
| 171 | + if (class_exists($output_class_name)) { |
|
| 172 | 172 | $output = new $output_class_name($this); |
| 173 | 173 | } else { |
| 174 | 174 | $output = new \Comodojo\Dispatcher\Response\Preprocessor\Status200($this); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $output->consolidate(); |
| 178 | 178 | |
| 179 | - if ( $route != null ) { |
|
| 179 | + if ($route != null) { |
|
| 180 | 180 | $this->setClientCache($request, $route); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $content = $this->getContent(); |
| 185 | 185 | $headers = $this->getHeaders(); |
| 186 | 186 | |
| 187 | - if ( (string) $request->getMethod() == 'HEAD' && !in_array($status, self::NO_CONTENT_STATUSES) ) { |
|
| 187 | + if ((string)$request->getMethod() == 'HEAD' && !in_array($status, self::NO_CONTENT_STATUSES)) { |
|
| 188 | 188 | $length = $content->length(); |
| 189 | 189 | $content->set(null); |
| 190 | 190 | if ($length) $headers->set('Content-Length', $length); |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $headers->delete('Content-Length'); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if ( (string) $request->getVersion() == '1.0' && false !== strpos($headers->get('Cache-Control'), 'no-cache')) { |
|
| 197 | + if ((string)$request->getVersion() == '1.0' && false !== strpos($headers->get('Cache-Control'), 'no-cache')) { |
|
| 198 | 198 | $headers->set('pragma', 'no-cache'); |
| 199 | 199 | $headers->set('expires', -1); |
| 200 | 200 | } |
@@ -204,20 +204,20 @@ discard block |
||
| 204 | 204 | private function setClientCache(Request $request, Route $route) { |
| 205 | 205 | |
| 206 | 206 | $cache = strtoupper($route->getParameter('cache')); |
| 207 | - $ttl = (int) $route->getParameter('ttl'); |
|
| 207 | + $ttl = (int)$route->getParameter('ttl'); |
|
| 208 | 208 | |
| 209 | 209 | if ( |
| 210 | 210 | ($cache == 'CLIENT' || $cache == 'BOTH') && |
| 211 | - in_array((string) $request->getMethod(), self::CACHEABLE_METHODS) && |
|
| 211 | + in_array((string)$request->getMethod(), self::CACHEABLE_METHODS) && |
|
| 212 | 212 | in_array($this->getStatus()->get(), self::CACHEABLE_STATUSES) |
| 213 | 213 | // @TODO: here we should also check for Cache-Control no-store or private; |
| 214 | 214 | // the cache layer will be improoved in future versions. |
| 215 | 215 | ) { |
| 216 | 216 | |
| 217 | 217 | $headers = $this->getHeaders(); |
| 218 | - $timestamp = (int) $this->getTime()->format('U') + $ttl; |
|
| 218 | + $timestamp = (int)$this->getTime()->format('U')+$ttl; |
|
| 219 | 219 | |
| 220 | - if ( $ttl > 0 ) { |
|
| 220 | + if ($ttl > 0) { |
|
| 221 | 221 | |
| 222 | 222 | $headers->set("Cache-Control", "max-age=".$ttl.", must-revalidate"); |
| 223 | 223 | $headers->set("Expires", gmdate("D, d M Y H:i:s", $timestamp)." GMT"); |
@@ -149,14 +149,24 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | public function import($data) { |
| 151 | 151 | |
| 152 | - if ( isset($data->headers) ) $this->setHeaders($data->headers); |
|
| 153 | - if ( isset($data->status) ) $this->setStatus($data->status); |
|
| 154 | - if ( isset($data->content) ) $this->setContent($data->content); |
|
| 155 | - if ( isset($data->location) ) $this->setLocation($data->location); |
|
| 152 | + if ( isset($data->headers) ) { |
|
| 153 | + $this->setHeaders($data->headers); |
|
| 154 | + } |
|
| 155 | + if ( isset($data->status) ) { |
|
| 156 | + $this->setStatus($data->status); |
|
| 157 | + } |
|
| 158 | + if ( isset($data->content) ) { |
|
| 159 | + $this->setContent($data->content); |
|
| 160 | + } |
|
| 161 | + if ( isset($data->location) ) { |
|
| 162 | + $this->setLocation($data->location); |
|
| 163 | + } |
|
| 156 | 164 | |
| 157 | 165 | if ( isset($data->cookies) && is_array($data->cookies) ) { |
| 158 | 166 | $cookies = $this->getCookies(); |
| 159 | - foreach ($data->cookies as $name => $cookie) $cookies->add($cookie); |
|
| 167 | + foreach ($data->cookies as $name => $cookie) { |
|
| 168 | + $cookies->add($cookie); |
|
| 169 | + } |
|
| 160 | 170 | } |
| 161 | 171 | |
| 162 | 172 | } |
@@ -187,7 +197,9 @@ discard block |
||
| 187 | 197 | if ( (string) $request->getMethod() == 'HEAD' && !in_array($status, self::NO_CONTENT_STATUSES) ) { |
| 188 | 198 | $length = $content->length(); |
| 189 | 199 | $content->set(null); |
| 190 | - if ($length) $headers->set('Content-Length', $length); |
|
| 200 | + if ($length) { |
|
| 201 | + $headers->set('Content-Length', $length); |
|
| 202 | + } |
|
| 191 | 203 | } |
| 192 | 204 | |
| 193 | 205 | if ($headers->get('Transfer-Encoding') != null) { |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function get($header = null) { |
| 30 | 30 | |
| 31 | - if ( is_null($header) ) return $this->headers; |
|
| 31 | + if (is_null($header)) return $this->headers; |
|
| 32 | 32 | |
| 33 | - else if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; |
|
| 33 | + else if (array_key_exists($header, $this->headers)) return $this->headers[$header]; |
|
| 34 | 34 | |
| 35 | 35 | else return null; |
| 36 | 36 | |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function getAsString($header = null) { |
| 40 | 40 | |
| 41 | - if ( is_null($header) ) { |
|
| 41 | + if (is_null($header)) { |
|
| 42 | 42 | |
| 43 | - return array_map( [$this, 'headerToString'], |
|
| 43 | + return array_map([$this, 'headerToString'], |
|
| 44 | 44 | array_keys($this->headers), |
| 45 | 45 | array_values($this->headers) |
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | - } else if ( array_key_exists($header, $this->headers) ) { |
|
| 48 | + } else if (array_key_exists($header, $this->headers)) { |
|
| 49 | 49 | |
| 50 | 50 | return self::headerToString($header, $this->headers[$header]); |
| 51 | 51 | |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public function set($header, $value=null) { |
|
| 56 | + public function set($header, $value = null) { |
|
| 57 | 57 | |
| 58 | - if ( is_null($value) ) { |
|
| 58 | + if (is_null($value)) { |
|
| 59 | 59 | |
| 60 | 60 | $header = explode(":", $header, 2); |
| 61 | 61 | |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | public function delete($header = null) { |
| 75 | 75 | |
| 76 | - if ( is_null($header) ) { |
|
| 76 | + if (is_null($header)) { |
|
| 77 | 77 | |
| 78 | 78 | $this->headers = array(); |
| 79 | 79 | |
| 80 | 80 | return true; |
| 81 | 81 | |
| 82 | - } else if ( array_key_exists($header, $this->headers) ) { |
|
| 82 | + } else if (array_key_exists($header, $this->headers)) { |
|
| 83 | 83 | |
| 84 | 84 | unset($this->headers[$header]); |
| 85 | 85 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | use ResponseTrait; |
| 49 | 49 | use ExtraTrait; |
| 50 | 50 | |
| 51 | - const SUPPORTED_METHODS = ['GET','PUT','POST','DELETE','OPTIONS','HEAD','TRACE','CONNECT','PURGE']; |
|
| 51 | + const SUPPORTED_METHODS = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'TRACE', 'CONNECT', 'PURGE']; |
|
| 52 | 52 | |
| 53 | 53 | public function __construct( |
| 54 | 54 | Configuration $configuration, |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | $supported_methods = $this->getConfiguration()->get('supported-http-methods'); |
| 83 | 83 | |
| 84 | - if ( is_null($supported_methods) ) $supported_methods = self::SUPPORTED_METHODS; |
|
| 84 | + if (is_null($supported_methods)) $supported_methods = self::SUPPORTED_METHODS; |
|
| 85 | 85 | |
| 86 | - if ( method_exists($this, 'any') ) { |
|
| 86 | + if (method_exists($this, 'any')) { |
|
| 87 | 87 | |
| 88 | 88 | return $supported_methods; |
| 89 | 89 | |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $implemented_methods = []; |
| 93 | 93 | |
| 94 | - foreach ( $supported_methods as $method ) { |
|
| 94 | + foreach ($supported_methods as $method) { |
|
| 95 | 95 | |
| 96 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods, $method); |
|
| 96 | + if (method_exists($this, strtolower($method))) array_push($implemented_methods, $method); |
|
| 97 | 97 | |
| 98 | 98 | } |
| 99 | 99 | |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $method = strtolower($method); |
| 111 | 111 | |
| 112 | - if ( method_exists($this, $method) ) { |
|
| 112 | + if (method_exists($this, $method)) { |
|
| 113 | 113 | |
| 114 | 114 | return $method; |
| 115 | 115 | |
| 116 | - } else if ( method_exists($this, 'any') ) { |
|
| 116 | + } else if (method_exists($this, 'any')) { |
|
| 117 | 117 | |
| 118 | 118 | return 'any'; |
| 119 | 119 | |
@@ -81,7 +81,9 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | $supported_methods = $this->getConfiguration()->get('supported-http-methods'); |
| 83 | 83 | |
| 84 | - if ( is_null($supported_methods) ) $supported_methods = self::SUPPORTED_METHODS; |
|
| 84 | + if ( is_null($supported_methods) ) { |
|
| 85 | + $supported_methods = self::SUPPORTED_METHODS; |
|
| 86 | + } |
|
| 85 | 87 | |
| 86 | 88 | if ( method_exists($this, 'any') ) { |
| 87 | 89 | |
@@ -93,7 +95,9 @@ discard block |
||
| 93 | 95 | |
| 94 | 96 | foreach ( $supported_methods as $method ) { |
| 95 | 97 | |
| 96 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods, $method); |
|
| 98 | + if ( method_exists($this, strtolower($method)) ) { |
|
| 99 | + array_push($implemented_methods, $method); |
|
| 100 | + } |
|
| 97 | 101 | |
| 98 | 102 | } |
| 99 | 103 | |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | // Because of the nature of the global regular expression, all the bits of the matched route are associated with a parameter key |
| 202 | 202 | foreach ($this->query as $key => $value) { |
| 203 | 203 | |
| 204 | - if ( isset($path[$key]) ) { |
|
| 204 | + if (isset($path[$key])) { |
|
| 205 | 205 | /* if it's available a bit associated with the parameter name, it is compared against |
| 206 | 206 | * it's regular expression in order to extrect backreferences |
| 207 | 207 | */ |
| 208 | - if ( preg_match('/^' . $value['regex'] . '$/', $path[$key], $matches) ) { |
|
| 208 | + if (preg_match('/^'.$value['regex'].'$/', $path[$key], $matches)) { |
|
| 209 | 209 | |
| 210 | - if ( count($matches) == 1 ) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
|
| 210 | + if (count($matches) == 1) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
|
| 211 | 211 | |
| 212 | 212 | // The extracted value (with any backreference available) is added to the query parameters. |
| 213 | 213 | $this->setRequestParameter($key, $matches); |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | public function serialize() { |
| 235 | 235 | |
| 236 | - return serialize( (object) [ |
|
| 236 | + return serialize((object)[ |
|
| 237 | 237 | 'classname' => $this->classname, |
| 238 | 238 | 'type' => $this->type, |
| 239 | 239 | 'service' => $this->service, |
@@ -207,7 +207,10 @@ |
||
| 207 | 207 | */ |
| 208 | 208 | if ( preg_match('/^' . $value['regex'] . '$/', $path[$key], $matches) ) { |
| 209 | 209 | |
| 210 | - if ( count($matches) == 1 ) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
|
| 210 | + if ( count($matches) == 1 ) { |
|
| 211 | + $matches = $matches[0]; |
|
| 212 | + } |
|
| 213 | + // This is the case where no backreferences are present or available. |
|
| 211 | 214 | |
| 212 | 215 | // The extracted value (with any backreference available) is added to the query parameters. |
| 213 | 216 | $this->setRequestParameter($key, $matches); |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | public function load($routes) { |
| 138 | 138 | |
| 139 | - if ( !empty($routes) ) { |
|
| 139 | + if (!empty($routes)) { |
|
| 140 | 140 | |
| 141 | - foreach( $routes as $name => $route ) { |
|
| 141 | + foreach ($routes as $name => $route) { |
|
| 142 | 142 | |
| 143 | 143 | $this->add($route['route'], $route['type'], $route['class'], $route['parameters']); |
| 144 | 144 | // $this->add($name, $route['type'], $route['class'], $route['parameters']); |
@@ -156,11 +156,11 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | private function readCache() { |
| 158 | 158 | |
| 159 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
| 159 | + if ($this->configuration->get('routing-table-cache') !== true) return; |
|
| 160 | 160 | |
| 161 | 161 | $data = $this->cache->read(); |
| 162 | 162 | |
| 163 | - if ( is_null($data) ) { |
|
| 163 | + if (is_null($data)) { |
|
| 164 | 164 | |
| 165 | 165 | $this->routes = []; |
| 166 | 166 | |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | private function dumpCache() { |
| 178 | 178 | |
| 179 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
| 179 | + if ($this->configuration->get('routing-table-cache') !== true) return; |
|
| 180 | 180 | |
| 181 | 181 | $ttl = $this->configuration->get('routing-table-ttl'); |
| 182 | 182 | |
| 183 | - if ( $this->cache->dump($this->routes, $ttl) ) { |
|
| 183 | + if ($this->cache->dump($this->routes, $ttl)) { |
|
| 184 | 184 | $this->logger->debug("Routing table saved to cache"); |
| 185 | 185 | } else { |
| 186 | 186 | $this->logger->warning("Cannot save routing table to cache"); |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | ->setClassName($class) // Class to be invoked |
| 199 | 199 | ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...) |
| 200 | 200 | |
| 201 | - $this->logger->debug("Route table - route: " . implode("/", $folders)); |
|
| 201 | + $this->logger->debug("Route table - route: ".implode("/", $folders)); |
|
| 202 | 202 | |
| 203 | 203 | // This method generate a global regular expression which will be able to match all the URI supported by the route |
| 204 | 204 | $regex = $this->parser->read($folders, $route); |
@@ -156,7 +156,9 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | private function readCache() { |
| 158 | 158 | |
| 159 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
| 159 | + if ( $this->configuration->get('routing-table-cache') !== true ) { |
|
| 160 | + return; |
|
| 161 | + } |
|
| 160 | 162 | |
| 161 | 163 | $data = $this->cache->read(); |
| 162 | 164 | |
@@ -176,7 +178,9 @@ discard block |
||
| 176 | 178 | |
| 177 | 179 | private function dumpCache() { |
| 178 | 180 | |
| 179 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
| 181 | + if ( $this->configuration->get('routing-table-cache') !== true ) { |
|
| 182 | + return; |
|
| 183 | + } |
|
| 180 | 184 | |
| 181 | 185 | $ttl = $this->configuration->get('routing-table-ttl'); |
| 182 | 186 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | return $this->read( |
| 106 | 106 | $folders, |
| 107 | 107 | $value, |
| 108 | - $regex.'(?:\/'.$param_regex.')'. (($param_required)?'{1}':'?') |
|
| 108 | + $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?') |
|
| 109 | 109 | ); |
| 110 | 110 | |
| 111 | 111 | } else { |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * If the field is required, the regular expression is completed with a '{1}' (which make it compulsory), |
| 162 | 162 | * otherwise a '?' is added. |
| 163 | 163 | */ |
| 164 | - return '(?P<' . $key . '>' . $string . ')' . (($field_required)?'{1}':'?'); |
|
| 164 | + return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?'); |
|
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | |
@@ -96,7 +96,9 @@ |
||
| 96 | 96 | */ |
| 97 | 97 | $param_regex .= $this->param($key, $string, $value); |
| 98 | 98 | |
| 99 | - if ($value->isQueryRequired($key)) $param_required = true; |
|
| 99 | + if ($value->isQueryRequired($key)) { |
|
| 100 | + $param_required = true; |
|
| 101 | + } |
|
| 100 | 102 | |
| 101 | 103 | $this->logger->debug("Route parser - parameter regex: $param_regex"); |
| 102 | 104 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | public function route(Request $request) { |
| 108 | 108 | |
| 109 | - $method = (string) $request->getMethod(); |
|
| 109 | + $method = (string)$request->getMethod(); |
|
| 110 | 110 | |
| 111 | 111 | $methods = $this->configuration->get('allowed-http-methods'); |
| 112 | 112 | |
| 113 | - if ( !empty($methods) && in_array($method, $methods) === false ) { |
|
| 113 | + if (!empty($methods) && in_array($method, $methods) === false) { |
|
| 114 | 114 | |
| 115 | 115 | throw new DispatcherException("Method not allowed", 0, null, 405, array( |
| 116 | - "Allow" => implode(",",$methods) |
|
| 116 | + "Allow" => implode(",", $methods) |
|
| 117 | 117 | )); |
| 118 | 118 | |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $this->setRequest($request); |
| 122 | 122 | |
| 123 | - if ( $this->bypass_routing === false ) { |
|
| 123 | + if ($this->bypass_routing === false) { |
|
| 124 | 124 | |
| 125 | - if ( !$this->parse() ) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
| 125 | + if (!$this->parse()) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | $class = $this->route->getClassName(); |
| 136 | 136 | |
| 137 | - if ( class_exists($class) ) { |
|
| 137 | + if (class_exists($class)) { |
|
| 138 | 138 | |
| 139 | 139 | // All the route parameters are also added to the query parameters |
| 140 | 140 | foreach ($this->route->getRequestParameters() as $parameter => $value) { |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | $this->setResponse($response); |
| 164 | 164 | |
| 165 | - if ( is_null($this->route) ) { |
|
| 165 | + if (is_null($this->route)) { |
|
| 166 | 166 | |
| 167 | 167 | throw new DispatcherException("Route has not been loaded!"); |
| 168 | 168 | |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if ( $this->bypass_service ) { |
|
| 171 | + if ($this->bypass_service) { |
|
| 172 | 172 | |
| 173 | 173 | return; |
| 174 | 174 | |
@@ -176,15 +176,15 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $service = $this->getServiceInstance(); |
| 178 | 178 | |
| 179 | - if ( !is_null($service) ) { |
|
| 179 | + if (!is_null($service)) { |
|
| 180 | 180 | |
| 181 | 181 | $result = ""; |
| 182 | 182 | |
| 183 | - $method = (string) $this->getRequest()->getMethod(); |
|
| 183 | + $method = (string)$this->getRequest()->getMethod(); |
|
| 184 | 184 | |
| 185 | 185 | $methods = $service->getImplementedMethods(); |
| 186 | 186 | |
| 187 | - if ( in_array($method, $methods) ) { |
|
| 187 | + if (in_array($method, $methods)) { |
|
| 188 | 188 | |
| 189 | 189 | $callable = $service->getMethod($method); |
| 190 | 190 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | foreach ($this->table->getRoutes() as $regex => $value) { |
| 228 | 228 | |
| 229 | 229 | // The current uri is checked against all the global regular expressions associated with the routes |
| 230 | - if ( preg_match("/" . $regex . "/", $path, $matches) ) { |
|
| 230 | + if (preg_match("/".$regex."/", $path, $matches)) { |
|
| 231 | 231 | |
| 232 | 232 | /* If a route is matched, all the bits of the route string are evalued in order to create |
| 233 | 233 | * new query parameters which will be available for the service class |
@@ -122,7 +122,9 @@ |
||
| 122 | 122 | |
| 123 | 123 | if ( $this->bypass_routing === false ) { |
| 124 | 124 | |
| 125 | - if ( !$this->parse() ) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
| 125 | + if ( !$this->parse() ) { |
|
| 126 | + throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
| 127 | + } |
|
| 126 | 128 | |
| 127 | 129 | } |
| 128 | 130 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $cache_object = $this->getCache()->setNamespace(self::CACHE_NAMESPACE)->get($name); |
| 49 | 49 | |
| 50 | - if ( is_null($cache_object) ) return false; |
|
| 50 | + if (is_null($cache_object)) return false; |
|
| 51 | 51 | |
| 52 | 52 | $response->import($cache_object); |
| 53 | 53 | |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | $name = self::getCacheName($request); |
| 69 | 69 | |
| 70 | - $method = (string) $request->getMethod(); |
|
| 70 | + $method = (string)$request->getMethod(); |
|
| 71 | 71 | |
| 72 | 72 | $status = $response->getStatus()->get(); |
| 73 | 73 | |
| 74 | 74 | if ( |
| 75 | - ( $cache == 'SERVER' || $cache == 'BOTH' ) && |
|
| 75 | + ($cache == 'SERVER' || $cache == 'BOTH') && |
|
| 76 | 76 | in_array($method, self::CACHABLE_METHODS) && |
| 77 | 77 | in_array($status, self::CACHABLE_STATUSES) |
| 78 | - ){ |
|
| 78 | + ) { |
|
| 79 | 79 | |
| 80 | 80 | $this->getCache() |
| 81 | 81 | ->setNamespace(self::CACHE_NAMESPACE) |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | private static function getCacheName(Request $request) { |
| 89 | 89 | |
| 90 | - return md5( (string) $request->getMethod() . (string) $request->getUri() ); |
|
| 90 | + return md5((string)$request->getMethod().(string)$request->getUri()); |
|
| 91 | 91 | |
| 92 | 92 | } |
| 93 | 93 | |
@@ -47,7 +47,9 @@ |
||
| 47 | 47 | |
| 48 | 48 | $cache_object = $this->getCache()->setNamespace(self::CACHE_NAMESPACE)->get($name); |
| 49 | 49 | |
| 50 | - if ( is_null($cache_object) ) return false; |
|
| 50 | + if ( is_null($cache_object) ) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 51 | 53 | |
| 52 | 54 | $response->import($cache_object); |
| 53 | 55 | |