@@ -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 |
@@ -46,8 +46,9 @@ discard block |
||
46 | 46 | "query" => array() |
47 | 47 | ); |
48 | 48 | |
49 | - if (count($folders) > 1 && empty($folders[0])) |
|
50 | - array_shift($folders); |
|
49 | + if (count($folders) > 1 && empty($folders[0])) { |
|
50 | + array_shift($folders); |
|
51 | + } |
|
51 | 52 | |
52 | 53 | if (count($folders) == 1 && empty($folders[0])) { |
53 | 54 | $this->def_route = $value; |
@@ -67,7 +68,9 @@ discard block |
||
67 | 68 | |
68 | 69 | $regex = $this->readpath($folders); |
69 | 70 | |
70 | - if (isset($this->routes[$regex])) unset($this->routes[$regex]); |
|
71 | + if (isset($this->routes[$regex])) { |
|
72 | + unset($this->routes[$regex]); |
|
73 | + } |
|
71 | 74 | |
72 | 75 | } |
73 | 76 |
@@ -124,14 +124,14 @@ |
||
124 | 124 | $value = preg_replace('/(?<!\\)\((?!\?)/', '(?:', $value); |
125 | 125 | $value = preg_replace('/\.([\*\+])(?!\?)/', '.\${1}?', $value); |
126 | 126 | |
127 | - $param_regex .= '(?P<' . $key . '>' . $value . ')' . (($field_required)?'{1}':'?'); |
|
127 | + $param_regex .= '(?P<'.$key.'>'.$value.')'.(($field_required) ? '{1}' : '?'); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
131 | 131 | $this->readpath( |
132 | 132 | $folders, |
133 | 133 | $value, |
134 | - $regex.'(?:\/'.$param_regex.')'. (($param_required)?'{1}':'?') |
|
134 | + $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?') |
|
135 | 135 | ); |
136 | 136 | |
137 | 137 | } else { |
@@ -47,6 +47,10 @@ discard block |
||
47 | 47 | |
48 | 48 | private $table = array(); |
49 | 49 | |
50 | + /** |
|
51 | + * @param \Comodojo\Dispatcher\Components\Configuration $routing_table |
|
52 | + * @param \Comodojo\Cache\CacheManager $logger |
|
53 | + */ |
|
50 | 54 | public function __construct($routing_table, $configuration = null, $logger = null, $cache = null) { |
51 | 55 | |
52 | 56 | parent::__construct($configuration, $logger); |
@@ -173,6 +177,9 @@ discard block |
||
173 | 177 | |
174 | 178 | } |
175 | 179 | |
180 | + /** |
|
181 | + * @param string[] $bits |
|
182 | + */ |
|
176 | 183 | private function evalUri($parameters, $bits) { |
177 | 184 | |
178 | 185 | $count = 0; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | foreach ($this->table as $regex => $value) { |
151 | 151 | |
152 | - if (preg_match("/" . $regex . "/", $path, $matches)) { |
|
152 | + if (preg_match("/".$regex."/", $path, $matches)) { |
|
153 | 153 | |
154 | 154 | $this->evalUri($value['query'], $matches); |
155 | 155 | |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | |
176 | 176 | private function evalUri($parameters, $bits) { |
177 | 177 | |
178 | - $count = 0; |
|
178 | + $count = 0; |
|
179 | 179 | |
180 | 180 | foreach ($parameters as $key => $value) { |
181 | 181 | |
182 | 182 | if (isset($bits[$key])) { |
183 | 183 | |
184 | - if (preg_match('/' . $value['regex'] . '/', $bits[$key], $matches)) { |
|
184 | + if (preg_match('/'.$value['regex'].'/', $bits[$key], $matches)) { |
|
185 | 185 | |
186 | 186 | if (count($matches) == 1) $matches = $matches[0]; |
187 | 187 |
@@ -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 |
@@ -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 |
@@ -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( |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | $this->logger = is_null($logger) ? DispatcherLogger::create($this->configuration) : $logger; |
75 | 75 | |
76 | - $this->cache = is_null($cache) ? new CacheManager( CacheManager::PICK_FIRST, $this->logger ) : $cache; |
|
76 | + $this->cache = is_null($cache) ? new CacheManager(CacheManager::PICK_FIRST, $this->logger) : $cache; |
|
77 | 77 | |
78 | 78 | $this->request = new Request($this->configuration, $this->logger); |
79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | $this->extra = new Extra($this->logger); |
85 | 85 | |
86 | - $this->router->load( $routing_table ); |
|
86 | + $this->router->load($routing_table); |
|
87 | 87 | |
88 | 88 | } |
89 | 89 | |
@@ -131,33 +131,33 @@ discard block |
||
131 | 131 | |
132 | 132 | public function dispatch() { |
133 | 133 | |
134 | - $this->events->emit( new DispatcherEvent($this) ); |
|
134 | + $this->events->emit(new DispatcherEvent($this)); |
|
135 | 135 | |
136 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
136 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
137 | 137 | |
138 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get()) ); |
|
138 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get())); |
|
139 | 139 | |
140 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
140 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
141 | 141 | |
142 | 142 | $this->router->route($this->request); |
143 | 143 | |
144 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
144 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
145 | 145 | |
146 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType()) ); |
|
146 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType())); |
|
147 | 147 | |
148 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService()) ); |
|
148 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService())); |
|
149 | 149 | |
150 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
150 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
151 | 151 | |
152 | 152 | // translate route to service |
153 | 153 | |
154 | 154 | $this->router->compose($this->response); |
155 | 155 | |
156 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
156 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
157 | 157 | |
158 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get()) ); |
|
158 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get())); |
|
159 | 159 | |
160 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
160 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
161 | 161 | |
162 | 162 | $return = Processor::parse($this->configuration, $this->logger, $this->response); |
163 | 163 |