vendor/shopware/storefront/Theme/StorefrontPluginRegistry.php line 64

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme;
  3. use Shopware\Core\Framework\App\ActiveAppsLoader;
  4. use Shopware\Core\Framework\Bundle;
  5. use Shopware\Core\Framework\Log\Package;
  6. use Shopware\Storefront\Theme\StorefrontPluginConfiguration\AbstractStorefrontPluginConfigurationFactory;
  7. use Shopware\Storefront\Theme\StorefrontPluginConfiguration\StorefrontPluginConfigurationCollection;
  8. use Symfony\Component\HttpKernel\KernelInterface;
  9. use Symfony\Contracts\Service\ResetInterface;
  10. #[Package('storefront')]
  11. class StorefrontPluginRegistry implements StorefrontPluginRegistryInterfaceResetInterface
  12. {
  13.     final public const BASE_THEME_NAME 'Storefront';
  14.     private ?StorefrontPluginConfigurationCollection $pluginConfigurations null;
  15.     /**
  16.      * @internal
  17.      */
  18.     public function __construct(
  19.         private readonly KernelInterface $kernel,
  20.         private readonly AbstractStorefrontPluginConfigurationFactory $pluginConfigurationFactory,
  21.         private readonly ActiveAppsLoader $activeAppsLoader
  22.     ) {
  23.     }
  24.     public function getConfigurations(): StorefrontPluginConfigurationCollection
  25.     {
  26.         if ($this->pluginConfigurations) {
  27.             return $this->pluginConfigurations;
  28.         }
  29.         $this->pluginConfigurations = new StorefrontPluginConfigurationCollection();
  30.         $this->addPluginConfigs();
  31.         $this->addAppConfigs();
  32.         return $this->pluginConfigurations ?? new StorefrontPluginConfigurationCollection();
  33.     }
  34.     public function reset(): void
  35.     {
  36.         $this->pluginConfigurations null;
  37.     }
  38.     private function addPluginConfigs(): void
  39.     {
  40.         foreach ($this->kernel->getBundles() as $bundle) {
  41.             if (!$bundle instanceof Bundle) {
  42.                 continue;
  43.             }
  44.             $config $this->pluginConfigurationFactory->createFromBundle($bundle);
  45.             $this->pluginConfigurations === null ?: $this->pluginConfigurations->add($config);
  46.         }
  47.     }
  48.     private function addAppConfigs(): void
  49.     {
  50.         foreach ($this->activeAppsLoader->getActiveApps() as $app) {
  51.             $config $this->pluginConfigurationFactory->createFromApp($app['name'], $app['path']);
  52.             $this->pluginConfigurations === null ?: $this->pluginConfigurations->add($config);
  53.         }
  54.     }
  55. }