@@ -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 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | $this->events = new Emitter(); |
| 64 | 64 | |
| 65 | - $this->cache = new CacheManager( CacheManager::PICK_FIRST ); |
|
| 65 | + $this->cache = new CacheManager(CacheManager::PICK_FIRST); |
|
| 66 | 66 | |
| 67 | 67 | $this->request = new Request($this->configuration, $this->logger); |
| 68 | 68 | |
@@ -110,33 +110,33 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | public function dispatch() { |
| 112 | 112 | |
| 113 | - $this->events->emit( new DispatcherEvent($this) ); |
|
| 113 | + $this->events->emit(new DispatcherEvent($this)); |
|
| 114 | 114 | |
| 115 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
| 115 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
| 116 | 116 | |
| 117 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get()) ); |
|
| 117 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get())); |
|
| 118 | 118 | |
| 119 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
| 119 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
| 120 | 120 | |
| 121 | 121 | $this->router->route($this->request); |
| 122 | 122 | |
| 123 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
| 123 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
| 124 | 124 | |
| 125 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType()) ); |
|
| 125 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType())); |
|
| 126 | 126 | |
| 127 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService()) ); |
|
| 127 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService())); |
|
| 128 | 128 | |
| 129 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
| 129 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
| 130 | 130 | |
| 131 | 131 | // translate route to service |
| 132 | 132 | |
| 133 | 133 | $this->router->compose($this->response); |
| 134 | 134 | |
| 135 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
| 135 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
| 136 | 136 | |
| 137 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get()) ); |
|
| 137 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get())); |
|
| 138 | 138 | |
| 139 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
| 139 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
| 140 | 140 | |
| 141 | 141 | $return = Processor::parse($this->configuration, $this->logger, $this->response); |
| 142 | 142 | |
@@ -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 | |