custom/plugins/PickwareErpStarter/vendor/pickware/api-error-handling-bundle/src/PickwareApiErrorHandlingBundle.php line 24

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\ApiErrorHandlingBundle;
  11. use Doctrine\DBAL\Connection;
  12. use Pickware\BundleInstaller\BundleInstaller;
  13. use Shopware\Core\Framework\Bundle;
  14. use Shopware\Core\Framework\Migration\MigrationSource;
  15. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  16. use Shopware\Core\Framework\Struct\Collection;
  17. use Symfony\Component\Config\FileLocator;
  18. use Symfony\Component\DependencyInjection\ContainerBuilder;
  19. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  20. class PickwareApiErrorHandlingBundle extends Bundle
  21. {
  22.     private static ?self $instance null;
  23.     private static bool $registered false;
  24.     private static bool $migrationsRegistered false;
  25.     public static function register(Collection $bundleCollection): void
  26.     {
  27.         if (self::$registered) {
  28.             return;
  29.         }
  30.         $bundleCollection->add(self::getInstance());
  31.         self::$registered true;
  32.     }
  33.     public static function registerMigrations(MigrationSource $migrationSource): void
  34.     {
  35.         if (self::$migrationsRegistered) {
  36.             return;
  37.         }
  38.         $migrationsPath self::getInstance()->getMigrationPath();
  39.         $migrationNamespace self::getInstance()->getMigrationNamespace();
  40.         $migrationSource->addDirectory($migrationsPath$migrationNamespace);
  41.         self::$migrationsRegistered true;
  42.     }
  43.     public static function getInstance(): self
  44.     {
  45.         if (!self::$instance) {
  46.             self::$instance = new self();
  47.         }
  48.         return self::$instance;
  49.     }
  50.     public function build(ContainerBuilder $containerBuilder): void
  51.     {
  52.         parent::build($containerBuilder);
  53.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  54.         $loader->load('ControllerExceptionHandling/DependencyInjection/subscriber.xml');
  55.     }
  56.     public function shutdown(): void
  57.     {
  58.         parent::shutdown();
  59.         // Shopware may reboot the kernel under certain circumstances (e.g. plugin un-/installation) within a single
  60.         // request. After the kernel was rebooted, our bundles have to be registered again.
  61.         // We reset the registration flag when the kernel is shut down. This will cause the bundles to be registered
  62.         // again in the (re)boot process.
  63.         self::$registered false;
  64.     }
  65.     public function uninstall(UninstallContext $uninstallContext): void
  66.     {
  67.         if ($uninstallContext->keepUserData()) {
  68.             return;
  69.         }
  70.         $db $this->container->get(Connection::class);
  71.         // We need eight backslashes, as we need to match a single one and double the count for each of the following:
  72.         // 1. The PHP parser
  73.         // 2. The MySQL parser
  74.         // 3. The MySQL pattern matcher (only when using LIKE)
  75.         $db->executeStatement("DELETE FROM `migration` WHERE `class` LIKE 'Pickware\\\\\\\\ApiErrorHandlingBundle\\\\\\\\%'");
  76.         BundleInstaller::createForContainerAndClass($this->containerself::class)->uninstall($uninstallContext);
  77.     }
  78. }