/home/sharedstore/public_html/prestashop.sharedstore.ma/src/Core/Module
Edit: /home/sharedstore/public_html/prestashop.sharedstore.ma/src/Core/Module/EventSubscriber.php (2779B)
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
declare(strict_types=1);
namespace PrestaShop\PrestaShop\Core\Module;
use PrestaShop\PrestaShop\Adapter\Cache\Clearer\SymfonyCacheClearer;
use PrestaShopBundle\Event\ModuleManagementEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EventSubscriber implements EventSubscriberInterface
{
/**
* @var ModuleRepository
*/
private $moduleRepository;
/**
* @var SymfonyCacheClearer
*/
private $cacheClearer;
public function __construct(ModuleRepository $moduleRepository, SymfonyCacheClearer $cacheClearer)
{
$this->moduleRepository = $moduleRepository;
$this->cacheClearer = $cacheClearer;
}
public static function getSubscribedEvents()
{
return [
ModuleManagementEvent::INSTALL => 'onModuleInstalledOrUninstalled',
ModuleManagementEvent::UNINSTALL => 'onModuleInstalledOrUninstalled',
ModuleManagementEvent::UPGRADE => 'onModuleInstalledOrUninstalled',
ModuleManagementEvent::ENABLE => 'onModuleStateChanged',
ModuleManagementEvent::DISABLE => 'onModuleStateChanged',
ModuleManagementEvent::ENABLE_MOBILE => 'onModuleStateChanged',
ModuleManagementEvent::DISABLE_MOBILE => 'onModuleStateChanged',
];
}
public function onModuleStateChanged(ModuleManagementEvent $event): void
{
$moduleName = $event->getModule()->get('name');
$this->moduleRepository->clearCache($moduleName, true);
}
public function onModuleInstalledOrUninstalled(ModuleManagementEvent $event): void
{
$this->onModuleStateChanged($event);
$this->cacheClearer->clear();
}
}