This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php

75 lines
2.2 KiB
PHP
Raw Normal View History

2010-06-23 20:42:41 +01:00
<?php
namespace Symfony\Bundle\FrameworkBundle\HttpCache;
2010-06-23 20:42:41 +01:00
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache;
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpKernel\HttpCache\Store;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
2010-06-23 20:42:41 +01:00
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
2010-06-23 20:42:41 +01:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
2011-12-13 07:50:54 +00:00
* Manages HTTP cache objects in a Container.
2010-06-23 20:42:41 +01:00
*
* @author Fabien Potencier <fabien@symfony.com>
2010-06-23 20:42:41 +01:00
*/
abstract class HttpCache extends BaseHttpCache
2010-06-23 20:42:41 +01:00
{
/**
* Constructor.
*
* @param HttpKernelInterface $kernel An HttpKernelInterface instance
* @param String $cacheDir The cache directory (default used if null)
2010-06-23 20:42:41 +01:00
*/
public function __construct(HttpKernelInterface $kernel, $cacheDir = null)
2010-06-23 20:42:41 +01:00
{
if ($cacheDir) {
$store = new Store($cacheDir);
} else {
$store = new Store($kernel->getCacheDir().'/http_cache');
}
2010-06-23 20:42:41 +01:00
$esi = new Esi();
parent::__construct($kernel, $store, $esi, array_merge(array('debug' => $kernel->isDebug()), $this->getOptions()));
2010-06-23 20:42:41 +01:00
}
/**
* Forwards the Request to the backend and returns the Response.
*
2011-04-23 16:05:44 +01:00
* @param Request $request A Request instance
* @param Boolean $raw Whether to catch exceptions or not
* @param Response $entry A Response instance (the stale entry if present, null otherwise)
2010-06-23 20:42:41 +01:00
*
* @return Response A Response instance
2010-06-23 20:42:41 +01:00
*/
protected function forward(Request $request, $raw = false, Response $entry = null)
{
$this->getKernel()->boot();
$this->getKernel()->getContainer()->set('cache', $this);
$this->getKernel()->getContainer()->set('esi', $this->getEsi());
2010-06-23 20:42:41 +01:00
return parent::forward($request, $raw, $entry);
}
/**
* Returns an array of options to customize the Cache configuration.
*
* @return array An array of options
*/
protected function getOptions()
{
return array();
}
}