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

  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.  * @internal
  12.  */
  13. #[Package('storefront')]
  14. class ThemeAppLifecycleHandler implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @internal
  18.      */
  19.     public function __construct(
  20.         private readonly StorefrontPluginRegistryInterface $themeRegistry,
  21.         private readonly AbstractStorefrontPluginConfigurationFactory $themeConfigFactory,
  22.         private readonly ThemeLifecycleHandler $themeLifecycleHandler
  23.     ) {
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             AppUpdatedEvent::class => 'handleAppActivationOrUpdate',
  29.             AppActivatedEvent::class => 'handleAppActivationOrUpdate',
  30.             AppDeactivatedEvent::class => 'handleUninstall',
  31.         ];
  32.     }
  33.     public function handleAppActivationOrUpdate(AppChangedEvent $event): void
  34.     {
  35.         $app $event->getApp();
  36.         if (!$app->isActive()) {
  37.             return;
  38.         }
  39.         $configurationCollection $this->themeRegistry->getConfigurations();
  40.         $config $configurationCollection->getByTechnicalName($app->getName());
  41.         if (!$config) {
  42.             $config $this->themeConfigFactory->createFromApp($app->getName(), $app->getPath());
  43.             $configurationCollection = clone $configurationCollection;
  44.             $configurationCollection->add($config);
  45.         }
  46.         $this->themeLifecycleHandler->handleThemeInstallOrUpdate(
  47.             $config,
  48.             $configurationCollection,
  49.             $event->getContext()
  50.         );
  51.     }
  52.     public function handleUninstall(AppDeactivatedEvent $event): void
  53.     {
  54.         $config $this->themeRegistry->getConfigurations()->getByTechnicalName($event->getApp()->getName());
  55.         if (!$config) {
  56.             return;
  57.         }
  58.         $this->themeLifecycleHandler->handleThemeUninstall($config$event->getContext());
  59.     }
  60. }