vendor/shopware/storefront/Theme/ConfigLoader/StaticFileConfigDumper.php line 60

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shopware\Storefront\Theme\ConfigLoader;
  4. use League\Flysystem\FilesystemInterface;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Storefront\Theme\Event\ThemeAssignedEvent;
  7. use Shopware\Storefront\Theme\Event\ThemeConfigChangedEvent;
  8. use Shopware\Storefront\Theme\Event\ThemeConfigResetEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. /**
  11.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  12.  */
  13. class StaticFileConfigDumper implements EventSubscriberInterface
  14. {
  15.     private AbstractConfigLoader $configLoader;
  16.     private FilesystemInterface $filesystem;
  17.     private AbstractAvailableThemeProvider $availableThemeProvider;
  18.     /**
  19.      * @internal
  20.      */
  21.     public function __construct(
  22.         AbstractConfigLoader $configLoader,
  23.         AbstractAvailableThemeProvider $availableThemeProvider,
  24.         FilesystemInterface $filesystem
  25.     ) {
  26.         $this->configLoader $configLoader;
  27.         $this->filesystem $filesystem;
  28.         $this->availableThemeProvider $availableThemeProvider;
  29.     }
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             ThemeConfigChangedEvent::class => 'dumpConfigFromEvent',
  34.             ThemeAssignedEvent::class => 'dumpConfigFromEvent',
  35.             ThemeConfigResetEvent::class => 'dumpConfigFromEvent',
  36.         ];
  37.     }
  38.     public function dumpConfig(Context $context): void
  39.     {
  40.         $salesChannelToTheme $this->availableThemeProvider->load($context);
  41.         $this->filesystem->put(StaticFileAvailableThemeProvider::THEME_INDEXjson_encode($salesChannelToTheme, \JSON_THROW_ON_ERROR));
  42.         foreach ($salesChannelToTheme as $themeId) {
  43.             $struct $this->configLoader->load($themeId$context);
  44.             $path = \sprintf('theme-config/%s.json'$themeId);
  45.             $this->filesystem->put($path, \json_encode($struct->jsonSerialize(), \JSON_THROW_ON_ERROR));
  46.         }
  47.     }
  48.     public function dumpConfigFromEvent(): void
  49.     {
  50.         $this->dumpConfig(Context::createDefaultContext());
  51.     }
  52. }