<?php
/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/
namespace Pimcore\Bundle\WorkflowDesignerBundle\EventSubscriber;
use Pimcore\Cache\Symfony\CacheClearer;
use Pimcore\Tool;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Contracts\EventDispatcher\Event;
class ContainerClearSubscriber implements EventSubscriberInterface
{
/**
* @var CacheClearer
*/
protected CacheClearer $cacheClearer;
protected bool $resetCache = false;
/**
* @param CacheClearer $cacheClearer
*/
public function __construct(CacheClearer $cacheClearer)
{
$this->cacheClearer = $cacheClearer;
}
public static function getSubscribedEvents()
{
return [
KernelEvents::TERMINATE => [['onTerminate', -5000]]
];
}
/**
* @param bool $resetCache
*/
public function setResetCache(bool $resetCache): void
{
$this->resetCache = $resetCache;
}
public function onTerminate(Event $terminateEvent)
{
if ($this->resetCache) {
foreach (Tool::getCachedSymfonyEnvironments() as $environment) {
$this->cacheClearer->clear($environment, [
'no-warmup' => true
]);
}
}
}
}