vendor/shopware/storefront/Theme/SalesChannelThemeLoader.php line 42

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Shopware\Core\Framework\Uuid\Uuid;
  6. use Symfony\Contracts\Service\ResetInterface;
  7. #[Package('storefront')]
  8. class SalesChannelThemeLoader implements ResetInterface
  9. {
  10.     /**
  11.      * @var array<string, array{themeId?: string, themeName?: string, parentThemeName?: string}>
  12.      */
  13.     private array $themes = [];
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(private readonly Connection $connection)
  18.     {
  19.     }
  20.     /**
  21.      * @return array{themeId?: string, themeName?: string, parentThemeName?: string}
  22.      */
  23.     public function load(string $salesChannelId): array
  24.     {
  25.         if (!empty($this->themes[$salesChannelId])) {
  26.             return $this->themes[$salesChannelId];
  27.         }
  28.         $theme $this->connection->fetchAssociative('
  29.             SELECT LOWER(HEX(theme.id)) themeId, theme.technical_name as themeName, parentTheme.technical_name as parentThemeName
  30.             FROM sales_channel
  31.                 LEFT JOIN theme_sales_channel ON sales_channel.id = theme_sales_channel.sales_channel_id
  32.                 LEFT JOIN theme ON theme_sales_channel.theme_id = theme.id
  33.                 LEFT JOIN theme AS parentTheme ON parentTheme.id = theme.parent_theme_id
  34.             WHERE sales_channel.id = :salesChannelId
  35.         ', [
  36.             'salesChannelId' => Uuid::fromHexToBytes($salesChannelId),
  37.         ]);
  38.         return $this->themes[$salesChannelId] = $theme ?: [];
  39.     }
  40.     public function reset(): void
  41.     {
  42.         $this->themes = [];
  43.     }
  44. }