<?phpdeclare(strict_types=1);namespace NetInventors\NetiNextEasyCouponDesigns;use Doctrine\DBAL\DBALException;use NetInventors\NetiNextEasyCouponDesigns\Components\RuleBasedContainerFile;use NetInventors\NetiNextEasyCouponDesigns\Components\RuleBasedContainerFileLoader;use NetInventors\NetiNextEasyCouponDesigns\Service\CheckService;use Shopware\Core\Framework\Parameter\AdditionalBundleParameters;use Shopware\Core\Framework\Plugin;use NetInventors\NetiNextEasyCouponDesigns\Components\Setup;use Shopware\Core\Framework\Plugin\Context\InstallContext;use Shopware\Core\Framework\Plugin\Context\UninstallContext;use Symfony\Component\DependencyInjection\ContainerBuilder;use Symfony\Component\DependencyInjection\ContainerInterface;use Throwable;use function is_file;use function version_compare;class NetiNextEasyCouponDesigns extends Plugin{ public const DOCUMENT_TYPE_ID = 'B41C26FF07FA4F7A9D0E42A293A1CF0A'; public const DOCUMENT_TYPE = 'easy_coupon'; private bool $autoloaderInjected = false; public function getAdditionalBundles(AdditionalBundleParameters $parameters): array { // This is not a nice solution, but there is no other way to inject the autoloader if (!$this->autoloaderInjected) { $this->injectAutoloader(); $this->autoloaderInjected = true; } return parent::getAdditionalBundles($parameters); } public function build(ContainerBuilder $container): void { parent::build($container); $ruleBasedContainerFileLoader = new RuleBasedContainerFileLoader( $container, $this->getPath() ); /** * @var string * * @psalm-suppress UndefinedDocblockClass * Dockblock-defined type UnitEnum is available in PHP 8 >= 8.1.0 */ $version = $container->getParameter('kernel.shopware_version'); $ruleBasedContainerFileLoader->load( new RuleBasedContainerFile( $this->getPath() . '/Resources/config/services/flow.xml', function () use ($version) { return version_compare($version, CheckService::MINIMUM_FLOW_SHOPWARE_VERSION, '>='); } ) ); } /** * @throws Throwable */ public function install(InstallContext $installContext): void { parent::install($installContext); if (!$this->container instanceof ContainerInterface) { return; } (new Setup($installContext, $this->container))->install(); } /** * @throws Throwable */ public function update(Plugin\Context\UpdateContext $updateContext): void { parent::install($updateContext); if (!$this->container instanceof ContainerInterface) { return; } (new Setup($updateContext, $this->container))->update(); } /** * @throws DBALException */ public function uninstall(UninstallContext $uninstallContext): void { parent::uninstall($uninstallContext); if ($uninstallContext->keepUserData() || !$this->container instanceof ContainerInterface) { return; } if (!$this->container instanceof ContainerInterface) { return; } (new Setup($uninstallContext, $this->container))->uninstall(); } private function injectAutoloader(): void { // For development if (is_file(__DIR__ . '/Resources/build/vendor/autoload.php')) { require __DIR__ . '/Resources/build/vendor/autoload.php'; return; } // For production if (is_file(__DIR__ . '/Resources/vendor/autoload.php')) { require __DIR__ . '/Resources/vendor/autoload.php'; return; } }}