handle() public method

public handle ( Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true )
$request Symfony\Component\HttpFoundation\Request
Beispiel #1
0
 /**
  * Handles an ESI from the cache.
  *
  * @param Cache   $cache        A Cache instance
  * @param string  $uri          The main URI
  * @param string  $alt          An alternative URI
  * @param Boolean $ignoreErrors Whether to ignore errors or not
  */
 public function handle(Cache $cache, $uri, $alt, $ignoreErrors)
 {
     $subRequest = Request::create($uri, 'get', array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());
     try {
         $response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
         if (200 != $response->getStatusCode()) {
             throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $subRequest->getUri(), $response->getStatusCode()));
         }
         return $response->getContent();
     } catch (\Exception $e) {
         if ($alt) {
             return $this->handle($cache, $alt, '', $ignoreErrors);
         }
         if (!$ignoreErrors) {
             throw $e;
         }
     }
 }