@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | private $dispatcher = [ |
| 33 | 33 | 'isTemplate' => 'JetFire\Routing\Dispatcher\TemplateDispatcher', |
| 34 | 34 | 'isController' => 'JetFire\Routing\Dispatcher\ControllerDispatcher', |
| 35 | - 'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher','JetFire\Routing\Dispatcher\TemplateDispatcher'], |
|
| 35 | + 'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher', 'JetFire\Routing\Dispatcher\TemplateDispatcher'], |
|
| 36 | 36 | ]; |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @param array $resolver |
| 48 | 48 | */ |
| 49 | - public function setResolver($resolver = []){ |
|
| 49 | + public function setResolver($resolver = []) { |
|
| 50 | 50 | $this->resolver = $resolver; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @param string $resolver |
| 55 | 55 | */ |
| 56 | - public function addResolver($resolver){ |
|
| 56 | + public function addResolver($resolver) { |
|
| 57 | 57 | $this->resolver[] = $resolver; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @param $class |
| 79 | 79 | * @return mixed|void |
| 80 | 80 | */ |
| 81 | - public function addDispatcher($method,$class){ |
|
| 81 | + public function addDispatcher($method, $class) { |
|
| 82 | 82 | $this->dispatcher[$method] = $class; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function match() |
| 89 | 89 | { |
| 90 | - foreach($this->resolver as $resolver){ |
|
| 91 | - if(is_array($target = call_user_func([$this,$resolver]))) { |
|
| 90 | + foreach ($this->resolver as $resolver) { |
|
| 91 | + if (is_array($target = call_user_func([$this, $resolver]))) { |
|
| 92 | 92 | $this->setTarget($target); |
| 93 | 93 | $this->router->response->setStatusCode(202); |
| 94 | 94 | return true; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | /** |
| 101 | 101 | * @param array $target |
| 102 | 102 | */ |
| 103 | - public function setTarget($target = []){ |
|
| 103 | + public function setTarget($target = []) { |
|
| 104 | 104 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 105 | 105 | $this->router->route->setDetail($this->request); |
| 106 | 106 | $this->router->route->setTarget($target); |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | /** |
| 112 | 112 | * @return array|bool |
| 113 | 113 | */ |
| 114 | - public function isControllerAndTemplate(){ |
|
| 115 | - if(is_array($ctrl = $this->isController())) { |
|
| 114 | + public function isControllerAndTemplate() { |
|
| 115 | + if (is_array($ctrl = $this->isController())) { |
|
| 116 | 116 | if (is_array($tpl = $this->isTemplate())) { |
| 117 | - return array_merge(array_merge($ctrl, $tpl),[ |
|
| 117 | + return array_merge(array_merge($ctrl, $tpl), [ |
|
| 118 | 118 | 'dispatcher' => $this->dispatcher['isControllerAndTemplate'] |
| 119 | 119 | ]); |
| 120 | 120 | } |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | { |
| 131 | 131 | foreach ($this->router->getConfig()['templateExtension'] as $extension) { |
| 132 | 132 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
| 133 | - $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '',$this->router->route->getUrl())); |
|
| 133 | + $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_'.$i), '', $this->router->route->getUrl())); |
|
| 134 | 134 | $end = array_pop($url); |
| 135 | 135 | $url = implode('/', array_map('ucwords', $url)).'/'.$end; |
| 136 | - if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) { |
|
| 136 | + if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_'.$i), '/').$url.$extension))) { |
|
| 137 | 137 | $this->request['collection_index'] = $i; |
| 138 | 138 | return [ |
| 139 | 139 | 'dispatcher' => $this->dispatcher['isTemplate'], |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | { |
| 155 | 155 | $routes = array_slice(explode('/', $this->router->route->getUrl()), 1); |
| 156 | 156 | $i = 0; |
| 157 | - do{ |
|
| 158 | - $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
| 157 | + do { |
|
| 158 | + $route = ('/'.$routes[0] == $this->router->collection->getRoutes('prefix_'.$i)) ? array_slice($routes, 1) : $routes; |
|
| 159 | 159 | if (isset($route[0])) { |
| 160 | - $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller')) |
|
| 161 | - ? $this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller' |
|
| 162 | - : ucfirst($route[0]) . 'Controller'; |
|
| 163 | - $route[1] = isset($route[1])?$route[1]:'index'; |
|
| 160 | + $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller')) |
|
| 161 | + ? $this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller' |
|
| 162 | + : ucfirst($route[0]).'Controller'; |
|
| 163 | + $route[1] = isset($route[1]) ? $route[1] : 'index'; |
|
| 164 | 164 | if (method_exists($class, $route[1])) { |
| 165 | 165 | $this->request['parameters'] = array_slice($route, 2); |
| 166 | 166 | $this->request['collection_index'] = $i; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | ++$i; |
| 176 | - }while($i < $this->router->collection->countRoutes); |
|
| 176 | + }while ($i < $this->router->collection->countRoutes); |
|
| 177 | 177 | return false; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -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 | /** |
@@ -126,24 +126,24 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function generateRoutesPath() |
| 128 | 128 | { |
| 129 | - $root = (isset($_SERVER['REQUEST_SCHEME'])?$_SERVER['REQUEST_SCHEME']:'http') . '://' . ($domain = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'])) . str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']); |
|
| 129 | + $root = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http').'://'.($domain = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'])).str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']); |
|
| 130 | 130 | if (strpos($domain, ($new_domain = $this->getDomain($root))) !== false) |
| 131 | 131 | $root = str_replace($domain, $new_domain, $root); |
| 132 | 132 | $count = 0; |
| 133 | 133 | for ($i = 0; $i < $this->countRoutes; ++$i) { |
| 134 | - $prefix = (isset($this->routes['prefix_' . $i])) ? $this->routes['prefix_' . $i] : ''; |
|
| 135 | - if (isset($this->routes['routes_' . $i])) |
|
| 136 | - foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
| 134 | + $prefix = (isset($this->routes['prefix_'.$i])) ? $this->routes['prefix_'.$i] : ''; |
|
| 135 | + if (isset($this->routes['routes_'.$i])) |
|
| 136 | + foreach ($this->routes['routes_'.$i] as $route => $dependencies) { |
|
| 137 | 137 | if (is_array($dependencies) && isset($dependencies['use'])) |
| 138 | - $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
| 138 | + $use = (is_callable($dependencies['use'])) ? 'closure-'.$count : trim($dependencies['use'], '/'); |
|
| 139 | 139 | elseif (!is_array($dependencies)) |
| 140 | - $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/'); |
|
| 140 | + $use = (is_callable($dependencies)) ? 'closure-'.$count : trim($dependencies, '/'); |
|
| 141 | 141 | else |
| 142 | 142 | $use = $route; |
| 143 | 143 | if (isset($route[0]) && $route[0] == '/') { |
| 144 | - (!is_callable($dependencies) && isset($dependencies['name'])) ? $this->routesByName[$use . '#' . $dependencies['name']] = $root . $prefix . $route : $this->routesByName[$use] = $root . $prefix . $route; |
|
| 144 | + (!is_callable($dependencies) && isset($dependencies['name'])) ? $this->routesByName[$use.'#'.$dependencies['name']] = $root.$prefix.$route : $this->routesByName[$use] = $root.$prefix.$route; |
|
| 145 | 145 | } else { |
| 146 | - (!is_callable($dependencies) && isset($dependencies['name'])) ? $this->routesByName[$use . '#' . $dependencies['name']] = $_SERVER['REQUEST_SCHEME'] . '://' . str_replace('{host}', $new_domain, $route) . $prefix : $this->routesByName[$use] = $_SERVER['REQUEST_SCHEME'] . '://' . str_replace('{host}', $new_domain, $route) . $prefix; |
|
| 146 | + (!is_callable($dependencies) && isset($dependencies['name'])) ? $this->routesByName[$use.'#'.$dependencies['name']] = $_SERVER['REQUEST_SCHEME'].'://'.str_replace('{host}', $new_domain, $route).$prefix : $this->routesByName[$use] = $_SERVER['REQUEST_SCHEME'].'://'.str_replace('{host}', $new_domain, $route).$prefix; |
|
| 147 | 147 | } |
| 148 | 148 | $count++; |
| 149 | 149 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | foreach ($this->routesByName as $key => $route) { |
| 177 | 177 | $param = explode('#', $key); |
| 178 | 178 | $route = str_replace('{subdomain}', $subdomain, $route); |
| 179 | - foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route); |
|
| 179 | + foreach ($params as $key2 => $value) $route = str_replace(':'.$key2, $value, $route); |
|
| 180 | 180 | if ($param[0] == trim($name, '/')) return $route; |
| 181 | 181 | else if (isset($param[1]) && $param[1] == $name) return $route; |
| 182 | 182 | } |
@@ -33,7 +33,9 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function __construct($routes = null, $options = []) |
| 35 | 35 | { |
| 36 | - if (!is_null($routes) || !empty($options)) $this->addRoutes($routes, $options); |
|
| 36 | + if (!is_null($routes) || !empty($options)) {
|
|
| 37 | + $this->addRoutes($routes, $options); |
|
| 38 | + } |
|
| 37 | 39 | } |
| 38 | 40 | |
| 39 | 41 | /** |
@@ -43,10 +45,16 @@ discard block |
||
| 43 | 45 | public function addRoutes($routes = null, $options = []) |
| 44 | 46 | { |
| 45 | 47 | 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; |
|
| 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'); |
|
| 48 | + if (strpos($routes, '.php') === false) {
|
|
| 49 | + $routes = trim($routes, '/') . '/'; |
|
| 50 | + } |
|
| 51 | + if (is_file($routes . '/routes.php') && is_array($routesFile = include $routes . '/routes.php')) {
|
|
| 52 | + $routes = $routesFile; |
|
| 53 | + } elseif (is_file($routes) && is_array($routesFile = include $routes)) {
|
|
| 54 | + $routes = $routesFile; |
|
| 55 | + } else {
|
|
| 56 | + throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "' . $routes . '" given');
|
|
| 57 | + } |
|
| 50 | 58 | } |
| 51 | 59 | $this->routes['routes_' . $this->countRoutes] = is_array($routes) ? $routes : []; |
| 52 | 60 | $this->setRoutes($options, $this->countRoutes); |
@@ -59,8 +67,9 @@ discard block |
||
| 59 | 67 | */ |
| 60 | 68 | public function getRoutes($key = null) |
| 61 | 69 | { |
| 62 | - if (!is_null($key)) |
|
| 63 | - return isset($this->routes[$key]) ? $this->routes[$key] : ''; |
|
| 70 | + if (!is_null($key)) {
|
|
| 71 | + return isset($this->routes[$key]) ? $this->routes[$key] : ''; |
|
| 72 | + } |
|
| 64 | 73 | return $this->routes; |
| 65 | 74 | } |
| 66 | 75 | |
@@ -71,12 +80,18 @@ discard block |
||
| 71 | 80 | { |
| 72 | 81 | if (is_array($args)) { |
| 73 | 82 | $nbrArgs = count($args); |
| 74 | - for ($i = 0; $i < $nbrArgs; ++$i) |
|
| 75 | - $this->routes['prefix_' . $i] = '/' . trim($args[$i], '/'); |
|
| 76 | - } elseif (is_string($args)) |
|
| 77 | - for ($i = 0; $i < $this->countRoutes; ++$i) |
|
| 78 | - $this->routes['prefix_' . $i] = '/' . trim($args, '/'); |
|
| 79 | - if ($this->countRoutes == 0) $this->countRoutes++; |
|
| 83 | + for ($i = 0; $i < $nbrArgs; ++$i) {
|
|
| 84 | + $this->routes['prefix_' . $i] = '/' . trim($args[$i], '/'); |
|
| 85 | + } |
|
| 86 | + } elseif (is_string($args)) {
|
|
| 87 | + for ($i = 0; |
|
| 88 | + } |
|
| 89 | + $i < $this->countRoutes; ++$i) {
|
|
| 90 | + $this->routes['prefix_' . $i] = '/' . trim($args, '/'); |
|
| 91 | + } |
|
| 92 | + if ($this->countRoutes == 0) {
|
|
| 93 | + $this->countRoutes++; |
|
| 94 | + } |
|
| 80 | 95 | } |
| 81 | 96 | |
| 82 | 97 | /** |
@@ -88,10 +103,14 @@ discard block |
||
| 88 | 103 | for ($i = 0; $i < $nbrArgs; ++$i) { |
| 89 | 104 | if (is_array($args[$i])) { |
| 90 | 105 | $this->setRoutes($args[$i], $i); |
| 91 | - if (!isset($this->routes['routes_' . $i])) $this->routes['routes_' . $i] = []; |
|
| 106 | + if (!isset($this->routes['routes_' . $i])) {
|
|
| 107 | + $this->routes['routes_' . $i] = []; |
|
| 108 | + } |
|
| 92 | 109 | } |
| 93 | 110 | } |
| 94 | - if ($this->countRoutes == 0) $this->countRoutes++; |
|
| 111 | + if ($this->countRoutes == 0) {
|
|
| 112 | + $this->countRoutes++; |
|
| 113 | + } |
|
| 95 | 114 | } |
| 96 | 115 | |
| 97 | 116 | /** |
@@ -113,12 +132,16 @@ discard block |
||
| 113 | 132 | */ |
| 114 | 133 | public function setMiddleware($middleware) |
| 115 | 134 | { |
| 116 | - if (is_string($middleware)) $middleware = rtrim($middleware, '/'); |
|
| 117 | - if (is_array($middleware)) |
|
| 118 | - $this->middleware = $middleware; |
|
| 119 | - elseif (is_file($middleware) && is_array($mid = include $middleware)) |
|
| 120 | - $this->middleware = $mid; |
|
| 121 | - else throw new \InvalidArgumentException('Accepted argument for setMiddleware are array and array file'); |
|
| 135 | + if (is_string($middleware)) {
|
|
| 136 | + $middleware = rtrim($middleware, '/'); |
|
| 137 | + } |
|
| 138 | + if (is_array($middleware)) {
|
|
| 139 | + $this->middleware = $middleware; |
|
| 140 | + } elseif (is_file($middleware) && is_array($mid = include $middleware)) {
|
|
| 141 | + $this->middleware = $mid; |
|
| 142 | + } else {
|
|
| 143 | + throw new \InvalidArgumentException('Accepted argument for setMiddleware are array and array file');
|
|
| 144 | + } |
|
| 122 | 145 | } |
| 123 | 146 | |
| 124 | 147 | /** |
@@ -127,19 +150,21 @@ discard block |
||
| 127 | 150 | public function generateRoutesPath() |
| 128 | 151 | { |
| 129 | 152 | $root = (isset($_SERVER['REQUEST_SCHEME'])?$_SERVER['REQUEST_SCHEME']:'http') . '://' . ($domain = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'])) . str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']); |
| 130 | - if (strpos($domain, ($new_domain = $this->getDomain($root))) !== false) |
|
| 131 | - $root = str_replace($domain, $new_domain, $root); |
|
| 153 | + if (strpos($domain, ($new_domain = $this->getDomain($root))) !== false) {
|
|
| 154 | + $root = str_replace($domain, $new_domain, $root); |
|
| 155 | + } |
|
| 132 | 156 | $count = 0; |
| 133 | 157 | for ($i = 0; $i < $this->countRoutes; ++$i) { |
| 134 | 158 | $prefix = (isset($this->routes['prefix_' . $i])) ? $this->routes['prefix_' . $i] : ''; |
| 135 | - if (isset($this->routes['routes_' . $i])) |
|
| 136 | - foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
| 159 | + if (isset($this->routes['routes_' . $i])) {
|
|
| 160 | + foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
| 137 | 161 | if (is_array($dependencies) && isset($dependencies['use'])) |
| 138 | - $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
| 139 | - elseif (!is_array($dependencies)) |
|
| 140 | - $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/'); |
|
| 141 | - else |
|
| 142 | - $use = $route; |
|
| 162 | + $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
| 163 | + } elseif (!is_array($dependencies)) {
|
|
| 164 | + $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/'); |
|
| 165 | + } else {
|
|
| 166 | + $use = $route; |
|
| 167 | + } |
|
| 143 | 168 | if (isset($route[0]) && $route[0] == '/') { |
| 144 | 169 | (!is_callable($dependencies) && isset($dependencies['name'])) ? $this->routesByName[$use . '#' . $dependencies['name']] = $root . $prefix . $route : $this->routesByName[$use] = $root . $prefix . $route; |
| 145 | 170 | } else { |
@@ -176,9 +201,14 @@ discard block |
||
| 176 | 201 | foreach ($this->routesByName as $key => $route) { |
| 177 | 202 | $param = explode('#', $key); |
| 178 | 203 | $route = str_replace('{subdomain}', $subdomain, $route); |
| 179 | - foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route); |
|
| 180 | - if ($param[0] == trim($name, '/')) return $route; |
|
| 181 | - else if (isset($param[1]) && $param[1] == $name) return $route; |
|
| 204 | + foreach ($params as $key2 => $value) {
|
|
| 205 | + $route = str_replace(':' . $key2, $value, $route);
|
|
| 206 | + } |
|
| 207 | + if ($param[0] == trim($name, '/')) {
|
|
| 208 | + return $route; |
|
| 209 | + } else if (isset($param[1]) && $param[1] == $name) {
|
|
| 210 | + return $route; |
|
| 211 | + } |
|
| 182 | 212 | } |
| 183 | 213 | return null; |
| 184 | 214 | } |