vendor/pimcore/pimcore/bundles/CoreBundle/EventListener/Frontend/DocumentStackListener.php line 53

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace Pimcore\Bundle\CoreBundle\EventListener\Frontend;
  15. use Pimcore\Document\DocumentStack;
  16. use Pimcore\Model\Document;
  17. use Psr\Log\LoggerAwareInterface;
  18. use Psr\Log\LoggerAwareTrait;
  19. use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter;
  20. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  21. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  22. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  23. use Symfony\Component\HttpKernel\KernelEvents;
  24. class DocumentStackListener implements EventSubscriberInterfaceLoggerAwareInterface
  25. {
  26.     use LoggerAwareTrait;
  27.     protected $documents;
  28.     protected $documentStack;
  29.     public function __construct(DocumentStack $documentStack)
  30.     {
  31.         $this->documentStack $documentStack;
  32.     }
  33.     /**
  34.      * @inheritDoc
  35.      */
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             KernelEvents::REQUEST => 'onKernelRequest',
  40.             KernelEvents::RESPONSE => 'onKernelResponse'
  41.         ];
  42.     }
  43.     /**
  44.      * @param GetResponseEvent $event
  45.      */
  46.     public function onKernelRequest(GetResponseEvent $event)
  47.     {
  48.         $request $event->getRequest();
  49.         if ($currentDoc $request->get(DynamicRouter::CONTENT_KEY)) {
  50.             if ($currentDoc instanceof Document) {
  51.                 $this->documentStack->push($currentDoc);
  52.             }
  53.         }
  54.     }
  55.     /**
  56.      * @param FilterResponseEvent $event
  57.      */
  58.     public function onKernelResponse(FilterResponseEvent $event)
  59.     {
  60.         $request $event->getRequest();
  61.         if ($currentDoc $request->get(DynamicRouter::CONTENT_KEY)) {
  62.             if ($currentDoc instanceof Document) {
  63.                 $this->documentStack->pop();
  64.             }
  65.         }
  66.     }
  67. }