@@ -209,6 +209,9 @@ |
||
209 | 209 | |
210 | 210 | } |
211 | 211 | |
212 | + /** |
|
213 | + * @param string[] $bits |
|
214 | + */ |
|
212 | 215 | private function evalUri($parameters, $bits) { |
213 | 216 | |
214 | 217 | $count = 0; |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | |
161 | 161 | $methods = $this->configuration->get('allowed-http-methods'); |
162 | 162 | |
163 | - if ( ( $methods != null || !empty($methods) ) && in_array($method, $methods) === false ) { |
|
163 | + if (($methods != null || !empty($methods)) && in_array($method, $methods) === false) { |
|
164 | 164 | |
165 | 165 | throw new DispatcherException("Method not allowed", 0, null, 405, array( |
166 | - "Allow" => implode(",",$methods) |
|
166 | + "Allow" => implode(",", $methods) |
|
167 | 167 | )); |
168 | 168 | |
169 | 169 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | $methods = $service->getImplementedMethods(); |
194 | 194 | |
195 | - if ( in_array($method, $methods) ) { |
|
195 | + if (in_array($method, $methods)) { |
|
196 | 196 | |
197 | 197 | $callable = $service->getMethod($method); |
198 | 198 | |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | |
233 | 233 | $routes = Yaml::parse($yaml); |
234 | 234 | |
235 | - if ( !empty($routes) ) { |
|
235 | + if (!empty($routes)) { |
|
236 | 236 | |
237 | - foreach( $routes as $name => $route ) { |
|
237 | + foreach ($routes as $name => $route) { |
|
238 | 238 | |
239 | 239 | $this->add($route['route'], $route['type'], $route['class'], $route['parameters']); |
240 | 240 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | foreach ($this->table->routes() as $regex => $value) { |
254 | 254 | |
255 | 255 | // The current uri is checked against all the global regular expressions associated with the routes |
256 | - if (preg_match("/" . $regex . "/", $path, $matches)) { |
|
256 | + if (preg_match("/".$regex."/", $path, $matches)) { |
|
257 | 257 | |
258 | 258 | /* If a route is matched, all the bits of the route string are evalued in order to create |
259 | 259 | * new query parameters which will be available for the service class |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | $this->classname = $value['class']; |
271 | 271 | $this->type = $value['type']; |
272 | 272 | $this->service = implode('.', $value['service']); |
273 | - $this->service = empty($this->service)?"default":$this->service; |
|
273 | + $this->service = empty($this->service) ? "default" : $this->service; |
|
274 | 274 | |
275 | 275 | return true; |
276 | 276 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | |
285 | 285 | private function evalUri($parameters, $bits) { |
286 | 286 | |
287 | - $count = 0; |
|
287 | + $count = 0; |
|
288 | 288 | |
289 | 289 | // Because of the nature of the global regular expression, all the bits of the matched route are associated with a parameter key |
290 | 290 | foreach ($parameters as $key => $value) { |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | /* if it's available a bit associated with the parameter name, it is compared against |
294 | 294 | * it's regular expression in order to extrect backreferences |
295 | 295 | */ |
296 | - if (preg_match('/^' . $value['regex'] . '$/', $bits[$key], $matches)) { |
|
296 | + if (preg_match('/^'.$value['regex'].'$/', $bits[$key], $matches)) { |
|
297 | 297 | |
298 | 298 | if (count($matches) == 1) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
299 | 299 |
@@ -113,8 +113,9 @@ discard block |
||
113 | 113 | $this->extra |
114 | 114 | ); |
115 | 115 | |
116 | + } else { |
|
117 | + return null; |
|
116 | 118 | } |
117 | - else return null; |
|
118 | 119 | |
119 | 120 | } |
120 | 121 | |
@@ -250,7 +251,9 @@ discard block |
||
250 | 251 | |
251 | 252 | $routes = $this->cache->get("dispatcher_routes"); |
252 | 253 | |
253 | - if (is_null($routes)) return null; |
|
254 | + if (is_null($routes)) { |
|
255 | + return null; |
|
256 | + } |
|
254 | 257 | |
255 | 258 | $this->table->routes($routes); |
256 | 259 | |
@@ -317,7 +320,10 @@ discard block |
||
317 | 320 | */ |
318 | 321 | if (preg_match('/^' . $value['regex'] . '$/', $bits[$key], $matches)) { |
319 | 322 | |
320 | - if (count($matches) == 1) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
|
323 | + if (count($matches) == 1) { |
|
324 | + $matches = $matches[0]; |
|
325 | + } |
|
326 | + // This is the case where no backreferences are present or available. |
|
321 | 327 | |
322 | 328 | // The extracted value (with any backreference available) is added to the query parameters. |
323 | 329 | $this->request->query()->set($key, $matches); |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | |
27 | 27 | protected $parameters = array(); |
28 | 28 | |
29 | - final public function get($parameter=null) { |
|
29 | + final public function get($parameter = null) { |
|
30 | 30 | |
31 | - if ( is_null($parameter) ) return $this->parameters; |
|
31 | + if (is_null($parameter)) return $this->parameters; |
|
32 | 32 | |
33 | - else if ( array_key_exists($parameter, $this->parameters) ) { |
|
33 | + else if (array_key_exists($parameter, $this->parameters)) { |
|
34 | 34 | |
35 | 35 | return $this->parameters[$parameter]; |
36 | 36 | |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | |
51 | 51 | final public function unset($parameter = null) { |
52 | 52 | |
53 | - if ( is_null($parameter) ) { |
|
53 | + if (is_null($parameter)) { |
|
54 | 54 | |
55 | 55 | $this->parameters = array(); |
56 | 56 | |
57 | 57 | return true; |
58 | 58 | |
59 | - } else if ( array_key_exists($parameter, $this->parameters) ) { |
|
59 | + } else if (array_key_exists($parameter, $this->parameters)) { |
|
60 | 60 | |
61 | 61 | unset($this->parameters[$parameter]); |
62 | 62 |
@@ -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) { |
@@ -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 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public function set($content) { |
42 | 42 | |
43 | - if ( !is_scalar($content) ) { |
|
43 | + if (!is_scalar($content)) { |
|
44 | 44 | |
45 | 45 | throw new Exception("Invalid HTTP content"); |
46 | 46 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | public function type($type = null) { |
56 | 56 | |
57 | - if ( is_null($type) ) { |
|
57 | + if (is_null($type)) { |
|
58 | 58 | |
59 | 59 | return $this->type; |
60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | public function charset($charset = null) { |
70 | 70 | |
71 | - if ( is_null($charset) ) { |
|
71 | + if (is_null($charset)) { |
|
72 | 72 | |
73 | 73 | return $this->charset; |
74 | 74 |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | public function set($code) { |
87 | 87 | |
88 | - if ( !array_key_exists($code, $this->http_status_codes) ) { |
|
88 | + if (!array_key_exists($code, $this->http_status_codes)) { |
|
89 | 89 | |
90 | 90 | throw new Exception("Invalid HTTP Status Code"); |
91 | 91 | |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | - public function description($code=null) { |
|
100 | + public function description($code = null) { |
|
101 | 101 | |
102 | - if ( is_null($code) || !array_key_exists($code, $this->http_status_codes) ) { |
|
102 | + if (is_null($code) || !array_key_exists($code, $this->http_status_codes)) { |
|
103 | 103 | |
104 | 104 | $message = $this->http_status_codes[$this->status_code]; |
105 | 105 |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | $supported_methods = $this->configuration()->get('dispatcher-supported-methods'); |
96 | 96 | |
97 | - if ( method_exists($this, 'any') ) { |
|
97 | + if (method_exists($this, 'any')) { |
|
98 | 98 | |
99 | 99 | return $supported_methods; |
100 | 100 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | $implemented_methods = array(); |
104 | 104 | |
105 | - foreach ( $supported_methods as $method ) { |
|
105 | + foreach ($supported_methods as $method) { |
|
106 | 106 | |
107 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method); |
|
107 | + if (method_exists($this, strtolower($method))) array_push($implemented_methods, $method); |
|
108 | 108 | |
109 | 109 | } |
110 | 110 | |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | */ |
119 | 119 | final public function getMethod($method) { |
120 | 120 | |
121 | - if ( method_exists($this, strtolower($method)) ) { |
|
121 | + if (method_exists($this, strtolower($method))) { |
|
122 | 122 | |
123 | 123 | return strtolower($method); |
124 | 124 | |
125 | - } else if ( method_exists($this, strtolower('any')) ) { |
|
125 | + } else if (method_exists($this, strtolower('any'))) { |
|
126 | 126 | |
127 | 127 | return 'any'; |
128 | 128 |
@@ -104,7 +104,9 @@ |
||
104 | 104 | |
105 | 105 | foreach ( $supported_methods as $method ) { |
106 | 106 | |
107 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method); |
|
107 | + if ( method_exists($this, strtolower($method)) ) { |
|
108 | + array_push($implemented_methods,$method); |
|
109 | + } |
|
108 | 110 | |
109 | 111 | } |
110 | 112 |
@@ -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 |