@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * @param array $resolver |
47 | 47 | */ |
48 | - public function setResolver($resolver = []){ |
|
48 | + public function setResolver($resolver = []) { |
|
49 | 49 | $this->resolver = $resolver; |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param string $resolver |
54 | 54 | */ |
55 | - public function addResolver($resolver){ |
|
55 | + public function addResolver($resolver) { |
|
56 | 56 | $this->resolver[] = $resolver; |
57 | 57 | } |
58 | 58 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param $class |
78 | 78 | * @return mixed|void |
79 | 79 | */ |
80 | - public function addDispatcher($method,$class){ |
|
80 | + public function addDispatcher($method, $class) { |
|
81 | 81 | $this->dispatcher[$method] = $class; |
82 | 82 | } |
83 | 83 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function match() |
88 | 88 | { |
89 | - foreach($this->resolver as $resolver){ |
|
90 | - if(is_array($target = call_user_func([$this,$resolver]))) { |
|
89 | + foreach ($this->resolver as $resolver) { |
|
90 | + if (is_array($target = call_user_func([$this, $resolver]))) { |
|
91 | 91 | $this->setTarget($target); |
92 | 92 | $this->router->response->setStatusCode(202); |
93 | 93 | return true; |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * @param array $target |
101 | 101 | */ |
102 | - public function setTarget($target = []){ |
|
102 | + public function setTarget($target = []) { |
|
103 | 103 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
104 | 104 | $this->router->route->setDetail($this->request); |
105 | 105 | $this->router->route->setTarget($target); |
106 | - $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_'.$index)); |
|
107 | - $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_'.$index)); |
|
106 | + $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_' . $index)); |
|
107 | + $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_' . $index)); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * @return array|bool |
112 | 112 | */ |
113 | - public function isControllerAndTemplate(){ |
|
114 | - if(is_array($ctrl = $this->isController())) { |
|
113 | + public function isControllerAndTemplate() { |
|
114 | + if (is_array($ctrl = $this->isController())) { |
|
115 | 115 | if (is_array($tpl = $this->isTemplate())) { |
116 | - return array_merge(array_merge($ctrl, $tpl),[ |
|
116 | + return array_merge(array_merge($ctrl, $tpl), [ |
|
117 | 117 | 'dispatcher' => [$this->dispatcher['matchController'], $this->dispatcher['matchTemplate']] |
118 | 118 | ]); |
119 | 119 | } |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | { |
130 | 130 | foreach ($this->router->getConfig()['templateExtension'] as $extension) { |
131 | 131 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
132 | - $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '',$this->router->route->getUrl())); |
|
132 | + $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '', $this->router->route->getUrl())); |
|
133 | 133 | $end = array_pop($url); |
134 | - $url = implode('/', array_map('ucwords', $url)).'/'.$end; |
|
134 | + $url = implode('/', array_map('ucwords', $url)) . '/' . $end; |
|
135 | 135 | if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) { |
136 | 136 | $this->request['collection_index'] = $i; |
137 | 137 | return [ |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | { |
154 | 154 | $routes = array_slice(explode('/', $this->router->route->getUrl()), 1); |
155 | 155 | $i = 0; |
156 | - do{ |
|
157 | - $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
156 | + do { |
|
157 | + $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
158 | 158 | if (isset($route[0])) { |
159 | - $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller')) |
|
160 | - ? $this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller' |
|
159 | + $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller')) |
|
160 | + ? $this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller' |
|
161 | 161 | : ucfirst($route[0]) . 'Controller'; |
162 | - $route[1] = isset($route[1])?$route[1]:'index'; |
|
162 | + $route[1] = isset($route[1]) ? $route[1] : 'index'; |
|
163 | 163 | if (method_exists($class, $route[1])) { |
164 | 164 | $this->request['parameters'] = array_slice($route, 2); |
165 | 165 | $this->request['collection_index'] = $i; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | } |
173 | 173 | } |
174 | 174 | ++$i; |
175 | - }while($i < $this->router->collection->countRoutes); |
|
175 | + }while ($i < $this->router->collection->countRoutes); |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | * @param ResponseInterface $response |
49 | 49 | * @param Route $route |
50 | 50 | */ |
51 | - public function __construct(RouteCollection $collection,ResponseInterface $response = null,Route $route = null) |
|
51 | + public function __construct(RouteCollection $collection, ResponseInterface $response = null, Route $route = null) |
|
52 | 52 | { |
53 | 53 | $this->collection = $collection; |
54 | - $this->response = is_null($response)? new Response() : $response; |
|
54 | + $this->response = is_null($response) ? new Response() : $response; |
|
55 | 55 | $this->response->setStatusCode(404); |
56 | - $this->route = is_null($route)? new Route() : $route; |
|
57 | - $this->config['di'] = function($class){ |
|
56 | + $this->route = is_null($route) ? new Route() : $route; |
|
57 | + $this->config['di'] = function($class) { |
|
58 | 58 | return new $class; |
59 | 59 | }; |
60 | 60 | } |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | /** |
79 | 79 | * @param object|array $matcher |
80 | 80 | */ |
81 | - public function setMatcher($matcher){ |
|
82 | - if(is_object($matcher)) |
|
81 | + public function setMatcher($matcher) { |
|
82 | + if (is_object($matcher)) |
|
83 | 83 | $matcher = [$matcher]; |
84 | 84 | $this->matcher = $matcher; |
85 | 85 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | /** |
88 | 88 | * @param string $matcher |
89 | 89 | */ |
90 | - public function addMatcher($matcher){ |
|
90 | + public function addMatcher($matcher) { |
|
91 | 91 | $this->matcher[] = $matcher; |
92 | 92 | } |
93 | 93 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function callTarget() |
134 | 134 | { |
135 | - $target = is_array($this->route->getTarget('dispatcher'))?$this->route->getTarget('dispatcher'):[$this->route->getTarget('dispatcher')]; |
|
136 | - if(!empty($target)) { |
|
137 | - foreach($target as $call) { |
|
135 | + $target = is_array($this->route->getTarget('dispatcher')) ? $this->route->getTarget('dispatcher') : [$this->route->getTarget('dispatcher')]; |
|
136 | + if (!empty($target)) { |
|
137 | + foreach ($target as $call) { |
|
138 | 138 | $this->dispatcher = new $call($this->route, $this->response); |
139 | 139 | call_user_func([$this->dispatcher, 'call']); |
140 | 140 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | { |
169 | 169 | if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) { |
170 | 170 | $this->route->setCallback($this->route->getDetail()['response_templates'][$code]); |
171 | - foreach($this->matcher as $key => $instance) { |
|
171 | + foreach ($this->matcher as $key => $instance) { |
|
172 | 172 | foreach (call_user_func([$instance, 'getResolver']) as $match) |
173 | - if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
174 | - call_user_func_array([$instance, 'setTarget'],[$target]); |
|
173 | + if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))) { |
|
174 | + call_user_func_array([$instance, 'setTarget'], [$target]); |
|
175 | 175 | $this->callTarget(); |
176 | 176 | break; |
177 | 177 | } |
@@ -79,8 +79,9 @@ discard block |
||
79 | 79 | * @param object|array $matcher |
80 | 80 | */ |
81 | 81 | public function setMatcher($matcher){ |
82 | - if(is_object($matcher)) |
|
83 | - $matcher = [$matcher]; |
|
82 | + if(is_object($matcher)) { |
|
83 | + $matcher = [$matcher]; |
|
84 | + } |
|
84 | 85 | $this->matcher = $matcher; |
85 | 86 | } |
86 | 87 | |
@@ -97,7 +98,9 @@ discard block |
||
97 | 98 | public function run() |
98 | 99 | { |
99 | 100 | $this->setUrl(); |
100 | - if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath(); |
|
101 | + if ($this->config['generateRoutesPath']) { |
|
102 | + $this->collection->generateRoutesPath(); |
|
103 | + } |
|
101 | 104 | if ($this->match()) { |
102 | 105 | $this->handle(); |
103 | 106 | $this->callTarget(); |
@@ -110,8 +113,9 @@ discard block |
||
110 | 113 | */ |
111 | 114 | public function setUrl($url = null) |
112 | 115 | { |
113 | - if (is_null($url)) |
|
114 | - $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
116 | + if (is_null($url)) { |
|
117 | + $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
118 | + } |
|
115 | 119 | $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
116 | 120 | } |
117 | 121 | |
@@ -121,8 +125,9 @@ discard block |
||
121 | 125 | public function match() |
122 | 126 | { |
123 | 127 | foreach ($this->matcher as $key => $matcher) { |
124 | - if (call_user_func([$this->matcher[$key], 'match'])) |
|
125 | - return true; |
|
128 | + if (call_user_func([$this->matcher[$key], 'match'])) { |
|
129 | + return true; |
|
130 | + } |
|
126 | 131 | } |
127 | 132 | return false; |
128 | 133 | } |
@@ -169,9 +174,10 @@ discard block |
||
169 | 174 | if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) { |
170 | 175 | $this->route->setCallback($this->route->getDetail()['response_templates'][$code]); |
171 | 176 | foreach($this->matcher as $key => $instance) { |
172 | - foreach (call_user_func([$instance, 'getResolver']) as $match) |
|
173 | - if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
174 | - call_user_func_array([$instance, 'setTarget'],[$target]); |
|
177 | + foreach (call_user_func([$instance, 'getResolver']) as $match) { |
|
178 | + if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
179 | + call_user_func_array([$instance, 'setTarget'],[$target]); |
|
180 | + } |
|
175 | 181 | $this->callTarget(); |
176 | 182 | break; |
177 | 183 | } |