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

82 lines
2.4 KiB
PHP
Raw Normal View History

2010-06-23 20:42:41 +01:00
<?php
/*
* 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.
*/
namespace Symfony\Bundle\FrameworkBundle\HttpCache;
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
/**
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
{
protected $cacheDir;
protected $kernel;
2010-06-23 20:42:41 +01:00
/**
* Constructor.
*
* @param HttpKernelInterface $kernel An HttpKernelInterface instance
2012-07-06 17:52:14 +01:00
* @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
{
$this->kernel = $kernel;
$this->cacheDir = $cacheDir;
2010-06-23 20:42:41 +01:00
2014-03-23 00:04:57 +00:00
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), 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 bool $raw Whether to catch exceptions or not
2011-04-23 16:05:44 +01:00
* @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); // to be removed in 4.0?
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();
}
2014-03-23 00:04:57 +00:00
protected function createSurrogate()
{
return new Esi();
}
2012-04-13 08:04:04 +01:00
protected function createStore()
{
return new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
}
2010-06-23 20:42:41 +01:00
}