app/Plugin/TabaFileManager2/EventListener/CacheListener.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (C) SPREAD WORKS Inc. All Rights Reserved.
  4.  *
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Plugin\TabaFileManager2\EventListener;
  9. use Plugin\TabaFileManager2\Common\Constants;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  12. class CacheListener
  13. {
  14.     /**
  15.      * @var ContainerInterface
  16.      */
  17.     private $container;
  18.     /**
  19.      * コンストラクタ
  20.      *
  21.      * @param ContainerInterface $container
  22.      */
  23.     public function __construct(ContainerInterface $container)
  24.     {
  25.         $this->container $container;
  26.     }
  27.     /**
  28.      *
  29.      * @param ResponseEvent $event
  30.      * @param string $eventName
  31.      */
  32.     public function onKernelResponse(ResponseEvent $event,$eventName) {
  33.         if ($this->container->has(Constants::CONTAINER_KEY_NAME)) {
  34.             if (!$this->container->get(Constants::CONTAINER_KEY_NAME)->get(Constants::HTTP_CACHE_STATUS)) {
  35.                 return;
  36.             }
  37.         } else {
  38.             return;
  39.         }
  40.         $response $event->getResponse();
  41.         $response->setMaxAge(60 60 24);
  42.         $response->setSharedMaxAge(60 60 24);
  43.         //$response->setPublic();
  44.         $response->setLastModified(null);
  45.         $response->setExpires((new \DateTime())->modify('+1 day'));
  46.     }
  47. }