@@ -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( |
@@ -194,7 +194,9 @@ discard block |
||
194 | 194 | |
195 | 195 | if ( !empty($params) && is_array($params) ) { |
196 | 196 | |
197 | - foreach($params as $name=>$value) $this->response->headers->set($name, $value); |
|
197 | + foreach($params as $name=>$value) { |
|
198 | + $this->response->headers->set($name, $value); |
|
199 | + } |
|
198 | 200 | } |
199 | 201 | |
200 | 202 | } |
@@ -246,8 +248,11 @@ discard block |
||
246 | 248 | |
247 | 249 | $this->logger->debug("Dispatcher run-cycle ends."); |
248 | 250 | |
249 | - if ( function_exists('fastcgi_finish_request') ) fastcgi_finish_request(); |
|
250 | - else ob_end_clean(); |
|
251 | + if ( function_exists('fastcgi_finish_request') ) { |
|
252 | + fastcgi_finish_request(); |
|
253 | + } else { |
|
254 | + ob_end_clean(); |
|
255 | + } |
|
251 | 256 | |
252 | 257 | return $return; |
253 | 258 |
@@ -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 | $logger = is_null($logger) ? LogManager::createFromConfiguration($configuration_object)->getLogger() : $logger; |
84 | 84 | |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | |
105 | 105 | $this->logger->debug("Emitting global dispatcher event."); |
106 | 106 | |
107 | - $this->events->emit( new DispatcherEvent($this) ); |
|
107 | + $this->events->emit(new DispatcherEvent($this)); |
|
108 | 108 | |
109 | - if ( $this->configuration->get('enabled') === false ) { |
|
109 | + if ($this->configuration->get('enabled') === false) { |
|
110 | 110 | |
111 | 111 | $this->logger->debug("Dispatcher disabled, shutting down gracefully."); |
112 | 112 | |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | |
125 | 125 | $cache = new ServerCache($this->cache); |
126 | 126 | |
127 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
127 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
128 | 128 | |
129 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()) ); |
|
129 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get())); |
|
130 | 130 | |
131 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
131 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
132 | 132 | |
133 | - if ( $cache->read($this->request, $this->response) ) { |
|
133 | + if ($cache->read($this->request, $this->response)) { |
|
134 | 134 | |
135 | 135 | return $this->shutdown(); |
136 | 136 | |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | |
159 | 159 | $this->logger->debug("Route acquired, type $route_type directed to $route_service."); |
160 | 160 | |
161 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
161 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
162 | 162 | |
163 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type) ); |
|
163 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type)); |
|
164 | 164 | |
165 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service) ); |
|
165 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service)); |
|
166 | 166 | |
167 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
167 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
168 | 168 | |
169 | 169 | // translate route to service |
170 | 170 | |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | |
195 | 195 | $params = $route->getParameter('headers'); |
196 | 196 | |
197 | - if ( !empty($params) && is_array($params) ) { |
|
197 | + if (!empty($params) && is_array($params)) { |
|
198 | 198 | |
199 | - foreach($params as $name=>$value) $this->response->headers->set($name, $value); |
|
199 | + foreach ($params as $name=>$value) $this->response->headers->set($name, $value); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | } |
@@ -236,11 +236,11 @@ discard block |
||
236 | 236 | |
237 | 237 | $this->response->consolidate($this->request, $this->route); |
238 | 238 | |
239 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
239 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
240 | 240 | |
241 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get()) ); |
|
241 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get())); |
|
242 | 242 | |
243 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
243 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
244 | 244 | |
245 | 245 | $this->logger->debug("Composing return value."); |
246 | 246 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | $this->logger->debug("Dispatcher run-cycle ends."); |
250 | 250 | |
251 | - if ( function_exists('fastcgi_finish_request') ) fastcgi_finish_request(); |
|
251 | + if (function_exists('fastcgi_finish_request')) fastcgi_finish_request(); |
|
252 | 252 | else ob_end_clean(); |
253 | 253 | |
254 | 254 | return $return; |
@@ -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 |
@@ -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 |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | |
109 | 109 | $methods = $this->configuration->get('allowed-http-methods'); |
110 | 110 | |
111 | - if ( ( $methods != null || !empty($methods) ) && in_array($method, $methods) === false ) { |
|
111 | + if (($methods != null || !empty($methods)) && in_array($method, $methods) === false) { |
|
112 | 112 | |
113 | 113 | throw new DispatcherException("Method not allowed", 0, null, 405, array( |
114 | - "Allow" => implode(",",$methods) |
|
114 | + "Allow" => implode(",", $methods) |
|
115 | 115 | )); |
116 | 116 | |
117 | 117 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | } |
140 | 140 | |
141 | - if ( $this->bypass_service ) { |
|
141 | + if ($this->bypass_service) { |
|
142 | 142 | |
143 | 143 | return; |
144 | 144 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | $methods = $service->getImplementedMethods(); |
160 | 160 | |
161 | - if ( in_array($method, $methods) ) { |
|
161 | + if (in_array($method, $methods)) { |
|
162 | 162 | |
163 | 163 | $callable = $service->getMethod($method); |
164 | 164 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | foreach ($this->table->routes() as $regex => $value) { |
202 | 202 | |
203 | 203 | // The current uri is checked against all the global regular expressions associated with the routes |
204 | - if (preg_match("/" . $regex . "/", $path, $matches)) { |
|
204 | + if (preg_match("/".$regex."/", $path, $matches)) { |
|
205 | 205 | |
206 | 206 | /* If a route is matched, all the bits of the route string are evalued in order to create |
207 | 207 | * new query parameters which will be available for the service class |
@@ -105,7 +105,9 @@ discard block |
||
105 | 105 | |
106 | 106 | if (!$this->bypass_routing) { |
107 | 107 | |
108 | - if (!$this->parse()) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
108 | + if (!$this->parse()) { |
|
109 | + throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
110 | + } |
|
109 | 111 | |
110 | 112 | } |
111 | 113 | |
@@ -133,8 +135,9 @@ discard block |
||
133 | 135 | $this->extra |
134 | 136 | ); |
135 | 137 | |
138 | + } else { |
|
139 | + return null; |
|
136 | 140 | } |
137 | - else return null; |
|
138 | 141 | |
139 | 142 | } |
140 | 143 |
@@ -48,11 +48,11 @@ |
||
48 | 48 | |
49 | 49 | private static function urlGetAbsolute() { |
50 | 50 | |
51 | - $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://'; |
|
51 | + $http = 'http'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'; |
|
52 | 52 | |
53 | 53 | $uri = self::uriGetAbsolute(); |
54 | 54 | |
55 | - return ( $http . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost') . $uri . "/" ); |
|
55 | + return ($http.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost').$uri."/"); |
|
56 | 56 | |
57 | 57 | } |
58 | 58 |
@@ -32,7 +32,9 @@ |
||
32 | 32 | |
33 | 33 | $location = $this->response()->location()->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()->headers()->set("Location: ".$location); |
38 | 40 |
@@ -32,11 +32,11 @@ |
||
32 | 32 | |
33 | 33 | $location = $this->response->location->get(); |
34 | 34 | |
35 | - if ( empty($location) ) throw new Exception("Invalid location, cannot redirect"); |
|
35 | + if (empty($location)) throw new Exception("Invalid location, cannot redirect"); |
|
36 | 36 | |
37 | 37 | $this->response->headers->set("Location: ".$location); |
38 | 38 | |
39 | - if ( empty($this->response->content->get()) ) { |
|
39 | + if (empty($this->response->content->get())) { |
|
40 | 40 | |
41 | 41 | $this->response->content->set(sprintf('<!DOCTYPE html> |
42 | 42 | <html> |
@@ -33,7 +33,7 @@ |
||
33 | 33 | // An Allow Header should be provided from DispatcherException |
34 | 34 | $allow = $this->response()->headers()->get('Allow'); |
35 | 35 | |
36 | - if ( is_null($allow) ) throw new Exception("Missing Allow header"); |
|
36 | + if (is_null($allow)) throw new Exception("Missing Allow header"); |
|
37 | 37 | |
38 | 38 | parent::consolidate(); |
39 | 39 |
@@ -33,7 +33,9 @@ |
||
33 | 33 | // An Allow Header should be provided from DispatcherException |
34 | 34 | $allow = $this->response()->headers()->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 |