@@ -47,12 +47,12 @@ discard block |
||
47 | 47 | public function addRoutes($routes = null, $options = []) |
48 | 48 | { |
49 | 49 | if (!is_null($routes) && !is_array($routes)) { |
50 | - if (strpos($routes, '.php') === false) $routes = trim($routes, '/') . '/'; |
|
51 | - if (is_file($routes . '/routes.php') && is_array($routesFile = include $routes . '/routes.php')) $routes = $routesFile; |
|
50 | + if (strpos($routes, '.php') === false) $routes = trim($routes, '/').'/'; |
|
51 | + if (is_file($routes.'/routes.php') && is_array($routesFile = include $routes.'/routes.php')) $routes = $routesFile; |
|
52 | 52 | elseif (is_file($routes) && is_array($routesFile = include $routes)) $routes = $routesFile; |
53 | - else throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "' . $routes . '" given'); |
|
53 | + else throw new \InvalidArgumentException('Argument for "'.get_called_class().'" constructor is not recognized. Expected argument array or file containing array but "'.$routes.'" given'); |
|
54 | 54 | } |
55 | - $this->routes['routes_' . $this->countRoutes] = is_array($routes) ? $routes : []; |
|
55 | + $this->routes['routes_'.$this->countRoutes] = is_array($routes) ? $routes : []; |
|
56 | 56 | $this->setRoutes($options, $this->countRoutes); |
57 | 57 | $this->countRoutes++; |
58 | 58 | } |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | if (is_array($args)) { |
77 | 77 | $nbrArgs = count($args); |
78 | 78 | for ($i = 0; $i < $nbrArgs; ++$i) |
79 | - $this->routes['prefix_' . $i] = '/' . trim($args[$i], '/'); |
|
79 | + $this->routes['prefix_'.$i] = '/'.trim($args[$i], '/'); |
|
80 | 80 | } elseif (is_string($args)) |
81 | 81 | for ($i = 0; $i < $this->countRoutes; ++$i) |
82 | - $this->routes['prefix_' . $i] = '/' . trim($args, '/'); |
|
82 | + $this->routes['prefix_'.$i] = '/'.trim($args, '/'); |
|
83 | 83 | if ($this->countRoutes == 0) $this->countRoutes++; |
84 | 84 | } |
85 | 85 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | for ($i = 0; $i < $nbrArgs; ++$i) { |
93 | 93 | if (is_array($args[$i])) { |
94 | 94 | $this->setRoutes($args[$i], $i); |
95 | - if (!isset($this->routes['routes_' . $i])) $this->routes['routes_' . $i] = []; |
|
95 | + if (!isset($this->routes['routes_'.$i])) $this->routes['routes_'.$i] = []; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | if ($this->countRoutes == 0) $this->countRoutes++; |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | */ |
105 | 105 | private function setRoutes($args = [], $i) |
106 | 106 | { |
107 | - $this->routes['block_' . $i] = (isset($args['block']) && !empty($args['block'])) ? rtrim($args['block'], '/') . '/' : ''; |
|
108 | - $this->routes['view_dir_' . $i] = (isset($args['view_dir']) && !empty($args['view_dir'])) ? rtrim($args['view_dir'], '/') . '/' : ''; |
|
109 | - $this->routes['ctrl_namespace_' . $i] = (isset($args['ctrl_namespace']) && !empty($args['ctrl_namespace'])) ? trim($args['ctrl_namespace'], '\\') . '\\' : ''; |
|
110 | - $this->routes['prefix_' . $i] = (isset($args['prefix']) && !empty($args['prefix'])) ? '/' . trim($args['prefix'], '/') : ''; |
|
111 | - $this->routes['subdomain_' . $i] = (isset($args['subdomain'])) ? $args['subdomain'] : ''; |
|
107 | + $this->routes['block_'.$i] = (isset($args['block']) && !empty($args['block'])) ? rtrim($args['block'], '/').'/' : ''; |
|
108 | + $this->routes['view_dir_'.$i] = (isset($args['view_dir']) && !empty($args['view_dir'])) ? rtrim($args['view_dir'], '/').'/' : ''; |
|
109 | + $this->routes['ctrl_namespace_'.$i] = (isset($args['ctrl_namespace']) && !empty($args['ctrl_namespace'])) ? trim($args['ctrl_namespace'], '\\').'\\' : ''; |
|
110 | + $this->routes['prefix_'.$i] = (isset($args['prefix']) && !empty($args['prefix'])) ? '/'.trim($args['prefix'], '/') : ''; |
|
111 | + $this->routes['subdomain_'.$i] = (isset($args['subdomain'])) ? $args['subdomain'] : ''; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -130,30 +130,30 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function generateRoutesPath() |
132 | 132 | { |
133 | - $root = ($protocol = (isset($_SERVER['REQUEST_SCHEME'])?$_SERVER['REQUEST_SCHEME']:'http')) . '://' . ($domain = $_SERVER['SERVER_NAME']) . (!empty($_SERVER['SERVER_PORT']) ? ':'.$_SERVER['SERVER_PORT'] : '' ) . str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']); |
|
133 | + $root = ($protocol = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http')).'://'.($domain = $_SERVER['SERVER_NAME']).(!empty($_SERVER['SERVER_PORT']) ? ':'.$_SERVER['SERVER_PORT'] : '').str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']); |
|
134 | 134 | if (strpos($domain, ($new_domain = $this->getDomain($root))) !== false) |
135 | 135 | $root = str_replace($domain, $new_domain, $root); |
136 | 136 | $count = 0; |
137 | 137 | for ($i = 0; $i < $this->countRoutes; ++$i) { |
138 | - $prefix = (isset($this->routes['prefix_' . $i])) ? $this->routes['prefix_' . $i] : ''; |
|
139 | - $subdomain = (isset($this->routes['subdomain_' . $i])) ? $this->routes['subdomain_' . $i] : ''; |
|
140 | - $url = (!empty($subdomain)) ? str_replace($protocol.'://',$protocol.'://'.$subdomain.'.' ,$root) : $root; |
|
141 | - if (isset($this->routes['routes_' . $i])) |
|
142 | - foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
138 | + $prefix = (isset($this->routes['prefix_'.$i])) ? $this->routes['prefix_'.$i] : ''; |
|
139 | + $subdomain = (isset($this->routes['subdomain_'.$i])) ? $this->routes['subdomain_'.$i] : ''; |
|
140 | + $url = (!empty($subdomain)) ? str_replace($protocol.'://', $protocol.'://'.$subdomain.'.', $root) : $root; |
|
141 | + if (isset($this->routes['routes_'.$i])) |
|
142 | + foreach ($this->routes['routes_'.$i] as $route => $dependencies) { |
|
143 | 143 | if (is_array($dependencies) && isset($dependencies['use'])) |
144 | - $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
144 | + $use = (is_callable($dependencies['use'])) ? 'closure-'.$count : trim($dependencies['use'], '/'); |
|
145 | 145 | elseif (!is_array($dependencies)) |
146 | - $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/'); |
|
146 | + $use = (is_callable($dependencies)) ? 'closure-'.$count : trim($dependencies, '/'); |
|
147 | 147 | else |
148 | 148 | $use = $route; |
149 | 149 | if (isset($route[0]) && $route[0] == '/') { |
150 | 150 | (!is_callable($dependencies) && isset($dependencies['name'])) |
151 | - ? $this->routesByName[$use . '#' . $dependencies['name']] = $url . $prefix . $route |
|
152 | - : $this->routesByName[$use] = $url . $prefix . $route; |
|
151 | + ? $this->routesByName[$use.'#'.$dependencies['name']] = $url.$prefix.$route |
|
152 | + : $this->routesByName[$use] = $url.$prefix.$route; |
|
153 | 153 | } else { |
154 | 154 | (!is_callable($dependencies) && isset($dependencies['name'])) |
155 | - ? $this->routesByName[$use . '#' . $dependencies['name']] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix |
|
156 | - : $this->routesByName[$use] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix; |
|
155 | + ? $this->routesByName[$use.'#'.$dependencies['name']] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix |
|
156 | + : $this->routesByName[$use] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix; |
|
157 | 157 | } |
158 | 158 | $count++; |
159 | 159 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | foreach ($this->routesByName as $key => $route) { |
187 | 187 | $param = explode('#', $key); |
188 | 188 | $route = str_replace('{subdomain}', $subdomain, $route); |
189 | - foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route); |
|
189 | + foreach ($params as $key2 => $value) $route = str_replace(':'.$key2, $value, $route); |
|
190 | 190 | if ($param[0] == trim($name, '/')) return $route; |
191 | 191 | else if (isset($param[1]) && $param[1] == $name) return $route; |
192 | 192 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | if (is_array($blocks)) { |
47 | 47 | foreach ($blocks as $block) |
48 | 48 | if (class_exists($block)) |
49 | - if($this->callHandler($block) === false) return false; |
|
49 | + if ($this->callHandler($block) === false) return false; |
|
50 | 50 | } |
51 | 51 | elseif (is_string($blocks) && class_exists($blocks)) |
52 | 52 | return $this->callHandler($blocks); |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | $ctrl = str_replace('\\', '/', $this->router->route->getTarget('controller')); |
64 | 64 | if (isset($this->router->collection->middleware['class_middleware'][$ctrl]) && class_exists($this->router->route->getTarget('controller'))) { |
65 | 65 | $classes = $this->router->collection->middleware['class_middleware'][$ctrl]; |
66 | - if(is_array($classes)){ |
|
66 | + if (is_array($classes)) { |
|
67 | 67 | foreach ($classes as $class) |
68 | - if($this->callHandler($class) === false)return false; |
|
69 | - }elseif(is_string($classes)) |
|
68 | + if ($this->callHandler($class) === false)return false; |
|
69 | + }elseif (is_string($classes)) |
|
70 | 70 | return $this->callHandler($classes); |
71 | 71 | } |
72 | 72 | } |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | if (isset($this->router->collection->middleware['route_middleware'])) |
82 | 82 | if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) { |
83 | 83 | $classes = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']]; |
84 | - if(is_array($classes)){ |
|
84 | + if (is_array($classes)) { |
|
85 | 85 | foreach ($classes as $class) |
86 | - if($this->callHandler($class) === false)return false; |
|
87 | - }elseif(is_string($classes)) |
|
86 | + if ($this->callHandler($class) === false)return false; |
|
87 | + }elseif (is_string($classes)) |
|
88 | 88 | return $this->callHandler($classes); |
89 | 89 | } |
90 | 90 | return null; |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @param $class |
95 | 95 | * @return mixed |
96 | 96 | */ |
97 | - private function callHandler($class){ |
|
98 | - $instance = call_user_func($this->router->getConfig()['di'],$class); |
|
97 | + private function callHandler($class) { |
|
98 | + $instance = call_user_func($this->router->getConfig()['di'], $class); |
|
99 | 99 | if (method_exists($instance, 'handle')) { |
100 | 100 | $reflectionMethod = new ReflectionMethod($instance, 'handle'); |
101 | 101 | $dependencies = []; |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param $class |
113 | 113 | * @return Route|RouteCollection|Router|mixed |
114 | 114 | */ |
115 | - private function getClass($class){ |
|
116 | - switch($class){ |
|
115 | + private function getClass($class) { |
|
116 | + switch ($class) { |
|
117 | 117 | case 'JetFire\Routing\Route': |
118 | 118 | return $this->router->route; |
119 | 119 | case 'JetFire\Routing\Router': |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | case 'JetFire\Routing\RouteCollection': |
122 | 122 | return $this->router->collection; |
123 | 123 | default: |
124 | - return call_user_func_array($this->router->getConfig()['di'],[$class]); |
|
124 | + return call_user_func_array($this->router->getConfig()['di'], [$class]); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |