@@ -80,8 +80,9 @@ discard block |
||
80 | 80 | * @param object|array $matcher |
81 | 81 | */ |
82 | 82 | public function setMatcher($matcher){ |
83 | - if(is_object($matcher)) |
|
84 | - $matcher = [$matcher]; |
|
83 | + if(is_object($matcher)) { |
|
84 | + $matcher = [$matcher]; |
|
85 | + } |
|
85 | 86 | $this->matcher = $matcher; |
86 | 87 | } |
87 | 88 | |
@@ -98,7 +99,9 @@ discard block |
||
98 | 99 | public function run() |
99 | 100 | { |
100 | 101 | $this->setUrl(); |
101 | - if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath(); |
|
102 | + if ($this->config['generateRoutesPath']) { |
|
103 | + $this->collection->generateRoutesPath(); |
|
104 | + } |
|
102 | 105 | if ($this->match()) { |
103 | 106 | $this->handle(); |
104 | 107 | $this->callTarget(); |
@@ -111,8 +114,9 @@ discard block |
||
111 | 114 | */ |
112 | 115 | public function setUrl($url = null) |
113 | 116 | { |
114 | - if (is_null($url)) |
|
115 | - $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
117 | + if (is_null($url)) { |
|
118 | + $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
119 | + } |
|
116 | 120 | $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
117 | 121 | } |
118 | 122 | |
@@ -122,8 +126,9 @@ discard block |
||
122 | 126 | public function match() |
123 | 127 | { |
124 | 128 | foreach ($this->matcher as $key => $matcher) { |
125 | - if (call_user_func([$this->matcher[$key], 'match'])) |
|
126 | - return true; |
|
129 | + if (call_user_func([$this->matcher[$key], 'match'])) { |
|
130 | + return true; |
|
131 | + } |
|
127 | 132 | } |
128 | 133 | return false; |
129 | 134 | } |
@@ -170,11 +175,16 @@ discard block |
||
170 | 175 | if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) { |
171 | 176 | $this->route->setCallback($this->route->getDetail()['response_templates'][$code]); |
172 | 177 | $matcher = null; |
173 | - foreach($this->matcher as $instance) if($instance instanceof ArrayMatcher) $matcher = $instance; |
|
174 | - if(is_null($matcher))$matcher = new ArrayMatcher($this); |
|
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]); |
|
178 | + foreach($this->matcher as $instance) { |
|
179 | + if($instance instanceof ArrayMatcher) $matcher = $instance; |
|
180 | + } |
|
181 | + if(is_null($matcher)) { |
|
182 | + $matcher = new ArrayMatcher($this); |
|
183 | + } |
|
184 | + foreach (call_user_func([$matcher, 'getResolver']) as $match) { |
|
185 | + if (is_array($target = call_user_func_array([$matcher, $match], [$this->route->getCallback()]))){ |
|
186 | + call_user_func_array([$matcher, 'setTarget'],[$target]); |
|
187 | + } |
|
178 | 188 | $this->callTarget(); |
179 | 189 | break; |
180 | 190 | } |