You are here

public function HttpCache::handle in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-kernel/HttpCache/HttpCache.php \Symfony\Component\HttpKernel\HttpCache\HttpCache::handle()

Handles a Request to convert it to a Response.

When $catch is true, the implementation must catch all exceptions and do its best to convert them to a Response instance.

Parameters

Request $request A Request instance:

int $type The type of the request: (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)

bool $catch Whether to catch exceptions or not:

Return value

Response A Response instance

Throws

\Exception When an Exception occurs during processing

Overrides HttpKernelInterface::handle

File

vendor/symfony/http-kernel/HttpCache/HttpCache.php, line 188

Class

HttpCache
Cache provides HTTP caching.

Namespace

Symfony\Component\HttpKernel\HttpCache

Code

public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) {

  // FIXME: catch exceptions and implement a 500 error page here? -> in Varnish, there is a built-in error page mechanism
  if (HttpKernelInterface::MASTER_REQUEST === $type) {
    $this->traces = array();
    $this->request = $request;
    if (null !== $this->surrogate) {
      $this->surrogateCacheStrategy = $this->surrogate
        ->createCacheStrategy();
    }
  }
  $path = $request
    ->getPathInfo();
  if ($qs = $request
    ->getQueryString()) {
    $path .= '?' . $qs;
  }
  $this->traces[$request
    ->getMethod() . ' ' . $path] = array();
  if (!$request
    ->isMethodSafe()) {
    $response = $this
      ->invalidate($request, $catch);
  }
  elseif ($request->headers
    ->has('expect')) {
    $response = $this
      ->pass($request, $catch);
  }
  else {
    $response = $this
      ->lookup($request, $catch);
  }
  $this
    ->restoreResponseBody($request, $response);
  $response
    ->setDate(\DateTime::createFromFormat('U', time(), new \DateTimeZone('UTC')));
  if (HttpKernelInterface::MASTER_REQUEST === $type && $this->options['debug']) {
    $response->headers
      ->set('X-Symfony-Cache', $this
      ->getLog());
  }
  if (null !== $this->surrogate) {
    if (HttpKernelInterface::MASTER_REQUEST === $type) {
      $this->surrogateCacheStrategy
        ->update($response);
    }
    else {
      $this->surrogateCacheStrategy
        ->add($response);
    }
  }
  $response
    ->prepare($request);
  $response
    ->isNotModified($request);
  return $response;
}