custom/plugins/CrayssnLabsRichSnippetsCreator/src/Subscriber/PluginSubscriber.php line 68

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace CrayssnLabsRichSnippetsCreator\Subscriber;
  4. use CrayssnLabsRichSnippetsCreator\CrayssnLabsRichSnippetsCreator;
  5. use League\Flysystem\FilesystemInterface;
  6. use Symfony\Component\Cache\Adapter\AdapterInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Shopware\Core\System\SystemConfig\Event\SystemConfigChangedEvent;
  9. /**
  10.  * Class PageSubscriber
  11.  *
  12.  * @package   CrayssnLabsRichSnippetsCreator\Subscriber
  13.  *
  14.  * @author    Sebastian Ludwig <dev@cl.team>
  15.  * @copyright Copyright (c) 2022, CrayssnLabs Ludwig Wiegler GbR
  16.  */
  17. class PluginSubscriber implements EventSubscriberInterface
  18. {
  19.     const PLACES_ID_KEY 'CrayssnLabsRichSnippetsCreator.config.placesId';
  20.     /**
  21.      * @var \Symfony\Component\Cache\Adapter\AdapterInterface
  22.      */
  23.     private $cache;
  24.     /**
  25.      * @var \League\Flysystem\FilesystemInterface
  26.      */
  27.     private $fileSystemPublic;
  28.     /**
  29.      * @param \Symfony\Component\Cache\Adapter\AdapterInterface $_cache
  30.      * @param \League\Flysystem\FilesystemInterface             $_fileSystemPublic
  31.      */
  32.     public function __construct(
  33.         AdapterInterface $_cache,
  34.         FilesystemInterface $_fileSystemPublic
  35.     )
  36.     {
  37.         $this->cache $_cache;
  38.         $this->fileSystemPublic $_fileSystemPublic;
  39.     }
  40.     /**
  41.      * Function getSubscribedEvents
  42.      *
  43.      * @return string[]
  44.      */
  45.     public static function getSubscribedEvents(): array
  46.     {
  47.         return [
  48.             SystemConfigChangedEvent::class => 'onSystemConfigChanged',
  49.         ];
  50.     }
  51.     /**
  52.      * Function onSystemConfigChanged
  53.      *
  54.      * @param \Shopware\Core\System\SystemConfig\Event\SystemConfigChangedEvent $_event
  55.      *
  56.      * @throws \League\Flysystem\FileNotFoundException
  57.      * @throws \Psr\Cache\InvalidArgumentException
  58.      */
  59.     public function onSystemConfigChanged(SystemConfigChangedEvent $_event)
  60.     {
  61.         if($_event->getKey() !== self::PLACES_ID_KEY)
  62.         {
  63.             return;
  64.         }
  65.         $this->cache->deleteItem(CrayssnLabsRichSnippetsCreator::CACHE_KEY);
  66.         $cachePictureFile CrayssnLabsRichSnippetsCreator::PUBLIC_CACHE_FOLDER DIRECTORY_SEPARATOR 'request-cache.jpg';
  67.         if($this->fileSystemPublic->has($cachePictureFile))
  68.         {
  69.             $this->fileSystemPublic->delete($cachePictureFile);
  70.         }
  71.     }
  72. }