custom/plugins/NetiNextEasyCouponDesigns/src/NetiNextEasyCouponDesigns.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextEasyCouponDesigns;
  4. use Doctrine\DBAL\DBALException;
  5. use NetInventors\NetiNextEasyCouponDesigns\Components\RuleBasedContainerFile;
  6. use NetInventors\NetiNextEasyCouponDesigns\Components\RuleBasedContainerFileLoader;
  7. use NetInventors\NetiNextEasyCouponDesigns\Service\CheckService;
  8. use Shopware\Core\Framework\Parameter\AdditionalBundleParameters;
  9. use Shopware\Core\Framework\Plugin;
  10. use NetInventors\NetiNextEasyCouponDesigns\Components\Setup;
  11. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  12. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Throwable;
  15. use function is_file;
  16. use function version_compare;
  17. class NetiNextEasyCouponDesigns extends Plugin
  18. {
  19.     public const DOCUMENT_TYPE_ID 'B41C26FF07FA4F7A9D0E42A293A1CF0A';
  20.     public const DOCUMENT_TYPE    'easy_coupon';
  21.     private bool $autoloaderInjected false;
  22.     public function getAdditionalBundles(AdditionalBundleParameters $parameters): array
  23.     {
  24.         // This is not a nice solution, but there is no other way to inject the autoloader
  25.         if (!$this->autoloaderInjected) {
  26.             $this->injectAutoloader();
  27.             $this->autoloaderInjected true;
  28.         }
  29.         return parent::getAdditionalBundles($parameters);
  30.     }
  31.     public function build(ContainerBuilder $container): void
  32.     {
  33.         parent::build($container);
  34.         $ruleBasedContainerFileLoader = new RuleBasedContainerFileLoader(
  35.             $container,
  36.             $this->getPath()
  37.         );
  38.         /**
  39.          * @var string
  40.          *
  41.          * @psalm-suppress UndefinedDocblockClass
  42.          *                 Dockblock-defined type UnitEnum is available in PHP 8 >= 8.1.0
  43.          */
  44.         $version $container->getParameter('kernel.shopware_version');
  45.         $ruleBasedContainerFileLoader->load(
  46.             new RuleBasedContainerFile(
  47.                 $this->getPath() . '/Resources/config/services/flow.xml',
  48.                 function () use ($version) {
  49.                     return version_compare($versionCheckService::MINIMUM_FLOW_SHOPWARE_VERSION'>=');
  50.                 }
  51.             )
  52.         );
  53.     }
  54.     /**
  55.      * @throws Throwable
  56.      */
  57.     public function install(InstallContext $installContext): void
  58.     {
  59.         parent::install($installContext);
  60.         (new Setup($installContext$this->container))->install();
  61.     }
  62.     /**
  63.      * @throws Throwable
  64.      */
  65.     public function update(Plugin\Context\UpdateContext $updateContext): void
  66.     {
  67.         parent::install($updateContext);
  68.         (new Setup($updateContext$this->container))->update();
  69.     }
  70.     /**
  71.      * @throws DBALException
  72.      */
  73.     public function uninstall(UninstallContext $uninstallContext): void
  74.     {
  75.         parent::uninstall($uninstallContext);
  76.         if ($uninstallContext->keepUserData()) {
  77.             return;
  78.         }
  79.         (new Setup($uninstallContext$this->container))->uninstall();
  80.     }
  81.     private function injectAutoloader(): void
  82.     {
  83.         // For development
  84.         if (is_file(__DIR__ '/Resources/build/vendor/autoload.php')) {
  85.             require __DIR__ '/Resources/build/vendor/autoload.php';
  86.             return;
  87.         }
  88.         // For production
  89.         if (is_file(__DIR__ '/Resources/vendor/autoload.php')) {
  90.             require __DIR__ '/Resources/vendor/autoload.php';
  91.             return;
  92.         }
  93.     }
  94. }