From f85facee9b5bebc14b734444c69262ec2d7c01e2 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 12 Jan 2025 15:15:16 +0100 Subject: [PATCH] Remove support for container-aware migrations --- UPGRADE.md | 5 +++ config/services.xml | 8 ----- phpstan-baseline.neon | 11 ------ phpstan.neon.dist | 5 --- .../DoctrineMigrationsExtension.php | 8 ----- .../ContainerAwareMigrationFactory.php | 35 ------------------- .../DoctrineMigrationsExtensionTest.php | 28 --------------- .../Migrations/ContainerAwareMigration.php | 30 ---------------- 8 files changed, 5 insertions(+), 125 deletions(-) delete mode 100644 phpstan-baseline.neon delete mode 100644 src/MigrationsFactory/ContainerAwareMigrationFactory.php delete mode 100644 tests/Fixtures/Migrations/ContainerAwareMigration.php diff --git a/UPGRADE.md b/UPGRADE.md index 4b235e0..732640f 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -7,6 +7,11 @@ Type declarations have been added to all method signatures and properties. You might have to adjust your own code to abide by the new type declarations. +## BC break: Removed support for container-aware migrations + +* Migrations that implement `ContainerAwareInterface` will no longer have the container injected automatically. +* The `ContainerAwareMigrationFactory` class has been removed. + ## From 2.x to 3.0.0 - The configuration for the migration namespace and directory changed as follows: diff --git a/config/services.xml b/config/services.xml index cb97871..da9b6ee 100644 --- a/config/services.xml +++ b/config/services.xml @@ -42,14 +42,6 @@ - - - - - diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index a81faa3..0000000 --- a/phpstan-baseline.neon +++ /dev/null @@ -1,11 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Call to method setContainer\\(\\) on an unknown class Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\.$#" - count: 1 - path: src/MigrationsFactory/ContainerAwareMigrationFactory.php - - - - message: "#^Class Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface not found\\.$#" - count: 2 - path: src/MigrationsFactory/ContainerAwareMigrationFactory.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ab98412..738e0ec 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,12 +5,7 @@ parameters: - src - tests - excludePaths: - # That file contains an error that cannot be ignored - - tests/Fixtures/Migrations/ContainerAwareMigration.php - includes: - - phpstan-baseline.neon - vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon diff --git a/src/DependencyInjection/DoctrineMigrationsExtension.php b/src/DependencyInjection/DoctrineMigrationsExtension.php index c06e17a..51e75a6 100644 --- a/src/DependencyInjection/DoctrineMigrationsExtension.php +++ b/src/DependencyInjection/DoctrineMigrationsExtension.php @@ -13,7 +13,6 @@ use RuntimeException; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -24,7 +23,6 @@ use function assert; use function explode; use function implode; -use function interface_exists; use function is_array; use function sprintf; use function strlen; @@ -128,12 +126,6 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter('doctrine.migrations.preferred_em', $config['em']); $container->setParameter('doctrine.migrations.preferred_connection', $config['connection']); - - if (interface_exists(ContainerAwareInterface::class)) { - return; - } - - $container->removeDefinition('doctrine.migrations.container_aware_migrations_factory'); } private function checkIfBundleRelativePath(string $path, ContainerBuilder $container): string diff --git a/src/MigrationsFactory/ContainerAwareMigrationFactory.php b/src/MigrationsFactory/ContainerAwareMigrationFactory.php deleted file mode 100644 index 39b849c..0000000 --- a/src/MigrationsFactory/ContainerAwareMigrationFactory.php +++ /dev/null @@ -1,35 +0,0 @@ -= 7 */ -class ContainerAwareMigrationFactory implements MigrationFactory -{ - public function __construct( - private MigrationFactory $migrationFactory, - private ContainerInterface $container, - ) { - } - - public function createVersion(string $migrationClassName): AbstractMigration - { - $migration = $this->migrationFactory->createVersion($migrationClassName); - - if ($migration instanceof ContainerAwareInterface) { - trigger_deprecation('doctrine/doctrine-migrations-bundle', '3.3', 'Migration "%s" implements "%s" to gain access to the application\'s service container. This method is deprecated and won\'t work with Symfony 7.', $migrationClassName, ContainerAwareInterface::class); - - $migration->setContainer($this->container); - } - - return $migration; - } -} diff --git a/tests/DependencyInjection/DoctrineMigrationsExtensionTest.php b/tests/DependencyInjection/DoctrineMigrationsExtensionTest.php index 985a2e4..3a9af4c 100644 --- a/tests/DependencyInjection/DoctrineMigrationsExtensionTest.php +++ b/tests/DependencyInjection/DoctrineMigrationsExtensionTest.php @@ -11,7 +11,6 @@ use Doctrine\Bundle\DoctrineBundle\Registry; use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension; use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; -use Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\Migrations\ContainerAwareMigration; use Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\TestBundle\TestBundle; use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\DependencyFactory; @@ -28,7 +27,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; @@ -37,7 +35,6 @@ use Symfony\Component\VarExporter\LazyGhostTrait; use function assert; -use function interface_exists; use function sys_get_temp_dir; use function trait_exists; @@ -177,31 +174,6 @@ public function compare(Version $a, Version $b): int self::assertSame($sorter, $di->getVersionComparator()); } - /** @group legacy */ - public function testContainerAwareMigrations(): void - { - if (! interface_exists(ContainerAwareInterface::class)) { - self::markTestSkipped('This test requires Symfony < 7'); - } - - $config = [ - 'migrations_paths' => ['DoctrineMigrationsTest' => 'a'], - ]; - $container = $this->getContainer($config); - - $container->compile(); - - $di = $container->get('doctrine.migrations.dependency_factory'); - self::assertInstanceOf(DependencyFactory::class, $di); - - $this->expectDeprecation('Since doctrine/doctrine-migrations-bundle 3.3: Migration "Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\Migrations\ContainerAwareMigration" implements "Symfony\Component\DependencyInjection\ContainerAwareInterface" to gain access to the application\'s service container. This method is deprecated and won\'t work with Symfony 7.'); - - $migration = $di->getMigrationFactory()->createVersion(ContainerAwareMigration::class); - - self::assertInstanceOf(ContainerAwareMigration::class, $migration); - self::assertSame($container, $migration->getContainer()); - } - public function testServicesAreLazy(): void { $config = [ diff --git a/tests/Fixtures/Migrations/ContainerAwareMigration.php b/tests/Fixtures/Migrations/ContainerAwareMigration.php deleted file mode 100644 index 755ecb5..0000000 --- a/tests/Fixtures/Migrations/ContainerAwareMigration.php +++ /dev/null @@ -1,30 +0,0 @@ -container = $container; - } - - public function getContainer(): ContainerInterface|null - { - return $this->container; - } -}