vendor/contao/core-bundle/src/EventListener/BackendRebuildCacheMessageListener.php line 50

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\EventListener;
  11. use Contao\CoreBundle\Routing\ScopeMatcher;
  12. use Psr\Cache\CacheItemPoolInterface;
  13. use Symfony\Component\HttpFoundation\Session\Session;
  14. use Symfony\Component\HttpKernel\Event\RequestEvent;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. /**
  17.  * @internal
  18.  */
  19. class BackendRebuildCacheMessageListener
  20. {
  21.     public const CACHE_DIRTY_FLAG 'contao.template_path_cache_dirty';
  22.     /**
  23.      * @var ScopeMatcher
  24.      */
  25.     private $scopeMatcher;
  26.     /**
  27.      * @var CacheItemPoolInterface
  28.      */
  29.     private $cache;
  30.     /**
  31.      * @var TranslatorInterface
  32.      */
  33.     private $translator;
  34.     public function __construct(ScopeMatcher $scopeMatcherCacheItemPoolInterface $cacheTranslatorInterface $translator)
  35.     {
  36.         $this->scopeMatcher $scopeMatcher;
  37.         $this->cache $cache;
  38.         $this->translator $translator;
  39.     }
  40.     public function __invoke(RequestEvent $event): void
  41.     {
  42.         $request $event->getRequest();
  43.         if (!$this->scopeMatcher->isBackendRequest($request)) {
  44.             return;
  45.         }
  46.         if (!$this->cache->hasItem(self::CACHE_DIRTY_FLAG)) {
  47.             return;
  48.         }
  49.         /** @var Session $session */
  50.         $session $request->getSession();
  51.         $session->getFlashBag()->add(
  52.             'contao.BE.info',
  53.             $this->translator->trans('ERR.applicationCache', [], 'contao_default')
  54.         );
  55.     }
  56. }