Source of file CacheListener.php
Size: 2,107 Bytes - Last Modified: 2013-07-09T11:29:53+02:00
/home/theseer/Downloads/Symfony/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/EventListener/CacheListener.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?php namespace Sensio\Bundle\FrameworkExtraBundle\EventListener; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /* * This file is part of the Symfony framework. * * (c) Fabien Potencier <fabien@symfony.com> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * The CacheListener class has the responsibility to modify the * Response object when a controller uses the "@Cache" annotation. * * @author Fabien Potencier <fabien@symfony.com> */ class CacheListener implements EventSubscriberInterface { /** * Modifies the response to apply HTTP expiration header fields. * * @param FilterResponseEvent $event The notified event */ public function onKernelResponse(FilterResponseEvent $event) { if (!$configuration = $event->getRequest()->attributes->get('_cache')) { return; } $response = $event->getResponse(); if (!$response->isSuccessful()) { return; } if (null !== $configuration->getSMaxAge()) { $response->setSharedMaxAge($configuration->getSMaxAge()); } if (null !== $configuration->getMaxAge()) { $response->setMaxAge($configuration->getMaxAge()); } if (null !== $configuration->getExpires()) { $date = \DateTime::createFromFormat('U', strtotime($configuration->getExpires()), new \DateTimeZone('UTC')); $response->setExpires($date); } if (null !== $configuration->getVary()) { $response->setVary($configuration->getVary()); } if ($configuration->isPublic()) { $response->setPublic(); } $event->setResponse($response); } public static function getSubscribedEvents() { return array( KernelEvents::RESPONSE => 'onKernelResponse', ); } } |