HttpCache.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Symfony\Bundle\FrameworkBundle\HttpCache;
  3. use Symfony\Component\HttpKernel\HttpKernelInterface;
  4. use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache;
  5. use Symfony\Component\HttpKernel\HttpCache\Esi;
  6. use Symfony\Component\HttpKernel\HttpCache\EsiResponseCacheStrategy;
  7. use Symfony\Component\HttpKernel\HttpCache\Store;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. /*
  11. * This file is part of the Symfony package.
  12. *
  13. * (c) Fabien Potencier <fabien@symfony.com>
  14. *
  15. * For the full copyright and license information, please view the LICENSE
  16. * file that was distributed with this source code.
  17. */
  18. /**
  19. *
  20. * @author Fabien Potencier <fabien@symfony.com>
  21. */
  22. abstract class HttpCache extends BaseHttpCache
  23. {
  24. /**
  25. * Constructor.
  26. *
  27. * @param HttpKernelInterface $kernel An HttpKernelInterface instance
  28. */
  29. public function __construct(HttpKernelInterface $kernel)
  30. {
  31. $store = new Store($kernel->getCacheDir().'/http_cache');
  32. $esi = new Esi();
  33. parent::__construct($kernel, $store, $esi, array_merge(array('debug' => $kernel->isDebug()), $this->getOptions()));
  34. }
  35. /**
  36. * Forwards the Request to the backend and returns the Response.
  37. *
  38. * @param Request $request A Request instance
  39. * @param Boolean $raw Whether to catch exceptions or not
  40. * @param Response $response A Response instance (the stale entry if present, null otherwise)
  41. *
  42. * @return Response A Response instance
  43. */
  44. protected function forward(Request $request, $raw = false, Response $entry = null)
  45. {
  46. $this->getKernel()->boot();
  47. $this->getKernel()->getContainer()->set('cache', $this);
  48. $this->getKernel()->getContainer()->set('esi', $this->esi);
  49. return parent::forward($request, $raw, $entry);
  50. }
  51. /**
  52. * Returns an array of options to customize the Cache configuration.
  53. *
  54. * @return array An array of options
  55. */
  56. protected function getOptions()
  57. {
  58. return array();
  59. }
  60. }