@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | public function addRoutes($routes = null, $options = []) |
| 44 | 44 | { |
| 45 | 45 | if (!is_null($routes) && !is_array($routes)) { |
| 46 | - if (strpos($routes, '.php') === false) $routes = trim($routes, '/') . '/'; |
|
| 47 | - if (is_file($routes . '/routes.php') && is_array($routesFile = include $routes . '/routes.php')) $routes = $routesFile; |
|
| 46 | + if (strpos($routes, '.php') === false) $routes = trim($routes, '/').'/'; |
|
| 47 | + if (is_file($routes.'/routes.php') && is_array($routesFile = include $routes.'/routes.php')) $routes = $routesFile; |
|
| 48 | 48 | elseif (is_file($routes) && is_array($routesFile = include $routes)) $routes = $routesFile; |
| 49 | - else throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "' . $routes . '" given'); |
|
| 49 | + else throw new \InvalidArgumentException('Argument for "'.get_called_class().'" constructor is not recognized. Expected argument array or file containing array but "'.$routes.'" given'); |
|
| 50 | 50 | } |
| 51 | - $this->routes['routes_' . $this->countRoutes] = is_array($routes) ? $routes : []; |
|
| 51 | + $this->routes['routes_'.$this->countRoutes] = is_array($routes) ? $routes : []; |
|
| 52 | 52 | $this->setRoutes($options, $this->countRoutes); |
| 53 | 53 | $this->countRoutes++; |
| 54 | 54 | } |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | if (is_array($args)) { |
| 73 | 73 | $nbrArgs = count($args); |
| 74 | 74 | for ($i = 0; $i < $nbrArgs; ++$i) |
| 75 | - $this->routes['prefix_' . $i] = '/' . trim($args[$i], '/'); |
|
| 75 | + $this->routes['prefix_'.$i] = '/'.trim($args[$i], '/'); |
|
| 76 | 76 | } elseif (is_string($args)) |
| 77 | 77 | for ($i = 0; $i < $this->countRoutes; ++$i) |
| 78 | - $this->routes['prefix_' . $i] = '/' . trim($args, '/'); |
|
| 78 | + $this->routes['prefix_'.$i] = '/'.trim($args, '/'); |
|
| 79 | 79 | if ($this->countRoutes == 0) $this->countRoutes++; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | for ($i = 0; $i < $nbrArgs; ++$i) { |
| 89 | 89 | if (is_array($args[$i])) { |
| 90 | 90 | $this->setRoutes($args[$i], $i); |
| 91 | - if (!isset($this->routes['routes_' . $i])) $this->routes['routes_' . $i] = []; |
|
| 91 | + if (!isset($this->routes['routes_'.$i])) $this->routes['routes_'.$i] = []; |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | if ($this->countRoutes == 0) $this->countRoutes++; |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | private function setRoutes($args = [], $i) |
| 102 | 102 | { |
| 103 | - $this->routes['block_' . $i] = (isset($args['block']) && !empty($args['block'])) ? rtrim($args['block'], '/') . '/' : ''; |
|
| 104 | - $this->routes['view_dir_' . $i] = (isset($args['view_dir']) && !empty($args['view_dir'])) ? rtrim($args['view_dir'], '/') . '/' : ''; |
|
| 105 | - $this->routes['ctrl_namespace_' . $i] = (isset($args['ctrl_namespace']) && !empty($args['ctrl_namespace'])) ? trim($args['ctrl_namespace'], '\\') . '\\' : ''; |
|
| 106 | - $this->routes['prefix_' . $i] = (isset($args['prefix']) && !empty($args['prefix'])) ? '/' . trim($args['prefix'], '/') : ''; |
|
| 107 | - $this->routes['subdomain_' . $i] = (isset($args['subdomain'])) ? $args['subdomain'] : ''; |
|
| 103 | + $this->routes['block_'.$i] = (isset($args['block']) && !empty($args['block'])) ? rtrim($args['block'], '/').'/' : ''; |
|
| 104 | + $this->routes['view_dir_'.$i] = (isset($args['view_dir']) && !empty($args['view_dir'])) ? rtrim($args['view_dir'], '/').'/' : ''; |
|
| 105 | + $this->routes['ctrl_namespace_'.$i] = (isset($args['ctrl_namespace']) && !empty($args['ctrl_namespace'])) ? trim($args['ctrl_namespace'], '\\').'\\' : ''; |
|
| 106 | + $this->routes['prefix_'.$i] = (isset($args['prefix']) && !empty($args['prefix'])) ? '/'.trim($args['prefix'], '/') : ''; |
|
| 107 | + $this->routes['subdomain_'.$i] = (isset($args['subdomain'])) ? $args['subdomain'] : ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $protocol = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http'; |
| 118 | 118 | $domain = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
| 119 | 119 | $root = (is_null($root)) |
| 120 | - ? $protocol . '://' . $domain . ((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':' . $_SERVER['SERVER_PORT'] : '') . str_replace('/' . $script_file, '', $_SERVER['SCRIPT_NAME']) |
|
| 120 | + ? $protocol.'://'.$domain.((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').str_replace('/'.$script_file, '', $_SERVER['SCRIPT_NAME']) |
|
| 121 | 121 | : $root; |
| 122 | 122 | $new_domain = $this->getDomain($root); |
| 123 | 123 | if (!is_null($domain) && strpos($domain, $new_domain) !== false) { |
@@ -125,26 +125,26 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | $count = 0; |
| 127 | 127 | for ($i = 0; $i < $this->countRoutes; ++$i) { |
| 128 | - $prefix = (isset($this->routes['prefix_' . $i])) ? $this->routes['prefix_' . $i] : ''; |
|
| 129 | - $subdomain = (isset($this->routes['subdomain_' . $i])) ? $this->routes['subdomain_' . $i] : ''; |
|
| 130 | - $url = (!empty($subdomain)) ? str_replace($protocol.'://',$protocol.'://'.$subdomain.'.' ,$root) : $root; |
|
| 131 | - if (isset($this->routes['routes_' . $i])) |
|
| 132 | - foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
| 128 | + $prefix = (isset($this->routes['prefix_'.$i])) ? $this->routes['prefix_'.$i] : ''; |
|
| 129 | + $subdomain = (isset($this->routes['subdomain_'.$i])) ? $this->routes['subdomain_'.$i] : ''; |
|
| 130 | + $url = (!empty($subdomain)) ? str_replace($protocol.'://', $protocol.'://'.$subdomain.'.', $root) : $root; |
|
| 131 | + if (isset($this->routes['routes_'.$i])) |
|
| 132 | + foreach ($this->routes['routes_'.$i] as $route => $dependencies) { |
|
| 133 | 133 | if (is_array($dependencies) && isset($dependencies['use']) && !is_array($dependencies['use'])) { |
| 134 | - $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
| 134 | + $use = (is_callable($dependencies['use'])) ? 'closure-'.$count : trim($dependencies['use'], '/'); |
|
| 135 | 135 | } elseif (!is_array($dependencies)) { |
| 136 | - $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/'); |
|
| 136 | + $use = (is_callable($dependencies)) ? 'closure-'.$count : trim($dependencies, '/'); |
|
| 137 | 137 | } else { |
| 138 | 138 | $use = $route; |
| 139 | 139 | } |
| 140 | 140 | if (isset($route[0]) && $route[0] == '/') { |
| 141 | 141 | (!is_callable($dependencies) && isset($dependencies['name'])) |
| 142 | - ? $this->routesByName[$use . '#' . $dependencies['name']] = $url . $prefix . $route |
|
| 143 | - : $this->routesByName[$use] = $url . $prefix . $route; |
|
| 142 | + ? $this->routesByName[$use.'#'.$dependencies['name']] = $url.$prefix.$route |
|
| 143 | + : $this->routesByName[$use] = $url.$prefix.$route; |
|
| 144 | 144 | } else { |
| 145 | 145 | (!is_callable($dependencies) && isset($dependencies['name'])) |
| 146 | - ? $this->routesByName[$use . '#' . $dependencies['name']] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix |
|
| 147 | - : $this->routesByName[$use] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix; |
|
| 146 | + ? $this->routesByName[$use.'#'.$dependencies['name']] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix |
|
| 147 | + : $this->routesByName[$use] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix; |
|
| 148 | 148 | } |
| 149 | 149 | $count++; |
| 150 | 150 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | foreach ($this->routesByName as $key => $route) { |
| 178 | 178 | $param = explode('#', $key); |
| 179 | 179 | $route = str_replace('{subdomain}', $subdomain, $route); |
| 180 | - foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route); |
|
| 180 | + foreach ($params as $key2 => $value) $route = str_replace(':'.$key2, $value, $route); |
|
| 181 | 181 | if ($param[0] == trim($name, '/')) return $route; |
| 182 | 182 | else if (isset($param[1]) && $param[1] == $name) return $route; |
| 183 | 183 | } |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | { |
| 86 | 86 | $reflector = new ReflectionClass($this->router->route->getTarget('controller')); |
| 87 | 87 | if (!$reflector->isInstantiable()) { |
| 88 | - throw new \Exception('Target [' . $this->router->route->getTarget('controller') . '] is not instantiable.'); |
|
| 88 | + throw new \Exception('Target ['.$this->router->route->getTarget('controller').'] is not instantiable.'); |
|
| 89 | 89 | } |
| 90 | 90 | $constructor = $reflector->getConstructor(); |
| 91 | 91 | if (is_null($constructor)) { |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 109 | 109 | $this->router->route->setDetail($this->request); |
| 110 | 110 | $this->router->route->setTarget($target); |
| 111 | - $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_' . $index)); |
|
| 112 | - $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_' . $index)); |
|
| 111 | + $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_'.$index)); |
|
| 112 | + $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_'.$index)); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | { |
| 136 | 136 | foreach ($this->router->getConfig()['templateExtension'] as $extension) { |
| 137 | 137 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
| 138 | - $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '', $this->router->route->getUrl())); |
|
| 138 | + $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_'.$i), '', $this->router->route->getUrl())); |
|
| 139 | 139 | $end = array_pop($url); |
| 140 | - $url = implode('/', array_map('ucwords', $url)) . '/' . $end; |
|
| 141 | - if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) { |
|
| 140 | + $url = implode('/', array_map('ucwords', $url)).'/'.$end; |
|
| 141 | + if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_'.$i), '/').$url.$extension))) { |
|
| 142 | 142 | $this->request['collection_index'] = $i; |
| 143 | 143 | return [ |
| 144 | 144 | 'dispatcher' => $this->dispatcher['isTemplate'], |
@@ -160,11 +160,11 @@ discard block |
||
| 160 | 160 | $routes = array_slice(explode('/', $this->router->route->getUrl()), 1); |
| 161 | 161 | $i = 0; |
| 162 | 162 | do { |
| 163 | - $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
| 163 | + $route = ('/'.$routes[0] == $this->router->collection->getRoutes('prefix_'.$i)) ? array_slice($routes, 1) : $routes; |
|
| 164 | 164 | if (isset($route[0])) { |
| 165 | - $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller')) |
|
| 166 | - ? $this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller' |
|
| 167 | - : ucfirst($route[0]) . 'Controller'; |
|
| 165 | + $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller')) |
|
| 166 | + ? $this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller' |
|
| 167 | + : ucfirst($route[0]).'Controller'; |
|
| 168 | 168 | $route[1] = isset($route[1]) ? $route[1] : 'index'; |
| 169 | 169 | if (method_exists($class, $route[1])) { |
| 170 | 170 | $this->request['parameters'] = array_slice($route, 2); |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | ++$i; |
| 181 | - } while ($i < $this->router->collection->countRoutes); |
|
| 181 | + }while ($i < $this->router->collection->countRoutes); |
|
| 182 | 182 | return false; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -98,15 +98,15 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | $this->request = []; |
| 100 | 100 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
| 101 | - $this->request['prefix'] = ($this->router->collection->getRoutes('prefix_' . $i) != '') ? $this->router->collection->getRoutes('prefix_' . $i) : ''; |
|
| 102 | - $this->request['subdomain'] = ($this->router->collection->getRoutes('subdomain_' . $i) != '') ? $this->router->collection->getRoutes('subdomain_' . $i) : ''; |
|
| 103 | - foreach ($this->router->collection->getRoutes('routes_' . $i) as $route => $params) { |
|
| 101 | + $this->request['prefix'] = ($this->router->collection->getRoutes('prefix_'.$i) != '') ? $this->router->collection->getRoutes('prefix_'.$i) : ''; |
|
| 102 | + $this->request['subdomain'] = ($this->router->collection->getRoutes('subdomain_'.$i) != '') ? $this->router->collection->getRoutes('subdomain_'.$i) : ''; |
|
| 103 | + foreach ($this->router->collection->getRoutes('routes_'.$i) as $route => $params) { |
|
| 104 | 104 | $this->request['params'] = $params; |
| 105 | 105 | $this->request['collection_index'] = $i; |
| 106 | 106 | if ($this->checkSubdomain($route)) { |
| 107 | 107 | $route = strstr($route, '/'); |
| 108 | - $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/' . trim(trim($this->request['prefix'], '/') . '/' . trim($route, '/'), '/')); |
|
| 109 | - if ($this->routeMatch('#^' . $this->request['route'] . '$#')) { |
|
| 108 | + $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/'.trim(trim($this->request['prefix'], '/').'/'.trim($route, '/'), '/')); |
|
| 109 | + if ($this->routeMatch('#^'.$this->request['route'].'$#')) { |
|
| 110 | 110 | $this->setCallback(); |
| 111 | 111 | return $this->generateTarget(); |
| 112 | 112 | } |
@@ -122,19 +122,19 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | private function checkSubdomain($route) |
| 124 | 124 | { |
| 125 | - $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http') . '://' . ($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'])); |
|
| 125 | + $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http').'://'.($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'])); |
|
| 126 | 126 | $host = explode(':', $host)[0]; |
| 127 | 127 | $domain = $this->router->collection->getDomain($url); |
| 128 | - if (!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'], '.') . '.' . $domain . $route; |
|
| 128 | + if (!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'], '.').'.'.$domain.$route; |
|
| 129 | 129 | if ($route[0] == '/') { |
| 130 | 130 | return ($host != $domain) ? false : true; |
| 131 | 131 | } elseif ($route[0] != '/' && $host != $domain) { |
| 132 | 132 | $route = substr($route, 0, strpos($route, "/")); |
| 133 | 133 | $route = str_replace('{host}', $domain, $route); |
| 134 | 134 | $route = preg_replace_callback('#{subdomain}#', [$this, 'subdomainMatch'], $route); |
| 135 | - if (preg_match('#^' . $route . '$#', $host, $this->request['called_subdomain'])) { |
|
| 135 | + if (preg_match('#^'.$route.'$#', $host, $this->request['called_subdomain'])) { |
|
| 136 | 136 | $this->request['called_subdomain'] = array_shift($this->request['called_subdomain']); |
| 137 | - $this->request['subdomain'] = str_replace('.' . $domain, '', $host); |
|
| 137 | + $this->request['subdomain'] = str_replace('.'.$domain, '', $host); |
|
| 138 | 138 | return true; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | private function subdomainMatch() |
| 148 | 148 | { |
| 149 | 149 | if (is_array($this->request['params']) && isset($this->request['params']['subdomain'])) { |
| 150 | - return '(' . $this->request['params']['subdomain'] . ')'; |
|
| 150 | + return '('.$this->request['params']['subdomain'].')'; |
|
| 151 | 151 | } |
| 152 | 152 | return '([^/]+)'; |
| 153 | 153 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | { |
| 161 | 161 | if (is_array($this->request['params']) && isset($this->request['params']['arguments'][$match[1]])) { |
| 162 | 162 | $this->request['params']['arguments'][$match[1]] = str_replace('(', '(?:', $this->request['params']['arguments'][$match[1]]); |
| 163 | - return '(' . $this->request['params']['arguments'][$match[1]] . ')'; |
|
| 163 | + return '('.$this->request['params']['arguments'][$match[1]].')'; |
|
| 164 | 164 | } |
| 165 | 165 | return '([^/]+)'; |
| 166 | 166 | } |
@@ -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 && isset($this->request['parameters'][0])) { |
| 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 | } |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | $this->router->route->setCallback($this->request['params']); |
| 238 | 238 | } else { |
| 239 | 239 | if (is_array($this->request['params']) && isset($this->request['params']['use'])) { |
| 240 | - if(is_array($this->request['params']['use']) && isset($this->request['params']['use'][$this->router->route->getMethod()])){ |
|
| 240 | + if (is_array($this->request['params']['use']) && isset($this->request['params']['use'][$this->router->route->getMethod()])) { |
|
| 241 | 241 | $this->router->route->setCallback($this->request['params']['use'][$this->router->route->getMethod()]); |
| 242 | - }elseif(!is_array($this->request['params']['use'])){ |
|
| 242 | + }elseif (!is_array($this->request['params']['use'])) { |
|
| 243 | 243 | $this->router->route->setCallback($this->request['params']['use']); |
| 244 | 244 | } |
| 245 | 245 | } else { |
@@ -342,9 +342,9 @@ discard block |
||
| 342 | 342 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 343 | 343 | $class = (class_exists($routes[0])) |
| 344 | 344 | ? $routes[0] |
| 345 | - : $this->router->collection->getRoutes()['ctrl_namespace_' . $index] . $routes[0]; |
|
| 345 | + : $this->router->collection->getRoutes()['ctrl_namespace_'.$index].$routes[0]; |
|
| 346 | 346 | if (!class_exists($class)) { |
| 347 | - throw new \Exception('Class "' . $class . '." is not found'); |
|
| 347 | + throw new \Exception('Class "'.$class.'." is not found'); |
|
| 348 | 348 | } |
| 349 | 349 | if (method_exists($class, $routes[1])) { |
| 350 | 350 | return [ |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | ]; |
| 356 | 356 | } |
| 357 | 357 | if (!strpos($callback, '{method}') !== false) { |
| 358 | - throw new \Exception('The required method "' . $routes[1] . '" is not found in "' . $class . '"'); |
|
| 358 | + throw new \Exception('The required method "'.$routes[1].'" is not found in "'.$class.'"'); |
|
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | return false; |
@@ -372,13 +372,13 @@ discard block |
||
| 372 | 372 | $path = trim($callback, '/'); |
| 373 | 373 | $extension = substr(strrchr($path, "."), 1); |
| 374 | 374 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 375 | - $viewDir = $this->router->collection->getRoutes('view_dir_' . $index); |
|
| 375 | + $viewDir = $this->router->collection->getRoutes('view_dir_'.$index); |
|
| 376 | 376 | $target = null; |
| 377 | - if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path))) { |
|
| 377 | + if (in_array('.'.$extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir.$path) || is_file($fullPath = $path))) { |
|
| 378 | 378 | $target = $fullPath; |
| 379 | 379 | } else { |
| 380 | 380 | foreach ($this->router->getConfig()['templateExtension'] as $ext) { |
| 381 | - if (is_file($fullPath = $viewDir . $path . $ext) || is_file($fullPath = $path . $ext)) { |
|
| 381 | + if (is_file($fullPath = $viewDir.$path.$ext) || is_file($fullPath = $path.$ext)) { |
|
| 382 | 382 | $target = $fullPath; |
| 383 | 383 | $extension = substr(strrchr($ext, "."), 1); |
| 384 | 384 | break; |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | 388 | if (is_null($target)) { |
| 389 | - throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"'); |
|
| 389 | + throw new \Exception('Template file "'.$path.'" is not found in "'.$viewDir.'"'); |
|
| 390 | 390 | } |
| 391 | 391 | return [ |
| 392 | 392 | 'dispatcher' => $this->dispatcher['isTemplate'], |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $this->collection = $collection; |
| 58 | 58 | $this->response = is_null($response) ? new Response() : $response; |
| 59 | 59 | $this->route = is_null($route) ? new Route() : $route; |
| 60 | - $this->config['di'] = function ($class) { |
|
| 60 | + $this->config['di'] = function($class) { |
|
| 61 | 61 | return new $class; |
| 62 | 62 | }; |
| 63 | 63 | } |
@@ -123,11 +123,11 @@ discard block |
||
| 123 | 123 | if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath(); |
| 124 | 124 | if ($this->match() === true) { |
| 125 | 125 | $this->callMiddleware('before'); |
| 126 | - if (!in_array(substr($this->response->getStatusCode(), 0, 1), [3,4,5])) { |
|
| 126 | + if (!in_array(substr($this->response->getStatusCode(), 0, 1), [3, 4, 5])) { |
|
| 127 | 127 | $this->callTarget(); |
| 128 | 128 | } |
| 129 | 129 | $this->callMiddleware('after'); |
| 130 | - }else{ |
|
| 130 | + } else { |
|
| 131 | 131 | $this->response->setStatusCode(404); |
| 132 | 132 | } |
| 133 | 133 | return $this->callResponse(); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | foreach ($middleware->getCallbacks() as $callback) { |
| 145 | 145 | if (method_exists($middleware, $callback)) { |
| 146 | 146 | $response = call_user_func_array([$middleware, $callback], [$action]); |
| 147 | - if($response instanceof ResponseInterface) { |
|
| 147 | + if ($response instanceof ResponseInterface) { |
|
| 148 | 148 | $this->response = $response; |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | { |
| 161 | 161 | if (is_null($url)) |
| 162 | 162 | $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
| 163 | - $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
|
| 163 | + $this->route->setUrl('/'.trim(explode('?', $url)[0], '/')); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |