<?php
declare(strict_types=1);
namespace CrayssnLabsRichSnippetsCreator\Subscriber;
use CrayssnLabsRichSnippetsCreator\CrayssnLabsRichSnippetsCreator;
use League\Flysystem\FilesystemInterface;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\System\SystemConfig\Event\SystemConfigChangedEvent;
/**
* Class PageSubscriber
*
* @package CrayssnLabsRichSnippetsCreator\Subscriber
*
* @author Sebastian Ludwig <dev@cl.team>
* @copyright Copyright (c) 2022, CrayssnLabs Ludwig Wiegler GbR
*/
class PluginSubscriber implements EventSubscriberInterface
{
const PLACES_ID_KEY = 'CrayssnLabsRichSnippetsCreator.config.placesId';
/**
* @var \Symfony\Component\Cache\Adapter\AdapterInterface
*/
private $cache;
/**
* @var \League\Flysystem\FilesystemInterface
*/
private $fileSystemPublic;
/**
* @param \Symfony\Component\Cache\Adapter\AdapterInterface $_cache
* @param \League\Flysystem\FilesystemInterface $_fileSystemPublic
*/
public function __construct(
AdapterInterface $_cache,
FilesystemInterface $_fileSystemPublic
)
{
$this->cache = $_cache;
$this->fileSystemPublic = $_fileSystemPublic;
}
/**
* Function getSubscribedEvents
*
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
SystemConfigChangedEvent::class => 'onSystemConfigChanged',
];
}
/**
* Function onSystemConfigChanged
*
* @param \Shopware\Core\System\SystemConfig\Event\SystemConfigChangedEvent $_event
*
* @throws \League\Flysystem\FileNotFoundException
* @throws \Psr\Cache\InvalidArgumentException
*/
public function onSystemConfigChanged(SystemConfigChangedEvent $_event)
{
if($_event->getKey() !== self::PLACES_ID_KEY)
{
return;
}
$this->cache->deleteItem(CrayssnLabsRichSnippetsCreator::CACHE_KEY);
$cachePictureFile = CrayssnLabsRichSnippetsCreator::PUBLIC_CACHE_FOLDER . DIRECTORY_SEPARATOR . 'request-cache.jpg';
if($this->fileSystemPublic->has($cachePictureFile))
{
$this->fileSystemPublic->delete($cachePictureFile);
}
}
}