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

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