|
@@ -95,15 +95,15 @@ discard block |
|
|
block discarded – undo |
|
95
|
95
|
{ |
|
96
|
96
|
$this->request = []; |
|
97
|
97
|
for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
|
98
|
|
- $this->request['prefix'] = ($this->router->collection->getRoutes('prefix_' . $i) != '') ? $this->router->collection->getRoutes('prefix_' . $i) : ''; |
|
99
|
|
- $this->request['subdomain'] = ($this->router->collection->getRoutes('subdomain_' . $i) != '') ? $this->router->collection->getRoutes('subdomain_' . $i) : ''; |
|
100
|
|
- foreach ($this->router->collection->getRoutes('routes_' . $i) as $route => $params) { |
|
|
98
|
+ $this->request['prefix'] = ($this->router->collection->getRoutes('prefix_'.$i) != '') ? $this->router->collection->getRoutes('prefix_'.$i) : ''; |
|
|
99
|
+ $this->request['subdomain'] = ($this->router->collection->getRoutes('subdomain_'.$i) != '') ? $this->router->collection->getRoutes('subdomain_'.$i) : ''; |
|
|
100
|
+ foreach ($this->router->collection->getRoutes('routes_'.$i) as $route => $params) { |
|
101
|
101
|
$this->request['params'] = $params; |
|
102
|
102
|
$this->request['collection_index'] = $i; |
|
103
|
103
|
if ($this->checkSubdomain($route)) { |
|
104
|
104
|
$route = strstr($route, '/'); |
|
105
|
|
- $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/' . trim(trim($this->request['prefix'], '/') . '/' . trim($route, '/'), '/')); |
|
106
|
|
- if ($this->routeMatch('#^' . $this->request['route'] . '$#')) { |
|
|
105
|
+ $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/'.trim(trim($this->request['prefix'], '/').'/'.trim($route, '/'), '/')); |
|
|
106
|
+ if ($this->routeMatch('#^'.$this->request['route'].'$#')) { |
|
107
|
107
|
$this->setCallback(); |
|
108
|
108
|
if (!is_null($response = $this->generateTarget())) return $response; |
|
109
|
109
|
} |
|
@@ -119,19 +119,19 @@ discard block |
|
|
block discarded – undo |
|
119
|
119
|
*/ |
|
120
|
120
|
private function checkSubdomain($route) |
|
121
|
121
|
{ |
|
122
|
|
- $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http') . '://' . ($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'])); |
|
|
122
|
+ $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http').'://'.($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'])); |
|
123
|
123
|
$host = explode(':', $host)[0]; |
|
124
|
124
|
$domain = $this->router->collection->getDomain($url); |
|
125
|
|
- if (!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'], '.') . '.' . $domain . $route; |
|
|
125
|
+ if (!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'], '.').'.'.$domain.$route; |
|
126
|
126
|
if ($route[0] == '/') { |
|
127
|
127
|
return ($host != $domain) ? false : true; |
|
128
|
128
|
} elseif ($route[0] != '/' && $host != $domain) { |
|
129
|
129
|
$route = substr($route, 0, strpos($route, "/")); |
|
130
|
130
|
$route = str_replace('{host}', $domain, $route); |
|
131
|
131
|
$route = preg_replace_callback('#{subdomain}#', [$this, 'subdomainMatch'], $route); |
|
132
|
|
- if (preg_match('#^' . $route . '$#', $host, $this->request['called_subdomain'])) { |
|
|
132
|
+ if (preg_match('#^'.$route.'$#', $host, $this->request['called_subdomain'])) { |
|
133
|
133
|
$this->request['called_subdomain'] = array_shift($this->request['called_subdomain']); |
|
134
|
|
- $this->request['subdomain'] = str_replace('.' . $domain, '', $host); |
|
|
134
|
+ $this->request['subdomain'] = str_replace('.'.$domain, '', $host); |
|
135
|
135
|
return true; |
|
136
|
136
|
} |
|
137
|
137
|
} |
|
@@ -144,7 +144,7 @@ discard block |
|
|
block discarded – undo |
|
144
|
144
|
private function subdomainMatch() |
|
145
|
145
|
{ |
|
146
|
146
|
if (is_array($this->request['params']) && isset($this->request['params']['subdomain'])) { |
|
147
|
|
- return '(' . $this->request['params']['subdomain'] . ')'; |
|
|
147
|
+ return '('.$this->request['params']['subdomain'].')'; |
|
148
|
148
|
} |
|
149
|
149
|
return '([^/]+)'; |
|
150
|
150
|
} |
|
@@ -157,7 +157,7 @@ discard block |
|
|
block discarded – undo |
|
157
|
157
|
{ |
|
158
|
158
|
if (is_array($this->request['params']) && isset($this->request['params']['arguments'][$match[1]])) { |
|
159
|
159
|
$this->request['params']['arguments'][$match[1]] = str_replace('(', '(?:', $this->request['params']['arguments'][$match[1]]); |
|
160
|
|
- return '(' . $this->request['params']['arguments'][$match[1]] . ')'; |
|
|
160
|
+ return '('.$this->request['params']['arguments'][$match[1]].')'; |
|
161
|
161
|
} |
|
162
|
162
|
return '([^/]+)'; |
|
163
|
163
|
} |
|
@@ -211,8 +211,8 @@ discard block |
|
|
block discarded – undo |
|
211
|
211
|
$this->checkRequest('prefix'); |
|
212
|
212
|
$this->router->route->setDetail($this->request); |
|
213
|
213
|
$this->router->route->setTarget($target); |
|
214
|
|
- $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_' . $index)); |
|
215
|
|
- $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_' . $index)); |
|
|
214
|
+ $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_'.$index)); |
|
|
215
|
+ $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_'.$index)); |
|
216
|
216
|
} |
|
217
|
217
|
|
|
218
|
218
|
/** |
|
@@ -221,7 +221,7 @@ discard block |
|
|
block discarded – undo |
|
221
|
221
|
private function checkRequest($key) |
|
222
|
222
|
{ |
|
223
|
223
|
if (strpos($this->request[$key], ':') !== false && isset($this->request['parameters'][0])) { |
|
224
|
|
- $this->request['@' . $key] = $this->request[$key]; |
|
|
224
|
+ $this->request['@'.$key] = $this->request[$key]; |
|
225
|
225
|
$this->request[$key] = $this->request['parameters'][0]; |
|
226
|
226
|
unset($this->request['parameters'][0]); |
|
227
|
227
|
} |
|
@@ -329,9 +329,9 @@ discard block |
|
|
block discarded – undo |
|
329
|
329
|
$index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
|
330
|
330
|
$class = (class_exists($routes[0])) |
|
331
|
331
|
? $routes[0] |
|
332
|
|
- : $this->router->collection->getRoutes()['ctrl_namespace_' . $index] . $routes[0]; |
|
|
332
|
+ : $this->router->collection->getRoutes()['ctrl_namespace_'.$index].$routes[0]; |
|
333
|
333
|
if (!class_exists($class)) |
|
334
|
|
- throw new \Exception('Class "' . $class . '." is not found'); |
|
|
334
|
+ throw new \Exception('Class "'.$class.'." is not found'); |
|
335
|
335
|
if (method_exists($class, $routes[1])) { |
|
336
|
336
|
return [ |
|
337
|
337
|
'dispatcher' => $this->dispatcher['isController'], |
|
@@ -341,7 +341,7 @@ discard block |
|
|
block discarded – undo |
|
341
|
341
|
]; |
|
342
|
342
|
} |
|
343
|
343
|
if (!strpos($callback, '{method}') !== false) |
|
344
|
|
- throw new \Exception('The required method "' . $routes[1] . '" is not found in "' . $class . '"'); |
|
|
344
|
+ throw new \Exception('The required method "'.$routes[1].'" is not found in "'.$class.'"'); |
|
345
|
345
|
} |
|
346
|
346
|
return false; |
|
347
|
347
|
} |
|
@@ -357,13 +357,13 @@ discard block |
|
|
block discarded – undo |
|
357
|
357
|
$path = trim($callback, '/'); |
|
358
|
358
|
$extension = substr(strrchr($path, "."), 1); |
|
359
|
359
|
$index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
|
360
|
|
- $viewDir = $this->router->collection->getRoutes('view_dir_' . $index); |
|
|
360
|
+ $viewDir = $this->router->collection->getRoutes('view_dir_'.$index); |
|
361
|
361
|
$target = null; |
|
362
|
|
- if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path))) |
|
|
362
|
+ if (in_array('.'.$extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir.$path) || is_file($fullPath = $path))) |
|
363
|
363
|
$target = $fullPath; |
|
364
|
364
|
else { |
|
365
|
365
|
foreach ($this->router->getConfig()['templateExtension'] as $ext) { |
|
366
|
|
- if (is_file($fullPath = $viewDir . $path . $ext) || is_file($fullPath = $path . $ext)) { |
|
|
366
|
+ if (is_file($fullPath = $viewDir.$path.$ext) || is_file($fullPath = $path.$ext)) { |
|
367
|
367
|
$target = $fullPath; |
|
368
|
368
|
$extension = substr(strrchr($ext, "."), 1); |
|
369
|
369
|
break; |
|
@@ -371,7 +371,7 @@ discard block |
|
|
block discarded – undo |
|
371
|
371
|
} |
|
372
|
372
|
} |
|
373
|
373
|
if (is_null($target)) |
|
374
|
|
- throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"'); |
|
|
374
|
+ throw new \Exception('Template file "'.$path.'" is not found in "'.$viewDir.'"'); |
|
375
|
375
|
return [ |
|
376
|
376
|
'dispatcher' => $this->dispatcher['isTemplate'], |
|
377
|
377
|
'template' => $target, |