custom/plugins/PickwareErpPro/vendor/pickware/pickware-ups-bundle/src/PickwareUpsBundle.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Pickware GmbH. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Pickware\PickwareUpsBundle;
  11. use Pickware\BundleInstaller\BundleInstaller;
  12. use Pickware\DalBundle\DalBundle;
  13. use Pickware\PickwareUpsBundle\Installation\PickwareUpsBundleInstaller;
  14. use Pickware\ShippingBundle\PickwareShippingBundle;
  15. use Shopware\Core\Framework\Bundle;
  16. use Shopware\Core\Framework\Migration\MigrationSource;
  17. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  18. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  19. use Shopware\Core\Framework\Struct\Collection;
  20. use Symfony\Component\Config\FileLocator;
  21. use Symfony\Component\DependencyInjection\ContainerBuilder;
  22. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  23. class PickwareUpsBundle extends Bundle
  24. {
  25.     /**
  26.      * @var class-string<Bundle>[]
  27.      */
  28.     private const ADDITIONAL_BUNDLES = [
  29.         DalBundle::class,
  30.         PickwareShippingBundle::class,
  31.     ];
  32.     private static ?self $instance null;
  33.     private static bool $registered false;
  34.     private static bool $migrationsRegistered false;
  35.     public static function register(Collection $bundleCollection): void
  36.     {
  37.         if (self::$registered) {
  38.             return;
  39.         }
  40.         $bundleCollection->add(self::getInstance());
  41.         foreach (self::ADDITIONAL_BUNDLES as $bundle) {
  42.             $bundle::register($bundleCollection);
  43.         }
  44.         self::$registered true;
  45.     }
  46.     public static function registerMigrations(MigrationSource $migrationSource): void
  47.     {
  48.         if (self::$migrationsRegistered) {
  49.             return;
  50.         }
  51.         $migrationsPath self::getInstance()->getMigrationPath();
  52.         $migrationNamespace self::getInstance()->getMigrationNamespace();
  53.         $migrationSource->addDirectory($migrationsPath$migrationNamespace);
  54.         self::$migrationsRegistered true;
  55.         foreach (self::ADDITIONAL_BUNDLES as $bundle) {
  56.             $bundle::registerMigrations($migrationSource);
  57.         }
  58.     }
  59.     public static function getInstance(): self
  60.     {
  61.         if (!self::$instance) {
  62.             self::$instance = new self();
  63.         }
  64.         return self::$instance;
  65.     }
  66.     public function build(ContainerBuilder $containerBuilder): void
  67.     {
  68.         parent::build($containerBuilder);
  69.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  70.         $loader->load('Adapter/DependencyInjection/service.xml');
  71.         $loader->load('Api/DependencyInjection/service.xml');
  72.         $loader->load('Api/DependencyInjection/controller.xml');
  73.     }
  74.     public function shutdown(): void
  75.     {
  76.         parent::shutdown();
  77.         // Shopware may reboot the kernel under certain circumstances (e.g. plugin un-/installation) within a single
  78.         // request. After the kernel was rebooted, our bundles have to be registered again.
  79.         // We reset the registration flag when the kernel is shut down. This will cause the bundles to be registered
  80.         // again in the (re)boot process.
  81.         self::$registered false;
  82.     }
  83.     public function install(InstallContext $installContext): void
  84.     {
  85.         BundleInstaller::createForContainerAndClass($this->containerself::class)
  86.             ->install(self::ADDITIONAL_BUNDLES$installContext);
  87.         PickwareUpsBundleInstaller::initFromContainer($this->container)->install($installContext->getContext());
  88.     }
  89.     public function onAfterActivate(InstallContext $installContext): void
  90.     {
  91.         BundleInstaller::createForContainerAndClass($this->containerself::class)
  92.             ->onAfterActivate(self::ADDITIONAL_BUNDLES$installContext);
  93.     }
  94.     public function uninstall(UninstallContext $uninstallContext): void
  95.     {
  96.         PickwareUpsBundleInstaller::initFromContainer($this->container)->uninstall($uninstallContext->getContext());
  97.         BundleInstaller::createForContainerAndClass($this->containerself::class)->uninstall($uninstallContext);
  98.     }
  99. }