custom/plugins/PickwareWms/vendor/pickware/api-versioning-bundle/src/PickwareApiVersioningBundle.php line 23

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