@@ -39,8 +39,8 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | 41 | EventManager::instance()->on( |
| 42 | - 'Server.buildMiddleware', |
|
| 43 | - function ($event, $middleware) { |
|
| 44 | - $middleware->add(new SubdomainMiddleware()); |
|
| 45 | - } |
|
| 42 | + 'Server.buildMiddleware', |
|
| 43 | + function ($event, $middleware) { |
|
| 44 | + $middleware->add(new SubdomainMiddleware()); |
|
| 45 | + } |
|
| 46 | 46 | ); |
| 47 | 47 | \ No newline at end of file |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | |
| 41 | 41 | EventManager::instance()->on( |
| 42 | 42 | 'Server.buildMiddleware', |
| 43 | - function ($event, $middleware) { |
|
| 43 | + function($event, $middleware) { |
|
| 44 | 44 | $middleware->add(new SubdomainMiddleware()); |
| 45 | 45 | } |
| 46 | 46 | ); |
| 47 | 47 | \ No newline at end of file |
@@ -19,40 +19,40 @@ |
||
| 19 | 19 | |
| 20 | 20 | class SubdomainMiddleware { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param \Psr\Http\Message\ServerRequestInterface $request The request. |
|
| 24 | - * @param \Psr\Http\Message\ResponseInterface $response The response. |
|
| 25 | - * @param callable $next The next middleware to call. |
|
| 26 | - * @return \Psr\Http\Message\ResponseInterface A response. |
|
| 27 | - */ |
|
| 28 | - public function __invoke($request, $response, $next) { |
|
| 22 | + /** |
|
| 23 | + * @param \Psr\Http\Message\ServerRequestInterface $request The request. |
|
| 24 | + * @param \Psr\Http\Message\ResponseInterface $response The response. |
|
| 25 | + * @param callable $next The next middleware to call. |
|
| 26 | + * @return \Psr\Http\Message\ResponseInterface A response. |
|
| 27 | + */ |
|
| 28 | + public function __invoke($request, $response, $next) { |
|
| 29 | 29 | |
| 30 | - $subdomains = $this->_getSubdomains(); |
|
| 30 | + $subdomains = $this->_getSubdomains(); |
|
| 31 | 31 | |
| 32 | - $uri = $request->getUri(); |
|
| 33 | - $host = $uri->getHost(); |
|
| 32 | + $uri = $request->getUri(); |
|
| 33 | + $host = $uri->getHost(); |
|
| 34 | 34 | |
| 35 | - if (preg_match('/(.*?)\.([^\/]*\..{2,5})/i', $host, $parts)) { |
|
| 35 | + if (preg_match('/(.*?)\.([^\/]*\..{2,5})/i', $host, $parts)) { |
|
| 36 | 36 | |
| 37 | - if (in_array($parts[1], $subdomains)) { |
|
| 37 | + if (in_array($parts[1], $subdomains)) { |
|
| 38 | 38 | |
| 39 | - $params = (array) $request->getAttribute('params', []); |
|
| 39 | + $params = (array) $request->getAttribute('params', []); |
|
| 40 | 40 | |
| 41 | - if (empty($params['prefix'])) { |
|
| 42 | - $params['prefix'] = $parts[1]; |
|
| 43 | - } |
|
| 41 | + if (empty($params['prefix'])) { |
|
| 42 | + $params['prefix'] = $parts[1]; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $request = $request->withAttribute('params', $params); |
|
| 45 | + $request = $request->withAttribute('params', $params); |
|
| 46 | 46 | |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return $next($request, $response); |
|
| 51 | + return $next($request, $response); |
|
| 52 | 52 | |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - private function _getSubdomains() { |
|
| 55 | + private function _getSubdomains() { |
|
| 56 | 56 | |
| 57 | 57 | $validConfiguration = Configure::check('Multidimensional/Subdomains.subdomains'); |
| 58 | 58 | |