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

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 Commercial License (PCL)
  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 PCL
  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\RequestEvent;
  20. use Symfony\Component\HttpKernel\KernelEvents;
  21. /**
  22.  * @internal
  23.  */
  24. class OutputTimestampListener implements EventSubscriberInterface
  25. {
  26.     const TIMESTAMP_OVERRIDE_PARAM_NAME 'pimcore_override_output_timestamp';
  27.     public function __construct(protected OutputTimestampResolver $outputTimestampResolver)
  28.     {
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             KernelEvents::REQUEST => 'onKernelRequest',
  37.         ];
  38.     }
  39.     public function onKernelRequest(RequestEvent $event)
  40.     {
  41.         if (!$event->isMainRequest()) {
  42.             return;
  43.         }
  44.         if ($overrideTimestamp = (int)$event->getRequest()->query->get(self::TIMESTAMP_OVERRIDE_PARAM_NAME)) {
  45.             if (\Pimcore::inDebugMode() || Authentication::authenticateSession($event->getRequest())) {
  46.                 $this->outputTimestampResolver->setOutputTimestamp($overrideTimestamp);
  47.             }
  48.         }
  49.     }
  50. }