vendor/shopware/storefront/Theme/ThemeAppLifecycleHandler.php line 70

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme;
  3. use Shopware\Core\Framework\App\Event\AppActivatedEvent;
  4. use Shopware\Core\Framework\App\Event\AppChangedEvent;
  5. use Shopware\Core\Framework\App\Event\AppDeactivatedEvent;
  6. use Shopware\Core\Framework\App\Event\AppUpdatedEvent;
  7. use Shopware\Core\Framework\Log\Package;
  8. use Shopware\Storefront\Theme\StorefrontPluginConfiguration\AbstractStorefrontPluginConfigurationFactory;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. /**
  11.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  12.  */
  13. #[Package('storefront')]
  14. class ThemeAppLifecycleHandler implements EventSubscriberInterface
  15. {
  16.     private StorefrontPluginRegistryInterface $themeRegistry;
  17.     private AbstractStorefrontPluginConfigurationFactory $themeConfigFactory;
  18.     private ThemeLifecycleHandler $themeLifecycleHandler;
  19.     /**
  20.      * @internal
  21.      */
  22.     public function __construct(
  23.         StorefrontPluginRegistryInterface $themeRegistry,
  24.         AbstractStorefrontPluginConfigurationFactory $themeConfigFactory,
  25.         ThemeLifecycleHandler $themeLifecycleHandler
  26.     ) {
  27.         $this->themeRegistry $themeRegistry;
  28.         $this->themeConfigFactory $themeConfigFactory;
  29.         $this->themeLifecycleHandler $themeLifecycleHandler;
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             AppUpdatedEvent::class => 'handleAppActivationOrUpdate',
  35.             AppActivatedEvent::class => 'handleAppActivationOrUpdate',
  36.             AppDeactivatedEvent::class => 'handleUninstall',
  37.         ];
  38.     }
  39.     public function handleAppActivationOrUpdate(AppChangedEvent $event): void
  40.     {
  41.         $app $event->getApp();
  42.         if (!$app->isActive()) {
  43.             return;
  44.         }
  45.         $configurationCollection $this->themeRegistry->getConfigurations();
  46.         $config $configurationCollection->getByTechnicalName($app->getName());
  47.         if (!$config) {
  48.             $config $this->themeConfigFactory->createFromApp($app->getName(), $app->getPath());
  49.             $configurationCollection = clone $configurationCollection;
  50.             $configurationCollection->add($config);
  51.         }
  52.         $this->themeLifecycleHandler->handleThemeInstallOrUpdate(
  53.             $config,
  54.             $configurationCollection,
  55.             $event->getContext()
  56.         );
  57.     }
  58.     public function handleUninstall(AppDeactivatedEvent $event): void
  59.     {
  60.         $config $this->themeRegistry->getConfigurations()->getByTechnicalName($event->getApp()->getName());
  61.         if (!$config) {
  62.             return;
  63.         }
  64.         $this->themeLifecycleHandler->handleThemeUninstall($config$event->getContext());
  65.     }
  66. }