@@ -166,8 +166,9 @@ |
||
166 | 166 | */ |
167 | 167 | public function sendHeaders() |
168 | 168 | { |
169 | - foreach($this->headers as $key => $content) |
|
170 | - header($key.' : '.$content); |
|
169 | + foreach($this->headers as $key => $content) { |
|
170 | + header($key.' : '.$content); |
|
171 | + } |
|
171 | 172 | http_response_code($this->getStatusCode()); |
172 | 173 | return $this; |
173 | 174 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * Class Response |
8 | 8 | * @package JetFire\Routing |
9 | 9 | */ |
10 | -class Response implements ResponseInterface{ |
|
10 | +class Response implements ResponseInterface { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @var array |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | public static $statusTexts = array( |
54 | 54 | 100 => 'Continue', |
55 | 55 | 101 => 'Switching Protocols', |
56 | - 102 => 'Processing', // RFC2518 |
|
56 | + 102 => 'Processing', // RFC2518 |
|
57 | 57 | 200 => 'OK', |
58 | 58 | 201 => 'Created', |
59 | 59 | 202 => 'Accepted', |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | 204 => 'No Content', |
62 | 62 | 205 => 'Reset Content', |
63 | 63 | 206 => 'Partial Content', |
64 | - 207 => 'Multi-Status', // RFC4918 |
|
65 | - 208 => 'Already Reported', // RFC5842 |
|
66 | - 226 => 'IM Used', // RFC3229 |
|
64 | + 207 => 'Multi-Status', // RFC4918 |
|
65 | + 208 => 'Already Reported', // RFC5842 |
|
66 | + 226 => 'IM Used', // RFC3229 |
|
67 | 67 | 300 => 'Multiple Choices', |
68 | 68 | 301 => 'Moved Permanently', |
69 | 69 | 302 => 'Found', |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | 304 => 'Not Modified', |
72 | 72 | 305 => 'Use Proxy', |
73 | 73 | 307 => 'Temporary Redirect', |
74 | - 308 => 'Permanent Redirect', // RFC7238 |
|
74 | + 308 => 'Permanent Redirect', // RFC7238 |
|
75 | 75 | 400 => 'Bad Request', |
76 | 76 | 401 => 'Unauthorized', |
77 | 77 | 402 => 'Payment Required', |
@@ -90,26 +90,26 @@ discard block |
||
90 | 90 | 415 => 'Unsupported Media Type', |
91 | 91 | 416 => 'Range Not Satisfiable', |
92 | 92 | 417 => 'Expectation Failed', |
93 | - 418 => 'I\'m a teapot', // RFC2324 |
|
94 | - 422 => 'Unprocessable Entity', // RFC4918 |
|
95 | - 423 => 'Locked', // RFC4918 |
|
96 | - 424 => 'Failed Dependency', // RFC4918 |
|
97 | - 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
|
98 | - 426 => 'Upgrade Required', // RFC2817 |
|
99 | - 428 => 'Precondition Required', // RFC6585 |
|
100 | - 429 => 'Too Many Requests', // RFC6585 |
|
101 | - 431 => 'Request Header Fields Too Large', // RFC6585 |
|
93 | + 418 => 'I\'m a teapot', // RFC2324 |
|
94 | + 422 => 'Unprocessable Entity', // RFC4918 |
|
95 | + 423 => 'Locked', // RFC4918 |
|
96 | + 424 => 'Failed Dependency', // RFC4918 |
|
97 | + 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
|
98 | + 426 => 'Upgrade Required', // RFC2817 |
|
99 | + 428 => 'Precondition Required', // RFC6585 |
|
100 | + 429 => 'Too Many Requests', // RFC6585 |
|
101 | + 431 => 'Request Header Fields Too Large', // RFC6585 |
|
102 | 102 | 500 => 'Internal Server Error', |
103 | 103 | 501 => 'Not Implemented', |
104 | 104 | 502 => 'Bad Gateway', |
105 | 105 | 503 => 'Service Unavailable', |
106 | 106 | 504 => 'Gateway Timeout', |
107 | 107 | 505 => 'HTTP Version Not Supported', |
108 | - 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 |
|
109 | - 507 => 'Insufficient Storage', // RFC4918 |
|
110 | - 508 => 'Loop Detected', // RFC5842 |
|
111 | - 510 => 'Not Extended', // RFC2774 |
|
112 | - 511 => 'Network Authentication Required', // RFC6585 |
|
108 | + 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 |
|
109 | + 507 => 'Insufficient Storage', // RFC4918 |
|
110 | + 508 => 'Loop Detected', // RFC5842 |
|
111 | + 510 => 'Not Extended', // RFC2774 |
|
112 | + 511 => 'Network Authentication Required', // RFC6585 |
|
113 | 113 | ); |
114 | 114 | |
115 | 115 | /** |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function sendHeaders() |
168 | 168 | { |
169 | - foreach($this->headers as $key => $content) |
|
169 | + foreach ($this->headers as $key => $content) |
|
170 | 170 | header($key.' : '.$content); |
171 | 171 | http_response_code($this->getStatusCode()); |
172 | 172 | return $this; |
@@ -52,10 +52,18 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function set($args = []) |
54 | 54 | { |
55 | - if (isset($args['name'])) $this->name = $args['name']; |
|
56 | - if (isset($args['callback'])) $this->callback = $args['callback']; |
|
57 | - if (isset($args['target'])) $this->target = $args['target']; |
|
58 | - if (isset($args['detail'])) $this->detail = $args['detail']; |
|
55 | + if (isset($args['name'])) { |
|
56 | + $this->name = $args['name']; |
|
57 | + } |
|
58 | + if (isset($args['callback'])) { |
|
59 | + $this->callback = $args['callback']; |
|
60 | + } |
|
61 | + if (isset($args['target'])) { |
|
62 | + $this->target = $args['target']; |
|
63 | + } |
|
64 | + if (isset($args['detail'])) { |
|
65 | + $this->detail = $args['detail']; |
|
66 | + } |
|
59 | 67 | } |
60 | 68 | |
61 | 69 | /** |
@@ -145,8 +153,9 @@ discard block |
||
145 | 153 | */ |
146 | 154 | public function getTarget($key = null) |
147 | 155 | { |
148 | - if (!is_null($key)) |
|
149 | - return isset($this->target[$key]) ? $this->target[$key] : ''; |
|
156 | + if (!is_null($key)) { |
|
157 | + return isset($this->target[$key]) ? $this->target[$key] : ''; |
|
158 | + } |
|
150 | 159 | return empty($this->target) ? '' : $this->target; |
151 | 160 | } |
152 | 161 | |
@@ -165,8 +174,9 @@ discard block |
||
165 | 174 | */ |
166 | 175 | public function hasTarget($key = null) |
167 | 176 | { |
168 | - if (!is_null($key)) |
|
169 | - return isset($this->target[$key]) ? true : false; |
|
177 | + if (!is_null($key)) { |
|
178 | + return isset($this->target[$key]) ? true : false; |
|
179 | + } |
|
170 | 180 | return empty($this->target) ? false : true; |
171 | 181 | } |
172 | 182 |
@@ -41,7 +41,7 @@ |
||
41 | 41 | * @param $method |
42 | 42 | * @param $class |
43 | 43 | */ |
44 | - public function addDispatcher($method,$class); |
|
44 | + public function addDispatcher($method, $class); |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @return mixed |
@@ -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)) { |
@@ -49,10 +49,11 @@ |
||
49 | 49 | |
50 | 50 | foreach ($reflectionMethod->getParameters() as $arg) { |
51 | 51 | if (!is_null($arg->getClass())) { |
52 | - if (isset($classInstance[$arg->getClass()->name])) |
|
53 | - $dependencies[] = $classInstance[$arg->getClass()->name]; |
|
54 | - else |
|
55 | - $dependencies[] = call_user_func_array($this->router->route->getTarget('di'), [$arg->getClass()->name]); |
|
52 | + if (isset($classInstance[$arg->getClass()->name])) { |
|
53 | + $dependencies[] = $classInstance[$arg->getClass()->name]; |
|
54 | + } else { |
|
55 | + $dependencies[] = call_user_func_array($this->router->route->getTarget('di'), [$arg->getClass()->name]); |
|
56 | + } |
|
56 | 57 | } else { |
57 | 58 | $count++; |
58 | 59 | } |
@@ -44,8 +44,12 @@ |
||
44 | 44 | $this->router->response->setContent(call_user_func_array($this->router->route->getTarget('callback')[$this->router->route->getTarget('extension')], [$this->router->route])); |
45 | 45 | } else { |
46 | 46 | ob_start(); |
47 | - if (isset($this->router->route->getTarget()['data'])) extract($this->router->route->getTarget('data')); |
|
48 | - if (isset($this->router->route->getParams()['data'])) extract($this->router->route->getParams()['data']); |
|
47 | + if (isset($this->router->route->getTarget()['data'])) { |
|
48 | + extract($this->router->route->getTarget('data')); |
|
49 | + } |
|
50 | + if (isset($this->router->route->getParams()['data'])) { |
|
51 | + extract($this->router->route->getParams()['data']); |
|
52 | + } |
|
49 | 53 | require($this->router->route->getTarget('template')); |
50 | 54 | $this->router->response->setContent(ob_get_clean()); |
51 | 55 | } |
@@ -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 | /** |
@@ -121,7 +140,7 @@ discard block |
||
121 | 140 | if(!is_null($root)){ |
122 | 141 | $protocol = explode('://', $root); |
123 | 142 | $protocol = $protocol[0]; |
124 | - }else{ |
|
143 | + } else{ |
|
125 | 144 | $root = $protocol . '://' . $domain . ((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':' . $_SERVER['SERVER_PORT'] : '') . str_replace('/' . $script_file, '', $_SERVER['SCRIPT_NAME']); |
126 | 145 | } |
127 | 146 | |
@@ -136,10 +155,11 @@ discard block |
||
136 | 155 | $subdomain = (isset($this->routes['subdomain_' . $i])) ? $this->routes['subdomain_' . $i] : ''; |
137 | 156 | $block_protocol = (isset($this->routes['protocol_' . $i])) ? $this->routes['protocol_' . $i] : 'http'; |
138 | 157 | $url = (!empty($subdomain)) ? str_replace($protocol . '://', $block_protocol . '://' . $subdomain . '.', $root) : $root; |
139 | - if (isset($this->routes['routes_' . $i])) |
|
140 | - foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
158 | + if (isset($this->routes['routes_' . $i])) { |
|
159 | + foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
141 | 160 | if (is_array($dependencies) && isset($dependencies['use']) && !is_array($dependencies['use'])) { |
142 | - $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
161 | + $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
162 | + } |
|
143 | 163 | } elseif (!is_array($dependencies)) { |
144 | 164 | $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/'); |
145 | 165 | } else { |
@@ -187,9 +207,14 @@ discard block |
||
187 | 207 | foreach ($this->routesByName as $key => $route) { |
188 | 208 | $param = explode('#', $key); |
189 | 209 | $route = str_replace('{subdomain}', $subdomain, $route); |
190 | - foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route); |
|
191 | - if ($param[0] == trim($name, '/')) return $route; |
|
192 | - else if (isset($param[1]) && $param[1] == $name) return $route; |
|
210 | + foreach ($params as $key2 => $value) { |
|
211 | + $route = str_replace(':' . $key2, $value, $route); |
|
212 | + } |
|
213 | + if ($param[0] == trim($name, '/')) { |
|
214 | + return $route; |
|
215 | + } else if (isset($param[1]) && $param[1] == $name) { |
|
216 | + return $route; |
|
217 | + } |
|
193 | 218 | } |
194 | 219 | return null; |
195 | 220 | } |
@@ -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,13 +100,13 @@ 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'] : ''; |
|
108 | - $this->routes['protocol_' . $i] = (isset($args['protocol'])) ? $args['protocol'] : 'http'; |
|
109 | - $this->routes['params_' . $i] = (isset($args['params'])) ? $args['params'] : []; |
|
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 | + $this->routes['protocol_'.$i] = (isset($args['protocol'])) ? $args['protocol'] : 'http'; |
|
109 | + $this->routes['params_'.$i] = (isset($args['params'])) ? $args['params'] : []; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | $protocol = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http'; |
120 | 120 | $domain = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
121 | 121 | |
122 | - if(!is_null($root)){ |
|
122 | + if (!is_null($root)) { |
|
123 | 123 | $protocol = explode('://', $root); |
124 | 124 | $protocol = $protocol[0]; |
125 | - }else{ |
|
126 | - $root = $protocol . '://' . $domain . ((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':' . $_SERVER['SERVER_PORT'] : '') . str_replace('/' . $script_file, '', $_SERVER['SCRIPT_NAME']); |
|
125 | + } else { |
|
126 | + $root = $protocol.'://'.$domain.((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').str_replace('/'.$script_file, '', $_SERVER['SCRIPT_NAME']); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | $new_domain = $this->getDomain($root); |
@@ -133,29 +133,29 @@ discard block |
||
133 | 133 | |
134 | 134 | $count = 0; |
135 | 135 | for ($i = 0; $i < $this->countRoutes; ++$i) { |
136 | - $prefix = (isset($this->routes['prefix_' . $i])) ? $this->routes['prefix_' . $i] : ''; |
|
137 | - $subdomain = (isset($this->routes['subdomain_' . $i])) ? $this->routes['subdomain_' . $i] : ''; |
|
138 | - $block_protocol = (isset($this->routes['protocol_' . $i])) ? $this->routes['protocol_' . $i] : 'http'; |
|
139 | - $url = (!empty($subdomain)) ? str_replace($protocol . '://', $block_protocol . '://' . $subdomain . '.', $root) : $root; |
|
140 | - if (isset($this->routes['routes_' . $i])) |
|
141 | - foreach ($this->routes['routes_' . $i] as $route => $dependencies) { |
|
136 | + $prefix = (isset($this->routes['prefix_'.$i])) ? $this->routes['prefix_'.$i] : ''; |
|
137 | + $subdomain = (isset($this->routes['subdomain_'.$i])) ? $this->routes['subdomain_'.$i] : ''; |
|
138 | + $block_protocol = (isset($this->routes['protocol_'.$i])) ? $this->routes['protocol_'.$i] : 'http'; |
|
139 | + $url = (!empty($subdomain)) ? str_replace($protocol.'://', $block_protocol.'://'.$subdomain.'.', $root) : $root; |
|
140 | + if (isset($this->routes['routes_'.$i])) |
|
141 | + foreach ($this->routes['routes_'.$i] as $route => $dependencies) { |
|
142 | 142 | if (is_array($dependencies) && isset($dependencies['use']) && !is_array($dependencies['use'])) { |
143 | - $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/'); |
|
143 | + $use = (is_callable($dependencies['use'])) ? 'closure-'.$count : trim($dependencies['use'], '/'); |
|
144 | 144 | } elseif (!is_array($dependencies)) { |
145 | - $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/'); |
|
145 | + $use = (is_callable($dependencies)) ? 'closure-'.$count : trim($dependencies, '/'); |
|
146 | 146 | } else { |
147 | 147 | $use = $route; |
148 | 148 | } |
149 | 149 | if (isset($route[0]) && $route[0] == '/') { |
150 | - $full_url = rtrim($url, '/') . '/' . trim($prefix, '/') . (empty($prefix) ? '' : '/') . trim($route, '/'); |
|
150 | + $full_url = rtrim($url, '/').'/'.trim($prefix, '/').(empty($prefix) ? '' : '/').trim($route, '/'); |
|
151 | 151 | (!is_callable($dependencies) && isset($dependencies['name'])) |
152 | - ? $this->routesByName[$use . '#' . $dependencies['name']] = $full_url |
|
152 | + ? $this->routesByName[$use.'#'.$dependencies['name']] = $full_url |
|
153 | 153 | : $this->routesByName[$use] = $full_url; |
154 | 154 | } else { |
155 | - $full_url = $block_protocol . '://' . str_replace('{host}', $new_domain, $route); |
|
155 | + $full_url = $block_protocol.'://'.str_replace('{host}', $new_domain, $route); |
|
156 | 156 | (!is_callable($dependencies) && isset($dependencies['name'])) |
157 | - ? $this->routesByName[$use . '#' . $dependencies['name']] = $full_url . $prefix |
|
158 | - : $this->routesByName[$use] = $full_url . $prefix; |
|
157 | + ? $this->routesByName[$use.'#'.$dependencies['name']] = $full_url.$prefix |
|
158 | + : $this->routesByName[$use] = $full_url.$prefix; |
|
159 | 159 | } |
160 | 160 | $count++; |
161 | 161 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | foreach ($this->routesByName as $key => $route) { |
189 | 189 | $param = explode('#', $key); |
190 | 190 | $route = str_replace('{subdomain}', $subdomain, $route); |
191 | - foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route); |
|
191 | + foreach ($params as $key2 => $value) $route = str_replace(':'.$key2, $value, $route); |
|
192 | 192 | if ($param[0] == trim($name, '/')) return $route; |
193 | 193 | else if (isset($param[1]) && $param[1] == $name) return $route; |
194 | 194 | } |
@@ -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,10 +123,10 @@ 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 | - }else{ |
|
129 | + } else { |
|
130 | 130 | $this->response->setStatusCode(404); |
131 | 131 | } |
132 | 132 | $this->callMiddleware('after'); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | { |
158 | 158 | if (is_null($url)) |
159 | 159 | $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
160 | - $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
|
160 | + $this->route->setUrl('/'.trim(explode('?', $url)[0], '/')); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -120,13 +120,15 @@ discard block |
||
120 | 120 | public function run() |
121 | 121 | { |
122 | 122 | $this->setUrl(); |
123 | - if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath(); |
|
123 | + if ($this->config['generateRoutesPath']) { |
|
124 | + $this->collection->generateRoutesPath(); |
|
125 | + } |
|
124 | 126 | if ($this->match() === true) { |
125 | 127 | $this->callMiddleware('before'); |
126 | 128 | if (!in_array(substr($this->response->getStatusCode(), 0, 1), [3,4,5])) { |
127 | 129 | $this->callTarget(); |
128 | 130 | } |
129 | - }else{ |
|
131 | + } else{ |
|
130 | 132 | $this->response->setStatusCode(404); |
131 | 133 | } |
132 | 134 | $this->callMiddleware('after'); |
@@ -155,8 +157,9 @@ discard block |
||
155 | 157 | */ |
156 | 158 | public function setUrl($url = null) |
157 | 159 | { |
158 | - if (is_null($url)) |
|
159 | - $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
160 | + if (is_null($url)) { |
|
161 | + $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
162 | + } |
|
160 | 163 | $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
161 | 164 | } |
162 | 165 | |
@@ -166,7 +169,9 @@ discard block |
||
166 | 169 | public function match() |
167 | 170 | { |
168 | 171 | foreach ($this->matcher as $key => $matcher) { |
169 | - if (call_user_func([$this->matcher[$key], 'match'])) return true; |
|
172 | + if (call_user_func([$this->matcher[$key], 'match'])) { |
|
173 | + return true; |
|
174 | + } |
|
170 | 175 | } |
171 | 176 | return false; |
172 | 177 | } |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | * @param $handlers |
155 | 155 | * @param array $params |
156 | 156 | */ |
157 | - private function callHandlers($handlers, $params = []){ |
|
157 | + private function callHandlers($handlers, $params = []) { |
|
158 | 158 | $handlers = is_array($handlers) ? $handlers : [$handlers]; |
159 | 159 | foreach ($handlers as $handler) { |
160 | - if($this->next && $this->handle($handler, $params) !== true){ |
|
160 | + if ($this->next && $this->handle($handler, $params) !== true) { |
|
161 | 161 | break; |
162 | 162 | } |
163 | 163 | } |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | } |
186 | 186 | $dependencies = array_merge($dependencies, [$this->router->route]); |
187 | 187 | $response = $reflectionMethod->invokeArgs($instance, $dependencies); |
188 | - if(is_array($response) && isset($response['call'])){ |
|
189 | - if(isset($response['response']) && $response['response'] instanceof ResponseInterface){ |
|
188 | + if (is_array($response) && isset($response['call'])) { |
|
189 | + if (isset($response['response']) && $response['response'] instanceof ResponseInterface) { |
|
190 | 190 | $this->router->response = $response['response']; |
191 | 191 | } |
192 | - $params = isset($response['params']) ? $response['params']: []; |
|
192 | + $params = isset($response['params']) ? $response['params'] : []; |
|
193 | 193 | $this->callHandlers($response['call'], $params); |
194 | - $this->next = isset($response['next']) ? (bool)$response['next'] : false; |
|
194 | + $this->next = isset($response['next']) ? (bool) $response['next'] : false; |
|
195 | 195 | } else if ($response instanceof ResponseInterface) { |
196 | 196 | $this->router->response = $response; |
197 | 197 | } |
@@ -108,9 +108,9 @@ 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)); |
|
113 | - $this->router->route->addTarget('params', $this->router->collection->getRoutes('params_' . $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 | + $this->router->route->addTarget('params', $this->router->collection->getRoutes('params_'.$index)); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | { |
137 | 137 | foreach ($this->router->getConfig()['templateExtension'] as $extension) { |
138 | 138 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
139 | - $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '', $this->router->route->getUrl())); |
|
139 | + $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_'.$i), '', $this->router->route->getUrl())); |
|
140 | 140 | $end = array_pop($url); |
141 | - $url = implode('/', array_map('ucwords', $url)) . '/' . $end; |
|
142 | - if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) { |
|
141 | + $url = implode('/', array_map('ucwords', $url)).'/'.$end; |
|
142 | + if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_'.$i), '/').$url.$extension))) { |
|
143 | 143 | $this->request['collection_index'] = $i; |
144 | 144 | return [ |
145 | 145 | 'dispatcher' => $this->dispatcher['isTemplate'], |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | $routes = array_slice(explode('/', $this->router->route->getUrl()), 1); |
162 | 162 | $i = 0; |
163 | 163 | do { |
164 | - $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
164 | + $route = ('/'.$routes[0] == $this->router->collection->getRoutes('prefix_'.$i)) ? array_slice($routes, 1) : $routes; |
|
165 | 165 | if (isset($route[0])) { |
166 | - $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller')) |
|
167 | - ? $this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller' |
|
168 | - : ucfirst($route[0]) . 'Controller'; |
|
166 | + $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller')) |
|
167 | + ? $this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller' |
|
168 | + : ucfirst($route[0]).'Controller'; |
|
169 | 169 | $route[1] = isset($route[1]) ? $route[1] : 'index'; |
170 | 170 | if (method_exists($class, $route[1])) { |
171 | 171 | $this->request['parameters'] = array_slice($route, 2); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | } |
181 | 181 | ++$i; |
182 | - } while ($i < $this->router->collection->countRoutes); |
|
182 | + }while ($i < $this->router->collection->countRoutes); |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 |