@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | * @param ResponseInterface $response |
| 50 | 50 | * @param Route $route |
| 51 | 51 | */ |
| 52 | - public function __construct(RouteCollection $collection,ResponseInterface $response = null,Route $route = null) |
|
| 52 | + public function __construct(RouteCollection $collection, ResponseInterface $response = null, Route $route = null) |
|
| 53 | 53 | { |
| 54 | 54 | $this->collection = $collection; |
| 55 | - $this->response = is_null($response)? new Response() : $response; |
|
| 55 | + $this->response = is_null($response) ? new Response() : $response; |
|
| 56 | 56 | $this->response->setStatusCode(404); |
| 57 | - $this->route = is_null($route)? new Route() : $route; |
|
| 58 | - $this->config['di'] = function($class){ |
|
| 57 | + $this->route = is_null($route) ? new Route() : $route; |
|
| 58 | + $this->config['di'] = function($class) { |
|
| 59 | 59 | return new $class; |
| 60 | 60 | }; |
| 61 | 61 | } |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | /** |
| 80 | 80 | * @param object|array $matcher |
| 81 | 81 | */ |
| 82 | - public function setMatcher($matcher){ |
|
| 83 | - if(is_object($matcher)) |
|
| 82 | + public function setMatcher($matcher) { |
|
| 83 | + if (is_object($matcher)) |
|
| 84 | 84 | $matcher = [$matcher]; |
| 85 | 85 | $this->matcher = $matcher; |
| 86 | 86 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | /** |
| 89 | 89 | * @param string $matcher |
| 90 | 90 | */ |
| 91 | - public function addMatcher($matcher){ |
|
| 91 | + public function addMatcher($matcher) { |
|
| 92 | 92 | $this->matcher[] = $matcher; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | { |
| 114 | 114 | if (is_null($url)) |
| 115 | 115 | $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
| 116 | - $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
|
| 116 | + $this->route->setUrl('/'.trim(explode('?', $url)[0], '/')); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function callTarget() |
| 135 | 135 | { |
| 136 | - $target = is_array($this->route->getTarget('dispatcher'))?$this->route->getTarget('dispatcher'):[$this->route->getTarget('dispatcher')]; |
|
| 137 | - if(!empty($target)) { |
|
| 138 | - foreach($target as $call) { |
|
| 136 | + $target = is_array($this->route->getTarget('dispatcher')) ? $this->route->getTarget('dispatcher') : [$this->route->getTarget('dispatcher')]; |
|
| 137 | + if (!empty($target)) { |
|
| 138 | + foreach ($target as $call) { |
|
| 139 | 139 | $this->dispatcher = new $call($this->route, $this->response); |
| 140 | 140 | call_user_func([$this->dispatcher, 'call']); |
| 141 | 141 | } |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) { |
| 171 | 171 | $this->route->setCallback($this->route->getDetail()['response_templates'][$code]); |
| 172 | 172 | $matcher = null; |
| 173 | - foreach($this->matcher as $instance) if($instance instanceof ArrayMatcher) $matcher = $instance; |
|
| 174 | - if(is_null($matcher))$matcher = new ArrayMatcher($this); |
|
| 173 | + foreach ($this->matcher as $instance) if ($instance instanceof ArrayMatcher) $matcher = $instance; |
|
| 174 | + if (is_null($matcher))$matcher = new ArrayMatcher($this); |
|
| 175 | 175 | foreach (call_user_func([$matcher, 'getResolver']) as $match) |
| 176 | - if (is_array($target = call_user_func_array([$matcher, $match], [$this->route->getCallback()]))){ |
|
| 177 | - call_user_func_array([$matcher, 'setTarget'],[$target]); |
|
| 176 | + if (is_array($target = call_user_func_array([$matcher, $match], [$this->route->getCallback()]))) { |
|
| 177 | + call_user_func_array([$matcher, 'setTarget'], [$target]); |
|
| 178 | 178 | $this->callTarget(); |
| 179 | 179 | break; |
| 180 | 180 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * Class Response |
| 8 | 8 | * @package JetFire\Routing |
| 9 | 9 | */ |
| 10 | -class Response implements ResponseInterface{ |
|
| 10 | +class Response implements ResponseInterface { |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * @var array |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | public static $statusTexts = array( |
| 54 | 54 | 100 => 'Continue', |
| 55 | 55 | 101 => 'Switching Protocols', |
| 56 | - 102 => 'Processing', // RFC2518 |
|
| 56 | + 102 => 'Processing', // RFC2518 |
|
| 57 | 57 | 200 => 'OK', |
| 58 | 58 | 201 => 'Created', |
| 59 | 59 | 202 => 'Accepted', |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | 204 => 'No Content', |
| 62 | 62 | 205 => 'Reset Content', |
| 63 | 63 | 206 => 'Partial Content', |
| 64 | - 207 => 'Multi-Status', // RFC4918 |
|
| 65 | - 208 => 'Already Reported', // RFC5842 |
|
| 66 | - 226 => 'IM Used', // RFC3229 |
|
| 64 | + 207 => 'Multi-Status', // RFC4918 |
|
| 65 | + 208 => 'Already Reported', // RFC5842 |
|
| 66 | + 226 => 'IM Used', // RFC3229 |
|
| 67 | 67 | 300 => 'Multiple Choices', |
| 68 | 68 | 301 => 'Moved Permanently', |
| 69 | 69 | 302 => 'Found', |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | 304 => 'Not Modified', |
| 72 | 72 | 305 => 'Use Proxy', |
| 73 | 73 | 307 => 'Temporary Redirect', |
| 74 | - 308 => 'Permanent Redirect', // RFC7238 |
|
| 74 | + 308 => 'Permanent Redirect', // RFC7238 |
|
| 75 | 75 | 400 => 'Bad Request', |
| 76 | 76 | 401 => 'Unauthorized', |
| 77 | 77 | 402 => 'Payment Required', |
@@ -90,26 +90,26 @@ discard block |
||
| 90 | 90 | 415 => 'Unsupported Media Type', |
| 91 | 91 | 416 => 'Range Not Satisfiable', |
| 92 | 92 | 417 => 'Expectation Failed', |
| 93 | - 418 => 'I\'m a teapot', // RFC2324 |
|
| 94 | - 422 => 'Unprocessable Entity', // RFC4918 |
|
| 95 | - 423 => 'Locked', // RFC4918 |
|
| 96 | - 424 => 'Failed Dependency', // RFC4918 |
|
| 97 | - 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
|
| 98 | - 426 => 'Upgrade Required', // RFC2817 |
|
| 99 | - 428 => 'Precondition Required', // RFC6585 |
|
| 100 | - 429 => 'Too Many Requests', // RFC6585 |
|
| 101 | - 431 => 'Request Header Fields Too Large', // RFC6585 |
|
| 93 | + 418 => 'I\'m a teapot', // RFC2324 |
|
| 94 | + 422 => 'Unprocessable Entity', // RFC4918 |
|
| 95 | + 423 => 'Locked', // RFC4918 |
|
| 96 | + 424 => 'Failed Dependency', // RFC4918 |
|
| 97 | + 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
|
| 98 | + 426 => 'Upgrade Required', // RFC2817 |
|
| 99 | + 428 => 'Precondition Required', // RFC6585 |
|
| 100 | + 429 => 'Too Many Requests', // RFC6585 |
|
| 101 | + 431 => 'Request Header Fields Too Large', // RFC6585 |
|
| 102 | 102 | 500 => 'Internal Server Error', |
| 103 | 103 | 501 => 'Not Implemented', |
| 104 | 104 | 502 => 'Bad Gateway', |
| 105 | 105 | 503 => 'Service Unavailable', |
| 106 | 106 | 504 => 'Gateway Timeout', |
| 107 | 107 | 505 => 'HTTP Version Not Supported', |
| 108 | - 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 |
|
| 109 | - 507 => 'Insufficient Storage', // RFC4918 |
|
| 110 | - 508 => 'Loop Detected', // RFC5842 |
|
| 111 | - 510 => 'Not Extended', // RFC2774 |
|
| 112 | - 511 => 'Network Authentication Required', // RFC6585 |
|
| 108 | + 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 |
|
| 109 | + 507 => 'Insufficient Storage', // RFC4918 |
|
| 110 | + 508 => 'Loop Detected', // RFC5842 |
|
| 111 | + 510 => 'Not Extended', // RFC2774 |
|
| 112 | + 511 => 'Network Authentication Required', // RFC6585 |
|
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function sendHeaders() |
| 168 | 168 | { |
| 169 | - foreach($this->headers as $key => $content) |
|
| 169 | + foreach ($this->headers as $key => $content) |
|
| 170 | 170 | header($key.' : '.$content); |
| 171 | 171 | http_response_code($this->getStatusCode()); |
| 172 | 172 | return $this; |