getGenerator() публичный статический Метод

Returns a callable to build a full path.
public static getGenerator ( Psr\Http\Message\ServerRequestInterface $request ) : callable | null
$request Psr\Http\Message\ServerRequestInterface
Результат callable | null
Пример #1
0
 /**
  * Returns a redirect response.
  *
  * @param ServerRequestInterface $request
  * @param UriInterface           $uri
  * @param ResponseInterface      $response
  *
  * @return ResponseInterface
  */
 private function getRedirectResponse(ServerRequestInterface $request, UriInterface $uri, ResponseInterface $response)
 {
     //Fix the basePath
     $generator = BasePath::getGenerator($request);
     if ($generator !== null) {
         $uri = $uri->withPath($generator($uri->getPath()));
     }
     return $response->withStatus($this->redirectStatus)->withHeader('Location', (string) $uri);
 }
Пример #2
0
 /**
  * Execute the middleware.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $renderer = $this->debugBar->getJavascriptRenderer();
     //Is an asset?
     $path = $request->getUri()->getPath();
     $renderPath = $renderer->getBaseUrl();
     if (strpos($path, $renderPath) === 0) {
         $file = $renderer->getBasePath() . substr($path, strlen($renderPath));
         if (file_exists($file)) {
             return $response->withBody(self::createStream($file, 'r'));
         }
     }
     $response = $next($request, $response);
     //Fix the render baseUrl
     $generator = BasePath::getGenerator($request);
     if ($generator) {
         $renderer->setBaseUrl($generator($renderer->getBaseUrl()));
     }
     $ajax = Utils\Helpers::isAjax($request);
     //Redirection response
     if (Utils\Helpers::isRedirect($response)) {
         if ($this->debugBar->isDataPersisted() || session_status() === PHP_SESSION_ACTIVE) {
             $this->debugBar->stackData();
         }
         //Html response
     } elseif (Utils\Helpers::getMimeType($response) === 'text/html') {
         if (!$ajax) {
             $response = $this->inject($response, $renderer->renderHead(), 'head');
         }
         $response = $this->inject($response, $renderer->render(!$ajax), 'body');
         //Ajax response
     } elseif ($ajax && $this->captureAjax) {
         $headers = $this->debugBar->getDataAsHeaders();
         foreach ($headers as $name => $value) {
             $response = $response->withHeader($name, $value);
         }
     }
     return $response;
 }