|
@@ -98,15 +98,15 @@ discard block |
|
|
block discarded – undo |
|
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 |
|
|
block discarded – undo |
|
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 |
|
|
block discarded – undo |
|
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 |
|
|
block discarded – undo |
|
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
|
} |
|
@@ -171,7 +171,7 @@ discard block |
|
|
block discarded – undo |
|
171
|
171
|
*/ |
|
172
|
172
|
private function routeMatch($regex) |
|
173
|
173
|
{ |
|
174
|
|
- $regex = (substr($this->request['route'], -1) == '*') ? '#^' . $this->request['route'] . '#' : $regex; |
|
|
174
|
+ $regex = (substr($this->request['route'], -1) == '*') ? '#^'.$this->request['route'].'#' : $regex; |
|
175
|
175
|
if (preg_match($regex, $this->router->route->getUrl(), $this->request['parameters'])) { |
|
176
|
176
|
array_shift($this->request['parameters']); |
|
177
|
177
|
return true; |
|
@@ -206,9 +206,9 @@ discard block |
|
|
block discarded – undo |
|
206
|
206
|
$this->checkRequest('prefix'); |
|
207
|
207
|
$this->router->route->setDetail($this->request); |
|
208
|
208
|
$this->router->route->setTarget($target); |
|
209
|
|
- $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_' . $index)); |
|
210
|
|
- $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_' . $index)); |
|
211
|
|
- $this->router->route->addTarget('params', $this->router->collection->getRoutes('params_' . $index)); |
|
|
209
|
+ $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_'.$index)); |
|
|
210
|
+ $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_'.$index)); |
|
|
211
|
+ $this->router->route->addTarget('params', $this->router->collection->getRoutes('params_'.$index)); |
|
212
|
212
|
} |
|
213
|
213
|
|
|
214
|
214
|
/** |
|
@@ -219,8 +219,8 @@ discard block |
|
|
block discarded – undo |
|
219
|
219
|
if (strpos($this->request[$key], ':') !== false && isset($this->request['parameters'][0])) { |
|
220
|
220
|
$replacements = $this->request['parameters']; |
|
221
|
221
|
$keys = []; |
|
222
|
|
- $this->request['@' . $key] = $this->request[$key]; |
|
223
|
|
- $this->request[$key] = preg_replace_callback('#:([\w]+)#', function ($matches) use (&$replacements, &$keys) { |
|
|
222
|
+ $this->request['@'.$key] = $this->request[$key]; |
|
|
223
|
+ $this->request[$key] = preg_replace_callback('#:([\w]+)#', function($matches) use (&$replacements, &$keys) { |
|
224
|
224
|
$keys[$matches[0]] = $replacements[0]; |
|
225
|
225
|
return array_shift($replacements); |
|
226
|
226
|
}, $this->request[$key]); |
|
@@ -335,7 +335,7 @@ discard block |
|
|
block discarded – undo |
|
335
|
335
|
$routes = explode('@', $callback); |
|
336
|
336
|
if (!isset($routes[1])) $routes[1] = 'index'; |
|
337
|
337
|
if ($routes[1] == '{method}') { |
|
338
|
|
- $params = explode('/', preg_replace('#' . str_replace('*', '', $this->request['route']) . '#', '', $this->router->route->getUrl())); |
|
|
338
|
+ $params = explode('/', preg_replace('#'.str_replace('*', '', $this->request['route']).'#', '', $this->router->route->getUrl())); |
|
339
|
339
|
$routes[1] = $params[0]; |
|
340
|
340
|
array_shift($params); |
|
341
|
341
|
array_merge($this->request['parameters'], $params); |
|
@@ -345,9 +345,9 @@ discard block |
|
|
block discarded – undo |
|
345
|
345
|
$index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
|
346
|
346
|
$class = (class_exists($routes[0])) |
|
347
|
347
|
? $routes[0] |
|
348
|
|
- : $this->router->collection->getRoutes()['ctrl_namespace_' . $index] . $routes[0]; |
|
|
348
|
+ : $this->router->collection->getRoutes()['ctrl_namespace_'.$index].$routes[0]; |
|
349
|
349
|
if (!class_exists($class)) { |
|
350
|
|
- throw new \Exception('Class "' . $class . '." is not found'); |
|
|
350
|
+ throw new \Exception('Class "'.$class.'." is not found'); |
|
351
|
351
|
} |
|
352
|
352
|
if (method_exists($class, $routes[1])) { |
|
353
|
353
|
return [ |
|
@@ -358,7 +358,7 @@ discard block |
|
|
block discarded – undo |
|
358
|
358
|
]; |
|
359
|
359
|
} |
|
360
|
360
|
if (!strpos($callback, '{method}') !== false) { |
|
361
|
|
- throw new \Exception('The required method "' . $routes[1] . '" is not found in "' . $class . '"'); |
|
|
361
|
+ throw new \Exception('The required method "'.$routes[1].'" is not found in "'.$class.'"'); |
|
362
|
362
|
} |
|
363
|
363
|
} |
|
364
|
364
|
return false; |
|
@@ -375,13 +375,13 @@ discard block |
|
|
block discarded – undo |
|
375
|
375
|
$path = trim($callback, '/'); |
|
376
|
376
|
$extension = substr(strrchr($path, "."), 1); |
|
377
|
377
|
$index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
|
378
|
|
- $viewDir = $this->router->collection->getRoutes('view_dir_' . $index); |
|
|
378
|
+ $viewDir = $this->router->collection->getRoutes('view_dir_'.$index); |
|
379
|
379
|
$target = null; |
|
380
|
|
- if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path))) { |
|
|
380
|
+ if (in_array('.'.$extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir.$path) || is_file($fullPath = $path))) { |
|
381
|
381
|
$target = $fullPath; |
|
382
|
382
|
} else { |
|
383
|
383
|
foreach ($this->router->getConfig()['templateExtension'] as $ext) { |
|
384
|
|
- if (is_file($fullPath = $viewDir . $path . $ext) || is_file($fullPath = $path . $ext)) { |
|
|
384
|
+ if (is_file($fullPath = $viewDir.$path.$ext) || is_file($fullPath = $path.$ext)) { |
|
385
|
385
|
$target = $fullPath; |
|
386
|
386
|
$extension = substr(strrchr($ext, "."), 1); |
|
387
|
387
|
break; |
|
@@ -389,7 +389,7 @@ discard block |
|
|
block discarded – undo |
|
389
|
389
|
} |
|
390
|
390
|
} |
|
391
|
391
|
if (is_null($target)) { |
|
392
|
|
- throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"'); |
|
|
392
|
+ throw new \Exception('Template file "'.$path.'" is not found in "'.$viewDir.'"'); |
|
393
|
393
|
} |
|
394
|
394
|
return [ |
|
395
|
395
|
'dispatcher' => $this->dispatcher['isTemplate'], |