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

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