custom/plugins/SwagCommercial/src/SwagCommercial.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Commercial;
  3. use Shopware\Commercial\CustomPricing\CustomPricing;
  4. use Shopware\Commercial\FlowBuilder\FlowSharing\FlowSharing;
  5. use Shopware\Commercial\Licensing\Exception\LicenseExpiredException;
  6. use Shopware\Commercial\Licensing\License;
  7. use Shopware\Commercial\Licensing\LicenseUpdater;
  8. use Shopware\Commercial\MultiWarehouse\MultiWarehouse;
  9. use Shopware\Commercial\MultiWarehouse\MultiWarehouseUninstallHandler;
  10. use Shopware\Commercial\RuleBuilderPreview\RuleBuilderPreview;
  11. use Shopware\Commercial\System\UninstallHandler;
  12. use Shopware\Commercial\TextGenerator\TextGenerator;
  13. use Shopware\Core\Framework\Parameter\AdditionalBundleParameters;
  14. use Shopware\Core\Framework\Plugin;
  15. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  16. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  17. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  18. use Shopware\Core\Framework\Store\Authentication\StoreRequestOptionsProvider;
  19. use Shopware\Core\System\SystemConfig\SystemConfigService;
  20. use Symfony\Component\Config\FileLocator;
  21. use Symfony\Component\Config\Loader\DelegatingLoader;
  22. use Symfony\Component\Config\Loader\LoaderResolver;
  23. use Symfony\Component\DependencyInjection\ContainerBuilder;
  24. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  25. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  26. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  27. class SwagCommercial extends Plugin
  28. {
  29.     public function boot(): void
  30.     {
  31.         $systemConfigService $this->container->get(SystemConfigService::class);
  32.         try {
  33.             License::set($systemConfigService);
  34.         } catch (LicenseExpiredException $e) {
  35.             // The given license key is expired. Renew now
  36.             $this->container->get(LicenseUpdater::class)->sync();
  37.             License::set($systemConfigService);
  38.         }
  39.     }
  40.     public function install(InstallContext $installContext): void
  41.     {
  42.         try {
  43.             $this->getLicenseUpdater()->sync();
  44.         } catch (\Throwable $e) {
  45.             // installation has to work always
  46.         }
  47.     }
  48.     public function uninstall(UninstallContext $uninstallContext): void
  49.     {
  50.         foreach ($this->getUninstallHandlers() as $handler) {
  51.             $handler->uninstall($this->container$uninstallContext);
  52.         }
  53.     }
  54.     public function update(UpdateContext $updateContext): void
  55.     {
  56.         try {
  57.             $this->getLicenseUpdater()->sync();
  58.         } catch (\Throwable $e) {
  59.             // update has to work always
  60.         }
  61.     }
  62.     public function build(ContainerBuilder $container): void
  63.     {
  64.         parent::build($container);
  65.         $fileLocator = new FileLocator($this->getPath());
  66.         $loaderResolver = new LoaderResolver([
  67.             new XmlFileLoader($container$fileLocator),
  68.             new YamlFileLoader($container$fileLocator),
  69.             new PhpFileLoader($container$fileLocator),
  70.         ]);
  71.         $delegatingLoader = new DelegatingLoader($loaderResolver);
  72.         $delegatingLoader->load(__DIR__ '/Licensing/DependencyInjection/services.xml');
  73.     }
  74.     public function getAdditionalBundles(AdditionalBundleParameters $parameters): array
  75.     {
  76.         return [
  77.             new CustomPricing(),
  78.             new RuleBuilderPreview(),
  79.             new FlowSharing(),
  80.             new MultiWarehouse(),
  81.             new TextGenerator(),
  82.         ];
  83.     }
  84.     /**
  85.      * @return array<UninstallHandler>
  86.      */
  87.     protected function getUninstallHandlers(): array
  88.     {
  89.         return [
  90.             new MultiWarehouseUninstallHandler(),
  91.         ];
  92.     }
  93.     private function getLicenseUpdater(): LicenseUpdater
  94.     {
  95.         return new LicenseUpdater(
  96.             $this->container->get('shopware.store_client'),
  97.             $this->container->get(StoreRequestOptionsProvider::class),
  98.             $this->container->get(SystemConfigService::class)
  99.         );
  100.     }
  101. }