custom/plugins/PickwareDhl/vendor/pickware/money-bundle/src/MoneyBundle.php line 25

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\MoneyBundle;
  11. use Pickware\BundleInstaller\BundleInstaller;
  12. use Pickware\DalBundle\DalBundle;
  13. use Shopware\Core\Framework\Bundle;
  14. use Shopware\Core\Framework\Migration\MigrationSource;
  15. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  16. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  17. use Shopware\Core\Framework\Struct\Collection;
  18. use Symfony\Component\Config\FileLocator;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  21. class MoneyBundle extends Bundle
  22. {
  23.     /**
  24.      * @var class-string<Bundle>[]
  25.      */
  26.     private const ADDITIONAL_BUNDLES = [DalBundle::class];
  27.     private static ?self $instance null;
  28.     private static bool $registered false;
  29.     private static bool $migrationsRegistered false;
  30.     public static function register(Collection $bundleCollection): void
  31.     {
  32.         if (self::$registered) {
  33.             return;
  34.         }
  35.         $bundleCollection->add(self::getInstance());
  36.         foreach (self::ADDITIONAL_BUNDLES as $bundle) {
  37.             $bundle::register($bundleCollection);
  38.         }
  39.         self::$registered true;
  40.     }
  41.     public static function registerMigrations(MigrationSource $migrationSource): void
  42.     {
  43.         if (self::$migrationsRegistered) {
  44.             return;
  45.         }
  46.         $migrationsPath self::getInstance()->getMigrationPath();
  47.         $migrationNamespace self::getInstance()->getMigrationNamespace();
  48.         $migrationSource->addDirectory($migrationsPath$migrationNamespace);
  49.         self::$migrationsRegistered true;
  50.     }
  51.     public static function getInstance(): self
  52.     {
  53.         if (!self::$instance) {
  54.             self::$instance = new self();
  55.         }
  56.         return self::$instance;
  57.     }
  58.     public function build(ContainerBuilder $containerBuilder): void
  59.     {
  60.         parent::build($containerBuilder);
  61.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  62.         $loader->load('DependencyInjection/service.xml');
  63.     }
  64.     public function shutdown(): void
  65.     {
  66.         parent::shutdown();
  67.         // Shopware may reboot the kernel under certain circumstances (e.g. plugin un-/installation) within a single
  68.         // request. After the kernel was rebooted, our bundles have to be registered again.
  69.         // We reset the registration flag when the kernel is shut down. This will cause the bundles to be registered
  70.         // again in the (re)boot process.
  71.         self::$registered false;
  72.     }
  73.     public function install(InstallContext $installContext): void
  74.     {
  75.         BundleInstaller::createForContainerAndClass($this->containerself::class)
  76.             ->install(self::ADDITIONAL_BUNDLES$installContext);
  77.     }
  78.     public function onAfterActivate(InstallContext $installContext): void
  79.     {
  80.         BundleInstaller::createForContainerAndClass($this->containerself::class)
  81.             ->onAfterActivate(self::ADDITIONAL_BUNDLES$installContext);
  82.     }
  83.     public function uninstall(UninstallContext $uninstallContext): void
  84.     {
  85.         BundleInstaller::createForContainerAndClass($this->containerself::class)->uninstall($uninstallContext);
  86.     }
  87. }