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

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