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

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