@@ -167,6 +167,9 @@ |
||
| 167 | 167 | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | + /** |
|
| 171 | + * @param string $name |
|
| 172 | + */ |
|
| 170 | 173 | private function emitServiceSpecializedEvents($name) { |
| 171 | 174 | |
| 172 | 175 | return new ServiceEvent( |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | $this->setTimestamp(); |
| 61 | 61 | |
| 62 | 62 | // parsing configuration |
| 63 | - $this->configuration = new Configuration( DefaultConfiguration::get() ); |
|
| 63 | + $this->configuration = new Configuration(DefaultConfiguration::get()); |
|
| 64 | 64 | |
| 65 | 65 | $this->configuration->merge($configuration); |
| 66 | 66 | |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $this->logger->debug("Emitting global dispatcher event."); |
| 93 | 93 | |
| 94 | - $this->events->emit( new DispatcherEvent($this) ); |
|
| 94 | + $this->events->emit(new DispatcherEvent($this)); |
|
| 95 | 95 | |
| 96 | - if ( $this->configuration->get('enabled') === false ) { |
|
| 96 | + if ($this->configuration->get('enabled') === false) { |
|
| 97 | 97 | |
| 98 | 98 | $this->logger->debug("Dispatcher disabled, shutting down gracefully."); |
| 99 | 99 | |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
| 112 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
| 113 | 113 | |
| 114 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()) ); |
|
| 114 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get())); |
|
| 115 | 115 | |
| 116 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
| 116 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
| 117 | 117 | |
| 118 | - if ( $this->readCache() ) { |
|
| 118 | + if ($this->readCache()) { |
|
| 119 | 119 | |
| 120 | 120 | return $this->shutdown(); |
| 121 | 121 | |
@@ -145,13 +145,13 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $this->logger->debug("Route acquired, type $route_type directed to $route_service."); |
| 147 | 147 | |
| 148 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
| 148 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
| 149 | 149 | |
| 150 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type) ); |
|
| 150 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type)); |
|
| 151 | 151 | |
| 152 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service) ); |
|
| 152 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service)); |
|
| 153 | 153 | |
| 154 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
| 154 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
| 155 | 155 | |
| 156 | 156 | // translate route to service |
| 157 | 157 | |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | private function readCache() { |
| 181 | 181 | |
| 182 | - $name = (string) $this->request->uri; |
|
| 182 | + $name = (string)$this->request->uri; |
|
| 183 | 183 | |
| 184 | 184 | $cache = $this->cache->setNamespace('dispatcherservice')->get($name); |
| 185 | 185 | |
| 186 | - if ( is_null($cache) ) return false; |
|
| 186 | + if (is_null($cache)) return false; |
|
| 187 | 187 | |
| 188 | 188 | $this->response->import($cache); |
| 189 | 189 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | $cache = strtoupper($route->getParameter('cache')); |
| 197 | 197 | $ttl = $route->getParameter('ttl'); |
| 198 | - $name = (string) $this->request->uri; |
|
| 198 | + $name = (string)$this->request->uri; |
|
| 199 | 199 | $method = $this->request->method->get(); |
| 200 | 200 | $status = $this->response->status->get(); |
| 201 | 201 | |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | // because of dispatcher internal structure: if post request is cached |
| 204 | 204 | // subsequent requests will never reach the service. |
| 205 | 205 | if ( |
| 206 | - ( $cache == 'SERVER' || $cache == 'BOTH' ) && |
|
| 206 | + ($cache == 'SERVER' || $cache == 'BOTH') && |
|
| 207 | 207 | in_array($request->method->get(), array('GET', 'HEAD')) && |
| 208 | 208 | in_array($this->status->get(), array(200, 203, 300, 301, 302, 404, 410)) |
| 209 | - ){ |
|
| 209 | + ) { |
|
| 210 | 210 | |
| 211 | 211 | $this->cache->setNamespace('dispatcherservice')->set($name, $this->response->export(), $ttl); |
| 212 | 212 | |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | $params = $route->getParameter('headers'); |
| 220 | 220 | |
| 221 | - if ( !empty($params) && is_array($params) ) { |
|
| 221 | + if (!empty($params) && is_array($params)) { |
|
| 222 | 222 | |
| 223 | - foreach($params as $name=>$value) $this->response->headers->set($name, $value); |
|
| 223 | + foreach ($params as $name=>$value) $this->response->headers->set($name, $value); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | } |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | $this->response->consolidate($this->request, $this->route); |
| 262 | 262 | |
| 263 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
| 263 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
| 264 | 264 | |
| 265 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get()) ); |
|
| 265 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get())); |
|
| 266 | 266 | |
| 267 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
| 267 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
| 268 | 268 | |
| 269 | 269 | $this->logger->debug("Composing return value."); |
| 270 | 270 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | $this->logger->debug("Dispatcher run-cycle ends."); |
| 274 | 274 | |
| 275 | - if ( function_exists('fastcgi_finish_request') ) fastcgi_finish_request(); |
|
| 275 | + if (function_exists('fastcgi_finish_request')) fastcgi_finish_request(); |
|
| 276 | 276 | else ob_end_clean(); |
| 277 | 277 | |
| 278 | 278 | return $return; |
@@ -183,7 +183,9 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | $cache = $this->cache->setNamespace('dispatcherservice')->get($name); |
| 185 | 185 | |
| 186 | - if ( is_null($cache) ) return false; |
|
| 186 | + if ( is_null($cache) ) { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 187 | 189 | |
| 188 | 190 | $this->response->import($cache); |
| 189 | 191 | |
@@ -220,7 +222,9 @@ discard block |
||
| 220 | 222 | |
| 221 | 223 | if ( !empty($params) && is_array($params) ) { |
| 222 | 224 | |
| 223 | - foreach($params as $name=>$value) $this->response->headers->set($name, $value); |
|
| 225 | + foreach($params as $name=>$value) { |
|
| 226 | + $this->response->headers->set($name, $value); |
|
| 227 | + } |
|
| 224 | 228 | } |
| 225 | 229 | |
| 226 | 230 | } |
@@ -272,8 +276,11 @@ discard block |
||
| 272 | 276 | |
| 273 | 277 | $this->logger->debug("Dispatcher run-cycle ends."); |
| 274 | 278 | |
| 275 | - if ( function_exists('fastcgi_finish_request') ) fastcgi_finish_request(); |
|
| 276 | - else ob_end_clean(); |
|
| 279 | + if ( function_exists('fastcgi_finish_request') ) { |
|
| 280 | + fastcgi_finish_request(); |
|
| 281 | + } else { |
|
| 282 | + ob_end_clean(); |
|
| 283 | + } |
|
| 277 | 284 | |
| 278 | 285 | return $return; |
| 279 | 286 | |
@@ -28,16 +28,16 @@ |
||
| 28 | 28 | |
| 29 | 29 | final public function get($parameter=null) { |
| 30 | 30 | |
| 31 | - if ( is_null($parameter) ) return $this->parameters; |
|
| 32 | - |
|
| 33 | - else if ( array_key_exists($parameter, $this->parameters) ) { |
|
| 31 | + if ( is_null($parameter) ) { |
|
| 32 | + return $this->parameters; |
|
| 33 | + } else if ( array_key_exists($parameter, $this->parameters) ) { |
|
| 34 | 34 | |
| 35 | 35 | return $this->parameters[$parameter]; |
| 36 | 36 | |
| 37 | + } else { |
|
| 38 | + return null; |
|
| 37 | 39 | } |
| 38 | 40 | |
| 39 | - else return null; |
|
| 40 | - |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | final public function set($parameter, $value) { |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | protected $parameters = array(); |
| 29 | 29 | |
| 30 | - final public function get($parameter=null, $index=null) { |
|
| 30 | + final public function get($parameter = null, $index = null) { |
|
| 31 | 31 | |
| 32 | - if ( is_null($parameter) ) return $this->parameters; |
|
| 32 | + if (is_null($parameter)) return $this->parameters; |
|
| 33 | 33 | |
| 34 | - else if ( array_key_exists($parameter, $this->parameters) ) { |
|
| 34 | + else if (array_key_exists($parameter, $this->parameters)) { |
|
| 35 | 35 | |
| 36 | 36 | $value = $this->parameters[$parameter]; |
| 37 | 37 | |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | final public function delete($parameter = null) { |
| 71 | 71 | |
| 72 | - if ( is_null($parameter) ) { |
|
| 72 | + if (is_null($parameter)) { |
|
| 73 | 73 | |
| 74 | 74 | $this->parameters = array(); |
| 75 | 75 | |
| 76 | 76 | return true; |
| 77 | 77 | |
| 78 | - } else if ( array_key_exists($parameter, $this->parameters) ) { |
|
| 78 | + } else if (array_key_exists($parameter, $this->parameters)) { |
|
| 79 | 79 | |
| 80 | 80 | unset($this->parameters[$parameter]); |
| 81 | 81 | |
@@ -41,13 +41,13 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | private static function getHeaders() { |
| 43 | 43 | |
| 44 | - if ( function_exists('getallheaders') ) return getallheaders(); |
|
| 44 | + if (function_exists('getallheaders')) return getallheaders(); |
|
| 45 | 45 | |
| 46 | 46 | $headers = array(); |
| 47 | 47 | |
| 48 | - foreach ( $_SERVER as $name => $value ) { |
|
| 48 | + foreach ($_SERVER as $name => $value) { |
|
| 49 | 49 | |
| 50 | - if ( substr($name, 0, 5) == 'HTTP_' ) { |
|
| 50 | + if (substr($name, 0, 5) == 'HTTP_') { |
|
| 51 | 51 | |
| 52 | 52 | $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
| 53 | 53 | |
@@ -41,7 +41,9 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | private static function getHeaders() { |
| 43 | 43 | |
| 44 | - if ( function_exists('getallheaders') ) return getallheaders(); |
|
| 44 | + if ( function_exists('getallheaders') ) { |
|
| 45 | + return getallheaders(); |
|
| 46 | + } |
|
| 45 | 47 | |
| 46 | 48 | $headers = array(); |
| 47 | 49 | |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | |
| 47 | 47 | private static function getParameters() { |
| 48 | 48 | |
| 49 | - switch( $_SERVER['REQUEST_METHOD'] ) { |
|
| 49 | + switch ($_SERVER['REQUEST_METHOD']) { |
|
| 50 | 50 | |
| 51 | 51 | case 'POST': |
| 52 | 52 | |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | |
| 47 | 47 | private static function getParameters() { |
| 48 | 48 | |
| 49 | - switch( $_SERVER['REQUEST_METHOD'] ) { |
|
| 49 | + switch ($_SERVER['REQUEST_METHOD']) { |
|
| 50 | 50 | |
| 51 | 51 | case 'POST': |
| 52 | 52 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | protected $attributes = array(); |
| 29 | 29 | |
| 30 | - public function __construct( $configuration = array() ) { |
|
| 30 | + public function __construct($configuration = array()) { |
|
| 31 | 31 | |
| 32 | 32 | $this->attributes = array_merge($this->attributes, $configuration); |
| 33 | 33 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | final public function get($property = null) { |
| 37 | 37 | |
| 38 | - if ( is_null($property) ) { |
|
| 38 | + if (is_null($property)) { |
|
| 39 | 39 | |
| 40 | 40 | return $this->attributes; |
| 41 | 41 | |
@@ -91,13 +91,13 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | final public function delete($property = null) { |
| 93 | 93 | |
| 94 | - if ( is_null($property) ) { |
|
| 94 | + if (is_null($property)) { |
|
| 95 | 95 | |
| 96 | 96 | $this->attributes = array(); |
| 97 | 97 | |
| 98 | 98 | return true; |
| 99 | 99 | |
| 100 | - } else if ( $this->isDefined($property) ) { |
|
| 100 | + } else if ($this->isDefined($property)) { |
|
| 101 | 101 | |
| 102 | 102 | unset($this->attributes[$property]); |
| 103 | 103 | |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function get($header = null) { |
| 31 | 31 | |
| 32 | - if ( is_null($header) ) return $this->headers; |
|
| 32 | + if (is_null($header)) return $this->headers; |
|
| 33 | 33 | |
| 34 | - else if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; |
|
| 34 | + else if (array_key_exists($header, $this->headers)) return $this->headers[$header]; |
|
| 35 | 35 | |
| 36 | 36 | else return null; |
| 37 | 37 | |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | public function getAsString($header = null) { |
| 41 | 41 | |
| 42 | - if ( is_null($header) ) { |
|
| 42 | + if (is_null($header)) { |
|
| 43 | 43 | |
| 44 | - return array_map( function($header, $value) { |
|
| 44 | + return array_map(function($header, $value) { |
|
| 45 | 45 | return (string)($header.':'.$value); |
| 46 | 46 | }, |
| 47 | 47 | $this->headers); |
| 48 | 48 | |
| 49 | - } else if ( array_key_exists($header, $this->headers) ) { |
|
| 49 | + } else if (array_key_exists($header, $this->headers)) { |
|
| 50 | 50 | |
| 51 | 51 | return (string)($header.':'.$this->headers[$header]); |
| 52 | 52 | |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - public function set($header, $value=null) { |
|
| 57 | + public function set($header, $value = null) { |
|
| 58 | 58 | |
| 59 | - if ( is_null($value) ) { |
|
| 59 | + if (is_null($value)) { |
|
| 60 | 60 | |
| 61 | 61 | $header = explode(":", $header); |
| 62 | 62 | |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | public function delete($header = null) { |
| 76 | 76 | |
| 77 | - if ( is_null($header) ) { |
|
| 77 | + if (is_null($header)) { |
|
| 78 | 78 | |
| 79 | 79 | $this->headers = array(); |
| 80 | 80 | |
| 81 | 81 | return true; |
| 82 | 82 | |
| 83 | - } else if ( array_key_exists($header, $this->headers) ) { |
|
| 83 | + } else if (array_key_exists($header, $this->headers)) { |
|
| 84 | 84 | |
| 85 | 85 | unset($this->headers[$header]); |
| 86 | 86 | |
@@ -29,11 +29,13 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function get($header = null) { |
| 31 | 31 | |
| 32 | - if ( is_null($header) ) return $this->headers; |
|
| 33 | - |
|
| 34 | - else if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; |
|
| 35 | - |
|
| 36 | - else return null; |
|
| 32 | + if ( is_null($header) ) { |
|
| 33 | + return $this->headers; |
|
| 34 | + } else if ( array_key_exists($header, $this->headers) ) { |
|
| 35 | + return $this->headers[$header]; |
|
| 36 | + } else { |
|
| 37 | + return null; |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | } |
| 39 | 41 | |
@@ -50,7 +52,9 @@ discard block |
||
| 50 | 52 | |
| 51 | 53 | return (string)($header.':'.$this->headers[$header]); |
| 52 | 54 | |
| 53 | - } else return null; |
|
| 55 | + } else { |
|
| 56 | + return null; |
|
| 57 | + } |
|
| 54 | 58 | |
| 55 | 59 | } |
| 56 | 60 | |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | |
| 36 | 36 | final public function setTimestamp($time = null) { |
| 37 | 37 | |
| 38 | - if ( is_float($time) ) $this->timestamp = $time; |
|
| 38 | + if (is_float($time)) $this->timestamp = $time; |
|
| 39 | 39 | |
| 40 | 40 | else $this->timestamp = microtime(true); |
| 41 | 41 | |
@@ -35,9 +35,11 @@ |
||
| 35 | 35 | |
| 36 | 36 | final public function setTimestamp($time = null) { |
| 37 | 37 | |
| 38 | - if ( is_float($time) ) $this->timestamp = $time; |
|
| 39 | - |
|
| 40 | - else $this->timestamp = microtime(true); |
|
| 38 | + if ( is_float($time) ) { |
|
| 39 | + $this->timestamp = $time; |
|
| 40 | + } else { |
|
| 41 | + $this->timestamp = microtime(true); |
|
| 42 | + } |
|
| 41 | 43 | |
| 42 | 44 | return $this; |
| 43 | 45 | |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | foreach ($decoded as $key => $string) { |
| 75 | 75 | |
| 76 | - $this->logger->debug("PARAMETER KEY: " . $key); |
|
| 76 | + $this->logger->debug("PARAMETER KEY: ".$key); |
|
| 77 | 77 | |
| 78 | - $this->logger->debug("PARAMETER STRING: " . $string); |
|
| 78 | + $this->logger->debug("PARAMETER STRING: ".$string); |
|
| 79 | 79 | |
| 80 | 80 | /* The key and the regex of every paramater is passed to the 'param' |
| 81 | 81 | * method which will build an appropriate regular expression and will understand |
@@ -83,14 +83,14 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | $param_regex .= $this->param($key, $string, $param_required, $value); |
| 85 | 85 | |
| 86 | - $this->logger->debug("PARAMETER REGEX: " . $param_regex); |
|
| 86 | + $this->logger->debug("PARAMETER REGEX: ".$param_regex); |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | // Once the parameter is analyzed, the result is passed to the next iteration |
| 90 | 90 | return $this->read( |
| 91 | 91 | $folders, |
| 92 | 92 | $value, |
| 93 | - $regex.'(?:\/'.$param_regex.')'. (($param_required)?'{1}':'?') |
|
| 93 | + $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?') |
|
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | 96 | } else { |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * If the field is required, the regular expression is completed with a '{1}' (which make it compulsory), |
| 156 | 156 | * otherwise a '?' is added. |
| 157 | 157 | */ |
| 158 | - return '(?P<' . $key . '>' . $string . ')' . (($field_required)?'{1}':'?'); |
|
| 158 | + return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?'); |
|
| 159 | 159 | |
| 160 | 160 | } |
| 161 | 161 | |
@@ -103,7 +103,9 @@ |
||
| 103 | 103 | */ |
| 104 | 104 | $param_regex .= $this->param($key, $string, $value); |
| 105 | 105 | |
| 106 | - if ($value->isQueryRequired($key)) $param_required = true; |
|
| 106 | + if ($value->isQueryRequired($key)) { |
|
| 107 | + $param_required = true; |
|
| 108 | + } |
|
| 107 | 109 | |
| 108 | 110 | $this->logger->debug("PARAMETER REGEX: " . $param_regex); |
| 109 | 111 | |