コード例 #1
0
 private function resolvePage(ServerRequestInterface $request, ResponseInterface $response)
 {
     $requestUri = $request->getUri();
     $requestPath = array_filter(explode('/', $requestUri->getPath()), function ($value) {
         return strlen(trim($value)) > 0;
     });
     // If somehow the user has come to an index page via its not-pretty-uri 301 redirect them
     if (end($requestPath) === 'index') {
         array_pop($requestPath);
         $requestPathString = (string) $requestUri->withPath(implode('/', $requestPath));
         // Check first that we are not redirecting to a 404, if the request path is zero length then its safe to assume it exists as a / path
         if (count($requestPath) > 0 && !$this->pageExists($requestPath)) {
             return;
         }
         return $response->withStatus(301)->withHeader('Location', $requestPathString);
     }
     if ($viewPath = $this->resolvePageViewPath($requestPath)) {
         return $this->platesRenderer->render($response, $viewPath);
     }
 }