@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | /** |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - private $matcher = ['matchClosure','matchController','matchTemplate']; |
|
| 27 | + private $matcher = ['matchClosure', 'matchController', 'matchTemplate']; |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @var array |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @param string $matcher |
| 48 | 48 | */ |
| 49 | - public function addMatcher($matcher){ |
|
| 49 | + public function addMatcher($matcher) { |
|
| 50 | 50 | $this->matcher[] = $matcher; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | /** |
| 62 | 62 | * @param array $dispatcher |
| 63 | 63 | */ |
| 64 | - public function setDispatcher($dispatcher = []){ |
|
| 64 | + public function setDispatcher($dispatcher = []) { |
|
| 65 | 65 | $this->dispatcher = $dispatcher; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @return mixed|void |
| 72 | 72 | * @internal param array $dispatcher |
| 73 | 73 | */ |
| 74 | - public function addDispatcher($method,$class){ |
|
| 74 | + public function addDispatcher($method, $class) { |
|
| 75 | 75 | $this->dispatcher[$method] = $class; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -133,13 +133,13 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | private function generateTarget() |
| 135 | 135 | { |
| 136 | - if($this->validMethod()) { |
|
| 137 | - foreach($this->matcher as $match) if(call_user_func([$this,$match])) break; |
|
| 136 | + if ($this->validMethod()) { |
|
| 137 | + foreach ($this->matcher as $match) if (call_user_func([$this, $match])) break; |
|
| 138 | 138 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 139 | - $this->router->route->addTarget('block',$this->router->collection->getRoutes('block_'.$index)); |
|
| 140 | - $this->router->route->addTarget('view_dir',$this->router->collection->getRoutes('view_dir_'.$index)); |
|
| 139 | + $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_' . $index)); |
|
| 140 | + $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_' . $index)); |
|
| 141 | 141 | $this->router->response->setStatusCode(202); |
| 142 | - }else |
|
| 142 | + } else |
|
| 143 | 143 | $this->router->response->setStatusCode(405); |
| 144 | 144 | return $this->router->route->hasTarget(); |
| 145 | 145 | } |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | /** |
| 148 | 148 | * |
| 149 | 149 | */ |
| 150 | - private function setRoute(){ |
|
| 150 | + private function setRoute() { |
|
| 151 | 151 | if (isset($this->request['params'])) { |
| 152 | - if(is_callable($this->request['params'])) |
|
| 152 | + if (is_callable($this->request['params'])) |
|
| 153 | 153 | $this->router->route->setCallback($this->request['params']); |
| 154 | 154 | else { |
| 155 | 155 | (is_array($this->request['params']) && isset($this->request['params']['use'])) |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | public function validMethod() |
| 169 | 169 | { |
| 170 | - if(is_callable($this->request['params']))return true; |
|
| 170 | + if (is_callable($this->request['params']))return true; |
|
| 171 | 171 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') |
| 172 | 172 | return (isset($this->request['params']['ajax']) && $this->request['params']['ajax'] === true) ? true : false; |
| 173 | 173 | $method = (isset($this->router->route->getDetail()['params']['method'])) ? $this->router->route->getDetail()['params']['method'] : ['GET']; |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 203 | 203 | $class = (class_exists($routes[0])) |
| 204 | 204 | ? $routes[0] |
| 205 | - : $this->router->collection->getRoutes()['ctrl_namespace_'.$index].$routes[0]; |
|
| 205 | + : $this->router->collection->getRoutes()['ctrl_namespace_' . $index] . $routes[0]; |
|
| 206 | 206 | if (!class_exists($class)) |
| 207 | 207 | throw new \Exception('Class "' . $class . '." is not found'); |
| 208 | 208 | if (method_exists($class, $routes[1])) { |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public function matchTemplate() |
| 227 | 227 | { |
| 228 | - if(is_string($this->router->route->getCallback())) { |
|
| 228 | + if (is_string($this->router->route->getCallback())) { |
|
| 229 | 229 | $path = trim($this->router->route->getCallback(), '/'); |
| 230 | 230 | $extension = substr(strrchr($path, "."), 1); |
| 231 | 231 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | - if(is_null($target)) |
|
| 245 | + if (is_null($target)) |
|
| 246 | 246 | throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"'); |
| 247 | 247 | $this->router->route->setTarget([ |
| 248 | 248 | 'dispatcher' => $this->dispatcher['matchTemplate'], |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @var array |
| 22 | 22 | */ |
| 23 | - private $matcher = ['matchController','matchTemplate']; |
|
| 23 | + private $matcher = ['matchController', 'matchTemplate']; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var array |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * @param string $matcher |
| 43 | 43 | */ |
| 44 | - public function addMatcher($matcher){ |
|
| 44 | + public function addMatcher($matcher) { |
|
| 45 | 45 | $this->matcher[] = $matcher; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @param $class |
| 67 | 67 | * @return mixed|void |
| 68 | 68 | */ |
| 69 | - public function addDispatcher($method,$class){ |
|
| 69 | + public function addDispatcher($method, $class) { |
|
| 70 | 70 | $this->dispatcher[$method] = $class; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function match() |
| 77 | 77 | { |
| 78 | - foreach($this->matcher as $matcher){ |
|
| 79 | - if(call_user_func([$this,$matcher])) { |
|
| 78 | + foreach ($this->matcher as $matcher) { |
|
| 79 | + if (call_user_func([$this, $matcher])) { |
|
| 80 | 80 | $this->router->response->setStatusCode(202); |
| 81 | 81 | return true; |
| 82 | 82 | } |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | foreach ($this->router->getConfig()['templateExtension'] as $extension) { |
| 93 | 93 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
| 94 | - $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '',$this->router->route->getUrl())); |
|
| 94 | + $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '', $this->router->route->getUrl())); |
|
| 95 | 95 | $end = array_pop($url); |
| 96 | - $url = implode('/', array_map('ucwords', $url)).'/'.$end; |
|
| 96 | + $url = implode('/', array_map('ucwords', $url)) . '/' . $end; |
|
| 97 | 97 | if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) { |
| 98 | - $block = $this->router->collection->getRoutes('block_'.$i); |
|
| 99 | - $viewDir = $this->router->collection->getRoutes('view_dir_'.$i); |
|
| 98 | + $block = $this->router->collection->getRoutes('block_' . $i); |
|
| 99 | + $viewDir = $this->router->collection->getRoutes('view_dir_' . $i); |
|
| 100 | 100 | $this->router->route->setTarget([ |
| 101 | 101 | 'dispatcher' => $this->dispatcher['matchTemplate'], |
| 102 | 102 | 'block' => $block, |
@@ -119,15 +119,15 @@ discard block |
||
| 119 | 119 | { |
| 120 | 120 | $routes = array_slice(explode('/', $this->router->route->getUrl()), 1); |
| 121 | 121 | $i = 0; |
| 122 | - do{ |
|
| 123 | - $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
| 122 | + do { |
|
| 123 | + $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
| 124 | 124 | if (isset($route[0])) { |
| 125 | - $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller')) |
|
| 126 | - ? $this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller' |
|
| 125 | + $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller')) |
|
| 126 | + ? $this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller' |
|
| 127 | 127 | : ucfirst($route[0]) . 'Controller'; |
| 128 | 128 | if (isset($route[1]) && method_exists($class, $route[1])) { |
| 129 | - $block = $this->router->collection->getRoutes('block_'.$i); |
|
| 130 | - $viewDir = $this->router->collection->getRoutes('view_dir_'.$i); |
|
| 129 | + $block = $this->router->collection->getRoutes('block_' . $i); |
|
| 130 | + $viewDir = $this->router->collection->getRoutes('view_dir_' . $i); |
|
| 131 | 131 | $this->router->route->setTarget([ |
| 132 | 132 | 'dispatcher' => $this->dispatcher['matchController'], |
| 133 | 133 | 'block' => $block, |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | ++$i; |
| 144 | - }while($i < $this->router->collection->countRoutes); |
|
| 144 | + }while ($i < $this->router->collection->countRoutes); |
|
| 145 | 145 | return false; |
| 146 | 146 | } |
| 147 | 147 | |
@@ -41,5 +41,5 @@ |
||
| 41 | 41 | * @param $class |
| 42 | 42 | * @return mixed |
| 43 | 43 | */ |
| 44 | - public function addDispatcher($method,$class); |
|
| 44 | + public function addDispatcher($method, $class); |
|
| 45 | 45 | } |