. */ declare(strict_types=1); namespace App\Doctrine\Migration; use App\Services\UserSystem\PermissionPresetsHelper; use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\Version\MigrationFactory; use Symfony\Component\DependencyInjection\Attribute\AsDecorator; use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; use Symfony\Component\DependencyInjection\ContainerInterface; #[AsDecorator("doctrine.migrations.migrations_factory")] class ContainerAwareMigrationFactory implements MigrationFactory { public function __construct(private readonly MigrationFactory $decorated, //List all services that should be available in migrations here #[AutowireLocator([ PermissionPresetsHelper::class ])] private readonly ContainerInterface $container) { } public function createVersion(string $migrationClassName): AbstractMigration { $migration = $this->decorated->createVersion($migrationClassName); if ($migration instanceof ContainerAwareMigrationInterface) { $migration->setContainer($this->container); } return $migration; } }