| @@ -28,17 +28,17 @@ discard block | ||
| 28 | 28 | |
| 29 | 29 |      final public function get($header = null) { | 
| 30 | 30 | |
| 31 | - if ( is_null($header) ) return $this->headers; | |
| 31 | + if (is_null($header)) return $this->headers; | |
| 32 | 32 | |
| 33 | - else if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; | |
| 33 | + else if (array_key_exists($header, $this->headers)) return $this->headers[$header]; | |
| 34 | 34 | |
| 35 | 35 | else return null; | 
| 36 | 36 | |
| 37 | 37 | } | 
| 38 | 38 | |
| 39 | -    final public function set($header, $value=null) { | |
| 39 | +    final public function set($header, $value = null) { | |
| 40 | 40 | |
| 41 | -        if ( is_null($value) ) { | |
| 41 | +        if (is_null($value)) { | |
| 42 | 42 | |
| 43 | 43 |              $header = explode(":", $header); | 
| 44 | 44 | |
| @@ -56,13 +56,13 @@ discard block | ||
| 56 | 56 | |
| 57 | 57 |      final public function unset($header = null) { | 
| 58 | 58 | |
| 59 | -        if ( is_null($header) ) { | |
| 59 | +        if (is_null($header)) { | |
| 60 | 60 | |
| 61 | 61 | $this->headers = array(); | 
| 62 | 62 | |
| 63 | 63 | return true; | 
| 64 | 64 | |
| 65 | -        } else if ( array_key_exists($header, $this->headers) ) { | |
| 65 | +        } else if (array_key_exists($header, $this->headers)) { | |
| 66 | 66 | |
| 67 | 67 | unset($this->headers[$header]); | 
| 68 | 68 | |
| @@ -28,11 +28,13 @@ | ||
| 28 | 28 | |
| 29 | 29 |      final public function get($header = null) { | 
| 30 | 30 | |
| 31 | - if ( is_null($header) ) return $this->headers; | |
| 32 | - | |
| 33 | - else if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; | |
| 34 | - | |
| 35 | - else return null; | |
| 31 | +        if ( is_null($header) ) { | |
| 32 | + return $this->headers; | |
| 33 | +        } else if ( array_key_exists($header, $this->headers) ) { | |
| 34 | + return $this->headers[$header]; | |
| 35 | +        } else { | |
| 36 | + return null; | |
| 37 | + } | |
| 36 | 38 | |
| 37 | 39 | } | 
| 38 | 40 | |
| @@ -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 | |
| @@ -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,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 | |
| @@ -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 | |
| @@ -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; | 
| @@ -188,7 +188,7 @@ discard block | ||
| 188 | 188 | |
| 189 | 189 |          foreach ($this->table->routes() as $regex => $value) { | 
| 190 | 190 | |
| 191 | -            if (preg_match("/" . $regex . "/", $path, $matches)) { | |
| 191 | +            if (preg_match("/".$regex."/", $path, $matches)) { | |
| 192 | 192 | |
| 193 | 193 | $this->evalUri($value['query'], $matches); | 
| 194 | 194 | |
| @@ -201,7 +201,7 @@ discard block | ||
| 201 | 201 | $this->classname = $value['class']; | 
| 202 | 202 | $this->type = $value['type']; | 
| 203 | 203 |                  $this->service    = implode('.', $value['service']); | 
| 204 | - $this->service = empty($this->service)?"default":$this->service; | |
| 204 | + $this->service = empty($this->service) ? "default" : $this->service; | |
| 205 | 205 | |
| 206 | 206 | return true; | 
| 207 | 207 | |
| @@ -215,13 +215,13 @@ discard block | ||
| 215 | 215 | |
| 216 | 216 |      private function evalUri($parameters, $bits) { | 
| 217 | 217 | |
| 218 | - $count = 0; | |
| 218 | + $count = 0; | |
| 219 | 219 | |
| 220 | 220 |          foreach ($parameters as $key => $value) { | 
| 221 | 221 | |
| 222 | 222 |              if (isset($bits[$key])) { | 
| 223 | 223 | |
| 224 | -                if (preg_match('/^' . $value['regex'] . '$/', $bits[$key], $matches)) { | |
| 224 | +                if (preg_match('/^'.$value['regex'].'$/', $bits[$key], $matches)) { | |
| 225 | 225 | |
| 226 | 226 | if (count($matches) == 1) $matches = $matches[0]; | 
| 227 | 227 | |
| @@ -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( | 
| @@ -144,9 +144,9 @@ discard block | ||
| 144 | 144 | |
| 145 | 145 |      public function dispatch() { | 
| 146 | 146 | |
| 147 | - $this->events->emit( new DispatcherEvent($this) ); | |
| 147 | + $this->events->emit(new DispatcherEvent($this)); | |
| 148 | 148 | |
| 149 | -        if ( $this->configuration()->get('dispatcher-enabled') === false ) { | |
| 149 | +        if ($this->configuration()->get('dispatcher-enabled') === false) { | |
| 150 | 150 | |
| 151 | 151 |              $status = $this->configuration()->get('dispatcher-disabled-status'); | 
| 152 | 152 | |
| @@ -160,11 +160,11 @@ discard block | ||
| 160 | 160 | |
| 161 | 161 | } | 
| 162 | 162 | |
| 163 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); | |
| 163 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); | |
| 164 | 164 | |
| 165 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get()) ); | |
| 165 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get())); | |
| 166 | 166 | |
| 167 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); | |
| 167 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); | |
| 168 | 168 | |
| 169 | 169 |          try { | 
| 170 | 170 | |
| @@ -172,21 +172,21 @@ discard block | ||
| 172 | 172 | |
| 173 | 173 |          } catch (DispatcherException $de) { | 
| 174 | 174 | |
| 175 | - $this->response()->status()->set( $de->getStatus() ); | |
| 175 | + $this->response()->status()->set($de->getStatus()); | |
| 176 | 176 | |
| 177 | - $this->response()->content()->set( $de->getMessage() ); | |
| 177 | + $this->response()->content()->set($de->getMessage()); | |
| 178 | 178 | |
| 179 | 179 | return $this->shutdown(); | 
| 180 | 180 | |
| 181 | 181 | } | 
| 182 | 182 | |
| 183 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); | |
| 183 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); | |
| 184 | 184 | |
| 185 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType()) ); | |
| 185 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType())); | |
| 186 | 186 | |
| 187 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService()) ); | |
| 187 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService())); | |
| 188 | 188 | |
| 189 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); | |
| 189 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); | |
| 190 | 190 | |
| 191 | 191 | // translate route to service | 
| 192 | 192 | |
| @@ -196,9 +196,9 @@ discard block | ||
| 196 | 196 | |
| 197 | 197 |          } catch (DispatcherException $de) { | 
| 198 | 198 | |
| 199 | - $this->response()->status()->set( $de->getStatus() ); | |
| 199 | + $this->response()->status()->set($de->getStatus()); | |
| 200 | 200 | |
| 201 | - $this->response()->content()->set( $de->getMessage() ); | |
| 201 | + $this->response()->content()->set($de->getMessage()); | |
| 202 | 202 | |
| 203 | 203 | } | 
| 204 | 204 | |
| @@ -221,11 +221,11 @@ discard block | ||
| 221 | 221 | |
| 222 | 222 |      private function shutdown() { | 
| 223 | 223 | |
| 224 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); | |
| 224 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); | |
| 225 | 225 | |
| 226 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get()) ); | |
| 226 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get())); | |
| 227 | 227 | |
| 228 | -        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); | |
| 228 | +        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); | |
| 229 | 229 | |
| 230 | 230 | $return = Processor::parse($this->configuration, $this->logger, $this->response); | 
| 231 | 231 | |