@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @param Route $route |
38 | 38 | */ |
39 | - public function __construct(Route $route,ResponseInterface $response) |
|
39 | + public function __construct(Route $route, ResponseInterface $response) |
|
40 | 40 | { |
41 | 41 | $this->route = $route; |
42 | 42 | $this->response = $response; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route])); |
54 | 54 | else { |
55 | 55 | ob_start(); |
56 | - if(isset($this->route->getTarget()['data']))extract($this->route->getTarget('data')); |
|
56 | + if (isset($this->route->getTarget()['data']))extract($this->route->getTarget('data')); |
|
57 | 57 | require($this->route->getTarget('template')); |
58 | 58 | $this->response->setContent(ob_get_clean()); |
59 | 59 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * @param $extension |
64 | 64 | */ |
65 | - public function setContentType($extension){ |
|
65 | + public function setContentType($extension) { |
|
66 | 66 | $this->response->setStatusCode(200); |
67 | 67 | isset($this->types[$extension]) |
68 | 68 | ? $this->response->setHeaders(['Content-Type' => $this->types[$extension]]) |
@@ -47,13 +47,16 @@ |
||
47 | 47 | */ |
48 | 48 | public function call() |
49 | 49 | { |
50 | - if ($this->response->getStatusCode() == 202) |
|
51 | - $this->setContentType($this->route->getTarget('extension')); |
|
52 | - if (isset($this->route->getTarget('callback')[$this->route->getTarget('extension')])) |
|
53 | - $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route])); |
|
54 | - else { |
|
50 | + if ($this->response->getStatusCode() == 202) { |
|
51 | + $this->setContentType($this->route->getTarget('extension')); |
|
52 | + } |
|
53 | + if (isset($this->route->getTarget('callback')[$this->route->getTarget('extension')])) { |
|
54 | + $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route])); |
|
55 | + } else { |
|
55 | 56 | ob_start(); |
56 | - if(isset($this->route->getTarget()['data']))extract($this->route->getTarget('data')); |
|
57 | + if(isset($this->route->getTarget()['data'])) { |
|
58 | + extract($this->route->getTarget('data')); |
|
59 | + } |
|
57 | 60 | require($this->route->getTarget('template')); |
58 | 61 | $this->response->setContent(ob_get_clean()); |
59 | 62 | } |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | * @param ResponseInterface $response |
47 | 47 | * @param Route $route |
48 | 48 | */ |
49 | - public function __construct(RouteCollection $collection,ResponseInterface $response = null,Route $route = null) |
|
49 | + public function __construct(RouteCollection $collection, ResponseInterface $response = null, Route $route = null) |
|
50 | 50 | { |
51 | 51 | $this->collection = $collection; |
52 | - $this->response = is_null($response)? new Response() : $response; |
|
52 | + $this->response = is_null($response) ? new Response() : $response; |
|
53 | 53 | $this->response->setStatusCode(404); |
54 | - $this->route = is_null($route)? new Route() : $route; |
|
55 | - $this->config['di'] = function($class){ |
|
54 | + $this->route = is_null($route) ? new Route() : $route; |
|
55 | + $this->config['di'] = function($class) { |
|
56 | 56 | return new $class; |
57 | 57 | }; |
58 | 58 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | /** |
77 | 77 | * @param string $matcher |
78 | 78 | */ |
79 | - public function addMatcher($matcher){ |
|
79 | + public function addMatcher($matcher) { |
|
80 | 80 | $this->config['matcher'][] = $matcher; |
81 | 81 | } |
82 | 82 | |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function callTarget() |
124 | 124 | { |
125 | - $target = is_array($this->route->getTarget('dispatcher'))?$this->route->getTarget('dispatcher'):[$this->route->getTarget('dispatcher')]; |
|
126 | - if(!empty($target)) { |
|
127 | - foreach($target as $call) { |
|
125 | + $target = is_array($this->route->getTarget('dispatcher')) ? $this->route->getTarget('dispatcher') : [$this->route->getTarget('dispatcher')]; |
|
126 | + if (!empty($target)) { |
|
127 | + foreach ($target as $call) { |
|
128 | 128 | $this->dispatcher = new $call($this->route, $this->response); |
129 | 129 | call_user_func([$this->dispatcher, 'call']); |
130 | 130 | } |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | { |
159 | 159 | if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) { |
160 | 160 | $this->route->setCallback($this->route->getDetail()['response_templates'][$code]); |
161 | - if(!isset($this->config['matcherInstance'])) |
|
161 | + if (!isset($this->config['matcherInstance'])) |
|
162 | 162 | foreach ($this->config['matcher'] as $matcher) |
163 | 163 | $this->config['matcherInstance'][$matcher] = new $matcher($this); |
164 | - foreach($this->config['matcherInstance'] as $instance) { |
|
164 | + foreach ($this->config['matcherInstance'] as $instance) { |
|
165 | 165 | foreach (call_user_func([$instance, 'getMatcher']) as $match) |
166 | - if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
167 | - call_user_func_array([$instance, 'setTarget'],[$target]); |
|
166 | + if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))) { |
|
167 | + call_user_func_array([$instance, 'setTarget'], [$target]); |
|
168 | 168 | $this->callTarget(); |
169 | 169 | break; |
170 | 170 | } |
@@ -86,7 +86,9 @@ discard block |
||
86 | 86 | public function run() |
87 | 87 | { |
88 | 88 | $this->setUrl(); |
89 | - if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath(); |
|
89 | + if ($this->config['generateRoutesPath']) { |
|
90 | + $this->collection->generateRoutesPath(); |
|
91 | + } |
|
90 | 92 | if ($this->match()) { |
91 | 93 | $this->handle(); |
92 | 94 | $this->callTarget(); |
@@ -99,8 +101,9 @@ discard block |
||
99 | 101 | */ |
100 | 102 | public function setUrl($url = null) |
101 | 103 | { |
102 | - if (is_null($url)) |
|
103 | - $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
104 | + if (is_null($url)) { |
|
105 | + $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
106 | + } |
|
104 | 107 | $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
105 | 108 | } |
106 | 109 | |
@@ -111,8 +114,9 @@ discard block |
||
111 | 114 | { |
112 | 115 | foreach ($this->config['matcher'] as $matcher) { |
113 | 116 | $this->config['matcherInstance'][$matcher] = new $matcher($this); |
114 | - if (call_user_func([$this->config['matcherInstance'][$matcher], 'match'])) |
|
115 | - return true; |
|
117 | + if (call_user_func([$this->config['matcherInstance'][$matcher], 'match'])) { |
|
118 | + return true; |
|
119 | + } |
|
116 | 120 | } |
117 | 121 | return false; |
118 | 122 | } |
@@ -158,13 +162,15 @@ discard block |
||
158 | 162 | { |
159 | 163 | if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) { |
160 | 164 | $this->route->setCallback($this->route->getDetail()['response_templates'][$code]); |
161 | - if(!isset($this->config['matcherInstance'])) |
|
162 | - foreach ($this->config['matcher'] as $matcher) |
|
163 | - $this->config['matcherInstance'][$matcher] = new $matcher($this); |
|
165 | + if(!isset($this->config['matcherInstance'])) { |
|
166 | + foreach ($this->config['matcher'] as $matcher) |
|
167 | + $this->config['matcherInstance'][$matcher] = new $matcher($this); |
|
168 | + } |
|
164 | 169 | foreach($this->config['matcherInstance'] as $instance) { |
165 | - foreach (call_user_func([$instance, 'getMatcher']) as $match) |
|
166 | - if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
167 | - call_user_func_array([$instance, 'setTarget'],[$target]); |
|
170 | + foreach (call_user_func([$instance, 'getMatcher']) as $match) { |
|
171 | + if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
172 | + call_user_func_array([$instance, 'setTarget'],[$target]); |
|
173 | + } |
|
168 | 174 | $this->callTarget(); |
169 | 175 | break; |
170 | 176 | } |