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

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