custom/plugins/PickwareDhl/vendor/pickware/dal-bundle/src/DalBundle.php line 21

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\DalBundle;
  11. use Shopware\Core\Framework\Bundle;
  12. use Shopware\Core\Framework\Migration\MigrationSource;
  13. use Shopware\Core\Framework\Struct\Collection;
  14. use Symfony\Component\Config\FileLocator;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  17. class DalBundle extends Bundle
  18. {
  19.     private static ?self $instance null;
  20.     private static bool $registered false;
  21.     private static bool $migrationsRegistered false;
  22.     public static function register(Collection $bundleCollection): void
  23.     {
  24.         if (!self::$registered) {
  25.             $bundleCollection->add(self::getInstance());
  26.         }
  27.         self::$registered true;
  28.     }
  29.     public static function registerMigrations(MigrationSource $migrationSource): void
  30.     {
  31.         if (self::$migrationsRegistered) {
  32.             return;
  33.         }
  34.         $migrationsPath self::getInstance()->getMigrationPath();
  35.         $migrationNamespace self::getInstance()->getMigrationNamespace();
  36.         $migrationSource->addDirectory($migrationsPath$migrationNamespace);
  37.         self::$migrationsRegistered true;
  38.     }
  39.     public static function getInstance(): self
  40.     {
  41.         if (!self::$instance) {
  42.             self::$instance = new self();
  43.         }
  44.         return self::$instance;
  45.     }
  46.     public function build(ContainerBuilder $containerBuilder): void
  47.     {
  48.         parent::build($containerBuilder);
  49.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  50.         $loader->load('DependencyInjection/field.xml');
  51.         $loader->load('DependencyInjection/service.xml');
  52.     }
  53.     public function shutdown(): void
  54.     {
  55.         parent::shutdown();
  56.         // Shopware may reboot the kernel under certain circumstances (e.g. plugin un-/installation) within a single
  57.         // request. After the kernel was rebooted, our bundles have to be registered again.
  58.         // We reset the registration flag when the kernel is shut down. This will cause the bundles to be registered
  59.         // again in the (re)boot process.
  60.         self::$registered false;
  61.     }
  62. }