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

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. class StaticFileConfigDumper implements EventSubscriberInterface
  11. {
  12.     private AbstractConfigLoader $configLoader;
  13.     private FilesystemInterface $filesystem;
  14.     private AbstractAvailableThemeProvider $availableThemeProvider;
  15.     /**
  16.      * @internal
  17.      */
  18.     public function __construct(
  19.         AbstractConfigLoader $configLoader,
  20.         AbstractAvailableThemeProvider $availableThemeProvider,
  21.         FilesystemInterface $filesystem
  22.     ) {
  23.         $this->configLoader $configLoader;
  24.         $this->filesystem $filesystem;
  25.         $this->availableThemeProvider $availableThemeProvider;
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             ThemeConfigChangedEvent::class => 'dumpConfigFromEvent',
  31.             ThemeAssignedEvent::class => 'dumpConfigFromEvent',
  32.             ThemeConfigResetEvent::class => 'dumpConfigFromEvent',
  33.         ];
  34.     }
  35.     public function dumpConfig(Context $context): void
  36.     {
  37.         $salesChannelToTheme $this->availableThemeProvider->load($context);
  38.         $this->filesystem->put(StaticFileAvailableThemeProvider::THEME_INDEXjson_encode($salesChannelToTheme, \JSON_THROW_ON_ERROR));
  39.         foreach ($salesChannelToTheme as $themeId) {
  40.             $struct $this->configLoader->load($themeId$context);
  41.             $path = \sprintf('theme-config/%s.json'$themeId);
  42.             $this->filesystem->put($path, \json_encode($struct->jsonSerialize(), \JSON_THROW_ON_ERROR));
  43.         }
  44.     }
  45.     public function dumpConfigFromEvent(): void
  46.     {
  47.         $this->dumpConfig(Context::createDefaultContext());
  48.     }
  49. }