@@ -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,30 +126,30 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function generateRoutesPath() |
128 | 128 | { |
129 | - $root = ($protocol = (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 = ($protocol = (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 | - $subdomain = (isset($this->routes['subdomain_' . $i])) ? $this->routes['subdomain_' . $i] : ''; |
|
136 | - $url = (!empty($subdomain)) ? str_replace($protocol.'://',$protocol.'://'.$subdomain.'.' ,$root) : $root; |
|
137 | - if (isset($this->routes['routes_' . $i])) |
|
138 | - foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
134 | + $prefix = (isset($this->routes['prefix_'.$i])) ? $this->routes['prefix_'.$i] : ''; |
|
135 | + $subdomain = (isset($this->routes['subdomain_'.$i])) ? $this->routes['subdomain_'.$i] : ''; |
|
136 | + $url = (!empty($subdomain)) ? str_replace($protocol.'://', $protocol.'://'.$subdomain.'.', $root) : $root; |
|
137 | + if (isset($this->routes['routes_'.$i])) |
|
138 | + foreach ($this->routes['routes_'.$i] as $route => $dependencies) { |
|
139 | 139 | if (is_array($dependencies) && isset($dependencies['use'])) |
140 | - $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
140 | + $use = (is_callable($dependencies['use'])) ? 'closure-'.$count : trim($dependencies['use'], '/'); |
|
141 | 141 | elseif (!is_array($dependencies)) |
142 | - $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/'); |
|
142 | + $use = (is_callable($dependencies)) ? 'closure-'.$count : trim($dependencies, '/'); |
|
143 | 143 | else |
144 | 144 | $use = $route; |
145 | 145 | if (isset($route[0]) && $route[0] == '/') { |
146 | 146 | (!is_callable($dependencies) && isset($dependencies['name'])) |
147 | - ? $this->routesByName[$use . '#' . $dependencies['name']] = $url . $prefix . $route |
|
148 | - : $this->routesByName[$use] = $url . $prefix . $route; |
|
147 | + ? $this->routesByName[$use.'#'.$dependencies['name']] = $url.$prefix.$route |
|
148 | + : $this->routesByName[$use] = $url.$prefix.$route; |
|
149 | 149 | } else { |
150 | 150 | (!is_callable($dependencies) && isset($dependencies['name'])) |
151 | - ? $this->routesByName[$use . '#' . $dependencies['name']] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix |
|
152 | - : $this->routesByName[$use] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix; |
|
151 | + ? $this->routesByName[$use.'#'.$dependencies['name']] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix |
|
152 | + : $this->routesByName[$use] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix; |
|
153 | 153 | } |
154 | 154 | $count++; |
155 | 155 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | foreach ($this->routesByName as $key => $route) { |
183 | 183 | $param = explode('#', $key); |
184 | 184 | $route = str_replace('{subdomain}', $subdomain, $route); |
185 | - foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route); |
|
185 | + foreach ($params as $key2 => $value) $route = str_replace(':'.$key2, $value, $route); |
|
186 | 186 | if ($param[0] == trim($name, '/')) return $route; |
187 | 187 | else if (isset($param[1]) && $param[1] == $name) return $route; |
188 | 188 | } |