@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * @param $regex |
|
| 166 | + * @param string $regex |
|
| 167 | 167 | * @return bool |
| 168 | 168 | */ |
| 169 | 169 | private function routeMatch($regex) |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | - * @return bool |
|
| 184 | + * @return null|boolean |
|
| 185 | 185 | */ |
| 186 | 186 | private function generateTarget() |
| 187 | 187 | { |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | - * @param $key |
|
| 219 | + * @param string $key |
|
| 220 | 220 | */ |
| 221 | 221 | private function checkRequest($key) |
| 222 | 222 | { |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | { |
| 96 | 96 | $this->request = []; |
| 97 | 97 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
| 98 | - $this->request['prefix'] = ($this->router->collection->getRoutes('prefix_' . $i) != '') ? $this->router->collection->getRoutes('prefix_' . $i) : ''; |
|
| 99 | - $this->request['subdomain'] = ($this->router->collection->getRoutes('subdomain_' . $i) != '') ? $this->router->collection->getRoutes('subdomain_' . $i) : ''; |
|
| 100 | - foreach ($this->router->collection->getRoutes('routes_' . $i) as $route => $params) { |
|
| 98 | + $this->request['prefix'] = ($this->router->collection->getRoutes('prefix_'.$i) != '') ? $this->router->collection->getRoutes('prefix_'.$i) : ''; |
|
| 99 | + $this->request['subdomain'] = ($this->router->collection->getRoutes('subdomain_'.$i) != '') ? $this->router->collection->getRoutes('subdomain_'.$i) : ''; |
|
| 100 | + foreach ($this->router->collection->getRoutes('routes_'.$i) as $route => $params) { |
|
| 101 | 101 | $this->request['params'] = $params; |
| 102 | 102 | $this->request['collection_index'] = $i; |
| 103 | 103 | if ($this->checkSubdomain($route)) { |
| 104 | 104 | $route = strstr($route, '/'); |
| 105 | - $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/' . trim(trim($this->request['prefix'], '/') . '/' . trim($route, '/'), '/')); |
|
| 106 | - if ($this->routeMatch('#^' . $this->request['route'] . '$#')) { |
|
| 105 | + $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/'.trim(trim($this->request['prefix'], '/').'/'.trim($route, '/'), '/')); |
|
| 106 | + if ($this->routeMatch('#^'.$this->request['route'].'$#')) { |
|
| 107 | 107 | $this->setCallback(); |
| 108 | 108 | if (!is_null($response = $this->generateTarget())) return $response; |
| 109 | 109 | } |
@@ -119,19 +119,19 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | private function checkSubdomain($route) |
| 121 | 121 | { |
| 122 | - $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http') . '://' . ($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'])); |
|
| 122 | + $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http').'://'.($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'])); |
|
| 123 | 123 | $host = explode(':', $host)[0]; |
| 124 | 124 | $domain = $this->router->collection->getDomain($url); |
| 125 | - if (!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'], '.') . '.' . $domain . $route; |
|
| 125 | + if (!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'], '.').'.'.$domain.$route; |
|
| 126 | 126 | if ($route[0] == '/') { |
| 127 | 127 | return ($host != $domain) ? false : true; |
| 128 | 128 | } elseif ($route[0] != '/' && $host != $domain) { |
| 129 | 129 | $route = substr($route, 0, strpos($route, "/")); |
| 130 | 130 | $route = str_replace('{host}', $domain, $route); |
| 131 | 131 | $route = preg_replace_callback('#{subdomain}#', [$this, 'subdomainMatch'], $route); |
| 132 | - if (preg_match('#^' . $route . '$#', $host, $this->request['called_subdomain'])) { |
|
| 132 | + if (preg_match('#^'.$route.'$#', $host, $this->request['called_subdomain'])) { |
|
| 133 | 133 | $this->request['called_subdomain'] = array_shift($this->request['called_subdomain']); |
| 134 | - $this->request['subdomain'] = str_replace('.' . $domain, '', $host); |
|
| 134 | + $this->request['subdomain'] = str_replace('.'.$domain, '', $host); |
|
| 135 | 135 | return true; |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | private function subdomainMatch() |
| 145 | 145 | { |
| 146 | 146 | if (is_array($this->request['params']) && isset($this->request['params']['subdomain'])) { |
| 147 | - return '(' . $this->request['params']['subdomain'] . ')'; |
|
| 147 | + return '('.$this->request['params']['subdomain'].')'; |
|
| 148 | 148 | } |
| 149 | 149 | return '([^/]+)'; |
| 150 | 150 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | if (is_array($this->request['params']) && isset($this->request['params']['arguments'][$match[1]])) { |
| 159 | 159 | $this->request['params']['arguments'][$match[1]] = str_replace('(', '(?:', $this->request['params']['arguments'][$match[1]]); |
| 160 | - return '(' . $this->request['params']['arguments'][$match[1]] . ')'; |
|
| 160 | + return '('.$this->request['params']['arguments'][$match[1]].')'; |
|
| 161 | 161 | } |
| 162 | 162 | return '([^/]+)'; |
| 163 | 163 | } |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | $this->checkRequest('prefix'); |
| 212 | 212 | $this->router->route->setDetail($this->request); |
| 213 | 213 | $this->router->route->setTarget($target); |
| 214 | - $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_' . $index)); |
|
| 215 | - $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_' . $index)); |
|
| 214 | + $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_'.$index)); |
|
| 215 | + $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_'.$index)); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | private function checkRequest($key) |
| 222 | 222 | { |
| 223 | 223 | if (strpos($this->request[$key], ':') !== false) { |
| 224 | - $this->request['@' . $key] = $this->request[$key]; |
|
| 224 | + $this->request['@'.$key] = $this->request[$key]; |
|
| 225 | 225 | $this->request[$key] = $this->request['parameters'][0]; |
| 226 | 226 | unset($this->request['parameters'][0]); |
| 227 | 227 | } |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 330 | 330 | $class = (class_exists($routes[0])) |
| 331 | 331 | ? $routes[0] |
| 332 | - : $this->router->collection->getRoutes()['ctrl_namespace_' . $index] . $routes[0]; |
|
| 332 | + : $this->router->collection->getRoutes()['ctrl_namespace_'.$index].$routes[0]; |
|
| 333 | 333 | if (!class_exists($class)) |
| 334 | - throw new \Exception('Class "' . $class . '." is not found'); |
|
| 334 | + throw new \Exception('Class "'.$class.'." is not found'); |
|
| 335 | 335 | if (method_exists($class, $routes[1])) { |
| 336 | 336 | return [ |
| 337 | 337 | 'dispatcher' => $this->dispatcher['isController'], |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | ]; |
| 342 | 342 | } |
| 343 | 343 | if (!strpos($callback, '{method}') !== false) |
| 344 | - throw new \Exception('The required method "' . $routes[1] . '" is not found in "' . $class . '"'); |
|
| 344 | + throw new \Exception('The required method "'.$routes[1].'" is not found in "'.$class.'"'); |
|
| 345 | 345 | } |
| 346 | 346 | return false; |
| 347 | 347 | } |
@@ -357,13 +357,13 @@ discard block |
||
| 357 | 357 | $path = trim($callback, '/'); |
| 358 | 358 | $extension = substr(strrchr($path, "."), 1); |
| 359 | 359 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 360 | - $viewDir = $this->router->collection->getRoutes('view_dir_' . $index); |
|
| 360 | + $viewDir = $this->router->collection->getRoutes('view_dir_'.$index); |
|
| 361 | 361 | $target = null; |
| 362 | - if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path))) |
|
| 362 | + if (in_array('.'.$extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir.$path) || is_file($fullPath = $path))) |
|
| 363 | 363 | $target = $fullPath; |
| 364 | 364 | else { |
| 365 | 365 | foreach ($this->router->getConfig()['templateExtension'] as $ext) { |
| 366 | - if (is_file($fullPath = $viewDir . $path . $ext) || is_file($fullPath = $path . $ext)) { |
|
| 366 | + if (is_file($fullPath = $viewDir.$path.$ext) || is_file($fullPath = $path.$ext)) { |
|
| 367 | 367 | $target = $fullPath; |
| 368 | 368 | $extension = substr(strrchr($ext, "."), 1); |
| 369 | 369 | break; |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | if (is_null($target)) |
| 374 | - throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"'); |
|
| 374 | + throw new \Exception('Template file "'.$path.'" is not found in "'.$viewDir.'"'); |
|
| 375 | 375 | return [ |
| 376 | 376 | 'dispatcher' => $this->dispatcher['isTemplate'], |
| 377 | 377 | 'template' => $target, |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $this->response->setStatusCode(404); |
| 60 | 60 | $this->route = is_null($route) ? new Route() : $route; |
| 61 | 61 | $this->middleware = new Middleware($this); |
| 62 | - $this->config['di'] = function ($class) { |
|
| 62 | + $this->config['di'] = function($class) { |
|
| 63 | 63 | return new $class; |
| 64 | 64 | }; |
| 65 | 65 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | { |
| 117 | 117 | if (is_null($url)) |
| 118 | 118 | $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
| 119 | - $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
|
| 119 | + $this->route->setUrl('/'.trim(explode('?', $url)[0], '/')); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | $this->response->setStatusCode($code); |
| 172 | 172 | } |
| 173 | - if (isset($this->collection->middleware['before_render'])){ |
|
| 174 | - foreach ($this->collection->middleware['before_render'] as $callback){ |
|
| 173 | + if (isset($this->collection->middleware['before_render'])) { |
|
| 174 | + foreach ($this->collection->middleware['before_render'] as $callback) { |
|
| 175 | 175 | $call = explode('@', $callback); |
| 176 | - if(isset($call[1])){ |
|
| 176 | + if (isset($call[1])) { |
|
| 177 | 177 | $classes = ['JetFire\Routing\Router' => $this]; |
| 178 | 178 | $args = ['router' => $this, 'route' => $this->route, 'response' => $this->response]; |
| 179 | 179 | $this->callMethod($call[0], $call[1], $args, $args, $classes); |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | { |
| 222 | 222 | $reflector = new ReflectionClass($controller); |
| 223 | 223 | if (!$reflector->isInstantiable()) |
| 224 | - throw new \Exception('Controller [' . $controller . '] is not instantiable.'); |
|
| 224 | + throw new \Exception('Controller ['.$controller.'] is not instantiable.'); |
|
| 225 | 225 | $constructor = $reflector->getConstructor(); |
| 226 | 226 | if (is_null($constructor)) |
| 227 | 227 | return call_user_func_array($this->getConfig()['di'], [$controller]); |