vendor/pimcore/pimcore/bundles/CoreBundle/EventListener/Frontend/OutputTimestampListener.php line 50

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Enterprise License (PEL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  14.  */
  15. namespace Pimcore\Bundle\CoreBundle\EventListener\Frontend;
  16. use Pimcore\Http\Request\Resolver\OutputTimestampResolver;
  17. use Pimcore\Tool\Authentication;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  20. use Symfony\Component\HttpKernel\KernelEvents;
  21. class OutputTimestampListener implements EventSubscriberInterface
  22. {
  23.     const TIMESTAMP_OVERRIDE_PARAM_NAME 'pimcore_override_output_timestamp';
  24.     /**
  25.      * @var OutputTimestampResolver
  26.      */
  27.     protected $outputTimestampResolver;
  28.     public function __construct(OutputTimestampResolver $outputTimestampResolver)
  29.     {
  30.         $this->outputTimestampResolver $outputTimestampResolver;
  31.     }
  32.     /**
  33.      * @inheritDoc
  34.      */
  35.     public static function getSubscribedEvents()
  36.     {
  37.         return [
  38.             KernelEvents::REQUEST => 'onKernelRequest'
  39.         ];
  40.     }
  41.     public function onKernelRequest(GetResponseEvent $event)
  42.     {
  43.         if (!$event->isMasterRequest()) {
  44.             return;
  45.         }
  46.         if ($overrideTimestamp = (int)$event->getRequest()->query->get(self::TIMESTAMP_OVERRIDE_PARAM_NAME)) {
  47.             if (\Pimcore::inDebugMode() || Authentication::authenticateSession($event->getRequest())) {
  48.                 $this->outputTimestampResolver->setOutputTimestamp($overrideTimestamp);
  49.             }
  50.         }
  51.     }
  52. }