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

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