vendor/pimcore/workflow-designer/src/EventSubscriber/ContainerClearSubscriber.php line 53

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\WorkflowDesignerBundle\EventSubscriber;
  12. use Pimcore\Cache\Symfony\CacheClearer;
  13. use Pimcore\Tool;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\HttpKernel\KernelEvents;
  16. use Symfony\Contracts\EventDispatcher\Event;
  17. class ContainerClearSubscriber implements EventSubscriberInterface
  18. {
  19.     /**
  20.      * @var CacheClearer
  21.      */
  22.     protected CacheClearer $cacheClearer;
  23.     protected bool $resetCache false;
  24.     /**
  25.      * @param CacheClearer $cacheClearer
  26.      */
  27.     public function __construct(CacheClearer $cacheClearer)
  28.     {
  29.         $this->cacheClearer $cacheClearer;
  30.     }
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             KernelEvents::TERMINATE => [['onTerminate', -5000]]
  35.         ];
  36.     }
  37.     /**
  38.      * @param bool $resetCache
  39.      */
  40.     public function setResetCache(bool $resetCache): void
  41.     {
  42.         $this->resetCache $resetCache;
  43.     }
  44.     public function onTerminate(Event $terminateEvent)
  45.     {
  46.         if ($this->resetCache) {
  47.             foreach (Tool::getCachedSymfonyEnvironments() as $environment) {
  48.                 $this->cacheClearer->clear($environment, [
  49.                     'no-warmup' => true
  50.                 ]);
  51.             }
  52.         }
  53.     }
  54. }