@@ -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( |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | $this->extra = new Extra($this->logger); |
77 | 77 | |
78 | - $this->configuration = new Configuration( DefaultConfiguration::get() ); |
|
78 | + $this->configuration = new Configuration(DefaultConfiguration::get()); |
|
79 | 79 | |
80 | 80 | $this->configuration->merge($configuration); |
81 | 81 | |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | |
138 | 138 | public function dispatch() { |
139 | 139 | |
140 | - $this->events->emit( new DispatcherEvent($this) ); |
|
140 | + $this->events->emit(new DispatcherEvent($this)); |
|
141 | 141 | |
142 | - if ( $this->configuration()->get('enabled') === false ) { |
|
142 | + if ($this->configuration()->get('enabled') === false) { |
|
143 | 143 | |
144 | 144 | $status = $this->configuration()->get('disabled-status'); |
145 | 145 | |
@@ -153,11 +153,11 @@ discard block |
||
153 | 153 | |
154 | 154 | } |
155 | 155 | |
156 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
156 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
157 | 157 | |
158 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get()) ); |
|
158 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get())); |
|
159 | 159 | |
160 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
160 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
161 | 161 | |
162 | 162 | try { |
163 | 163 | |
@@ -165,21 +165,21 @@ discard block |
||
165 | 165 | |
166 | 166 | } catch (DispatcherException $de) { |
167 | 167 | |
168 | - $this->response()->status()->set( $de->getStatus() ); |
|
168 | + $this->response()->status()->set($de->getStatus()); |
|
169 | 169 | |
170 | - $this->response()->content()->set( $de->getMessage() ); |
|
170 | + $this->response()->content()->set($de->getMessage()); |
|
171 | 171 | |
172 | 172 | return $this->shutdown(); |
173 | 173 | |
174 | 174 | } |
175 | 175 | |
176 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
176 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
177 | 177 | |
178 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType()) ); |
|
178 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType())); |
|
179 | 179 | |
180 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService()) ); |
|
180 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService())); |
|
181 | 181 | |
182 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
182 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
183 | 183 | |
184 | 184 | // translate route to service |
185 | 185 | |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | |
190 | 190 | } catch (DispatcherException $de) { |
191 | 191 | |
192 | - $this->response()->status()->set( $de->getStatus() ); |
|
192 | + $this->response()->status()->set($de->getStatus()); |
|
193 | 193 | |
194 | - $this->response()->content()->set( $de->getMessage() ); |
|
194 | + $this->response()->content()->set($de->getMessage()); |
|
195 | 195 | |
196 | 196 | } |
197 | 197 | |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | |
215 | 215 | private function shutdown() { |
216 | 216 | |
217 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
217 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
218 | 218 | |
219 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get()) ); |
|
219 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get())); |
|
220 | 220 | |
221 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
221 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
222 | 222 | |
223 | 223 | $return = Processor::parse($this->configuration, $this->logger, $this->response); |
224 | 224 |
@@ -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; |
@@ -96,8 +96,9 @@ discard block |
||
96 | 96 | $this->response |
97 | 97 | ); |
98 | 98 | |
99 | + } else { |
|
100 | + return null; |
|
99 | 101 | } |
100 | - else return null; |
|
101 | 102 | |
102 | 103 | } |
103 | 104 | |
@@ -183,7 +184,9 @@ discard block |
||
183 | 184 | |
184 | 185 | if (preg_match('/' . $value['regex'] . '/', $bits[$key], $matches)) { |
185 | 186 | |
186 | - if (count($matches) == 1) $matches = $matches[0]; |
|
187 | + if (count($matches) == 1) { |
|
188 | + $matches = $matches[0]; |
|
189 | + } |
|
187 | 190 | |
188 | 191 | $this->request->query()->set($key, $matches); |
189 | 192 |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | |
219 | 219 | $routes = Yaml::parse($yaml); |
220 | 220 | |
221 | - if ( !empty($routes) ) { |
|
221 | + if (!empty($routes)) { |
|
222 | 222 | |
223 | - foreach( $routes as $name => $route ) { |
|
223 | + foreach ($routes as $name => $route) { |
|
224 | 224 | |
225 | 225 | $this->add($route['route'], $route['type'], $route['class'], $route['parameters']); |
226 | 226 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | foreach ($this->table->routes() as $regex => $value) { |
240 | 240 | |
241 | - if (preg_match("/" . $regex . "/", $path, $matches)) { |
|
241 | + if (preg_match("/".$regex."/", $path, $matches)) { |
|
242 | 242 | |
243 | 243 | $this->evalUri($value['query'], $matches); |
244 | 244 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | $this->classname = $value['class']; |
252 | 252 | $this->type = $value['type']; |
253 | 253 | $this->service = implode('.', $value['service']); |
254 | - $this->service = empty($this->service)?"default":$this->service; |
|
254 | + $this->service = empty($this->service) ? "default" : $this->service; |
|
255 | 255 | |
256 | 256 | return true; |
257 | 257 | |
@@ -265,13 +265,13 @@ discard block |
||
265 | 265 | |
266 | 266 | private function evalUri($parameters, $bits) { |
267 | 267 | |
268 | - $count = 0; |
|
268 | + $count = 0; |
|
269 | 269 | |
270 | 270 | foreach ($parameters as $key => $value) { |
271 | 271 | |
272 | 272 | if (isset($bits[$key])) { |
273 | 273 | |
274 | - if (preg_match('/^' . $value['regex'] . '$/', $bits[$key], $matches)) { |
|
274 | + if (preg_match('/^'.$value['regex'].'$/', $bits[$key], $matches)) { |
|
275 | 275 | |
276 | 276 | if (count($matches) == 1) $matches = $matches[0]; |
277 | 277 |
@@ -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) { |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | break; |
177 | 177 | |
178 | 178 | /** |
179 | - * @todo: how to get reverse allowed methods reference? |
|
180 | - */ |
|
179 | + * @todo: how to get reverse allowed methods reference? |
|
180 | + */ |
|
181 | 181 | // case 405: //Not allowed |
182 | 182 | // |
183 | 183 | // header('Allow: ' . $value, true, 405); |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | break; |
193 | 193 | |
194 | 194 | /** |
195 | - * @todo: how to get reverse allowed methods reference? |
|
196 | - */ |
|
195 | + * @todo: how to get reverse allowed methods reference? |
|
196 | + */ |
|
197 | 197 | // case 501: //Not implemented |
198 | 198 | // |
199 | 199 | // header('Allow: ' . $value, true, 501); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | header($_SERVER["SERVER_PROTOCOL"].' 204 No Content'); |
117 | 117 | header('Status: 204 No Content'); |
118 | - header('Content-Length: 0',true); |
|
118 | + header('Content-Length: 0', true); |
|
119 | 119 | |
120 | 120 | $return = null; |
121 | 121 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | case 303: //See Other |
128 | 128 | case 307: //Temporary Redirect |
129 | 129 | |
130 | - header("Location: ".$location->get(),true,$status); |
|
130 | + header("Location: ".$location->get(), true, $status); |
|
131 | 131 | |
132 | 132 | break; |
133 | 133 | |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | |
136 | 136 | $last_modified = $headers->get('Last-Modified'); |
137 | 137 | |
138 | - if ( is_null($last_modified) ) { |
|
138 | + if (is_null($last_modified)) { |
|
139 | 139 | |
140 | 140 | header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
141 | 141 | |
142 | - } else if ( is_int($last_modified) ) { |
|
142 | + } else if (is_int($last_modified)) { |
|
143 | 143 | |
144 | 144 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT', true, 304); |
145 | 145 |
@@ -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 |