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

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