You are here

public function Ssi::handle in Zircon Profile 8

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

Handles a Surrogate from the cache.

Parameters

HttpCache $cache An HttpCache instance:

string $uri The main URI:

string $alt An alternative URI:

bool $ignoreErrors Whether to ignore errors or not:

Return value

string

Throws

\RuntimeException

\Exception

Overrides SurrogateInterface::handle

File

vendor/symfony/http-kernel/HttpCache/Ssi.php, line 172

Class

Ssi
Ssi implements the SSI capabilities to Request and Response instances.

Namespace

Symfony\Component\HttpKernel\HttpCache

Code

public function handle(HttpCache $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 (!$response
      ->isSuccessful()) {
      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;
    }
  }
}