custom/plugins/PickwareGls/vendor/pickware/validation-bundle/src/PickwareValidationBundle.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\ValidationBundle;
  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 PickwareValidationBundle extends Bundle
  18. {
  19.     /**
  20.      * @var class-string<Bundle>[]
  21.      */
  22.     private const ADDITIONAL_BUNDLES = [];
  23.     private static ?PickwareValidationBundle $instance null;
  24.     private static bool $registered false;
  25.     private static bool $migrationsRegistered false;
  26.     public static function register(Collection $bundleCollection): void
  27.     {
  28.         if (self::$registered) {
  29.             return;
  30.         }
  31.         $bundleCollection->add(self::getInstance());
  32.         foreach (self::ADDITIONAL_BUNDLES as $bundle) {
  33.             $bundle::register($bundleCollection);
  34.         }
  35.         self::$registered true;
  36.     }
  37.     public static function registerMigrations(MigrationSource $migrationSource): void
  38.     {
  39.         if (self::$migrationsRegistered) {
  40.             return;
  41.         }
  42.         $migrationsPath self::getInstance()->getMigrationPath();
  43.         $migrationNamespace self::getInstance()->getMigrationNamespace();
  44.         $migrationSource->addDirectory($migrationsPath$migrationNamespace);
  45.         self::$migrationsRegistered true;
  46.         foreach (self::ADDITIONAL_BUNDLES as $bundle) {
  47.             $bundle::registerMigrations($migrationSource);
  48.         }
  49.     }
  50.     public static function getInstance(): self
  51.     {
  52.         if (!self::$instance) {
  53.             self::$instance = new self();
  54.         }
  55.         return self::$instance;
  56.     }
  57.     public function build(ContainerBuilder $containerBuilder): void
  58.     {
  59.         parent::build($containerBuilder);
  60.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  61.         $loader->load('DependencyInjection/service.xml');
  62.         $loader->load('DependencyInjection/subscriber.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. }