@@ -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( |
@@ -192,7 +192,9 @@ |
||
192 | 192 | |
193 | 193 | if ( !empty($params) && is_array($params) ) { |
194 | 194 | |
195 | - foreach($params as $name=>$value) $this->response->headers->set($name, $value); |
|
195 | + foreach($params as $name=>$value) { |
|
196 | + $this->response->headers->set($name, $value); |
|
197 | + } |
|
196 | 198 | } |
197 | 199 | |
198 | 200 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | // init core components |
76 | 76 | // create new configuration object and merge configuration |
77 | - $configuration_object = new Configuration( DefaultConfiguration::get() ); |
|
77 | + $configuration_object = new Configuration(DefaultConfiguration::get()); |
|
78 | 78 | $configuration_object->merge($configuration); |
79 | 79 | $logger = is_null($logger) ? LogManager::createFromConfiguration($configuration_object)->getLogger() : $logger; |
80 | 80 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $this->setRaw('response', new Response($this->configuration, $this->logger)); |
96 | 96 | |
97 | 97 | } catch (Exception $e) { |
98 | - $this->logger->critical($e->getMessage(),$e->getTrace()); |
|
98 | + $this->logger->critical($e->getMessage(), $e->getTrace()); |
|
99 | 99 | throw $e; |
100 | 100 | } |
101 | 101 | |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | |
111 | 111 | $this->logger->debug("Emitting global dispatcher event."); |
112 | 112 | |
113 | - $this->events->emit( new DispatcherEvent($this) ); |
|
113 | + $this->events->emit(new DispatcherEvent($this)); |
|
114 | 114 | |
115 | - if ( $this->configuration->get('enabled') === false ) { |
|
115 | + if ($this->configuration->get('enabled') === false) { |
|
116 | 116 | |
117 | 117 | $this->logger->debug("Dispatcher disabled, shutting down gracefully."); |
118 | 118 | |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | |
131 | 131 | $cache = new ServerCache($this->cache); |
132 | 132 | |
133 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
133 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
134 | 134 | |
135 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()) ); |
|
135 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get())); |
|
136 | 136 | |
137 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
137 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
138 | 138 | |
139 | - if ( $cache->read($this->request, $this->response) ) { |
|
139 | + if ($cache->read($this->request, $this->response)) { |
|
140 | 140 | |
141 | 141 | return $this->shutdown(); |
142 | 142 | |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | |
165 | 165 | $this->logger->debug("Route acquired, type $route_type directed to $route_service"); |
166 | 166 | |
167 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
167 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
168 | 168 | |
169 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type) ); |
|
169 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type)); |
|
170 | 170 | |
171 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service) ); |
|
171 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service)); |
|
172 | 172 | |
173 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
173 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
174 | 174 | |
175 | 175 | // translate route to service |
176 | 176 | |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | |
201 | 201 | $params = $route->getParameter('headers'); |
202 | 202 | |
203 | - if ( !empty($params) && is_array($params) ) { |
|
203 | + if (!empty($params) && is_array($params)) { |
|
204 | 204 | |
205 | - foreach($params as $name=>$value) $this->response->headers->set($name, $value); |
|
205 | + foreach ($params as $name=>$value) $this->response->headers->set($name, $value); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | } |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | |
243 | 243 | $this->response->consolidate($this->request, $this->route); |
244 | 244 | |
245 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
245 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
246 | 246 | |
247 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get()) ); |
|
247 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get())); |
|
248 | 248 | |
249 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
249 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
250 | 250 | |
251 | 251 | $this->logger->debug("Composing return value"); |
252 | 252 |
@@ -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 |