ContainerAwareMigrationFactory.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Bundle\MigrationsBundle\MigrationsFactory;
  4. use Doctrine\Migrations\AbstractMigration;
  5. use Doctrine\Migrations\Version\MigrationFactory;
  6. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. class ContainerAwareMigrationFactory implements MigrationFactory
  9. {
  10. /**
  11. * @var ContainerInterface
  12. */
  13. private $container;
  14. /**
  15. * @var MigrationFactory
  16. */
  17. private $migrationFactory;
  18. public function __construct(MigrationFactory $migrationFactory, ContainerInterface $container)
  19. {
  20. $this->container = $container;
  21. $this->migrationFactory = $migrationFactory;
  22. }
  23. public function createVersion(string $migrationClassName): AbstractMigration
  24. {
  25. $migration = $this->migrationFactory->createVersion($migrationClassName);
  26. if ($migration instanceof ContainerAwareInterface) {
  27. $migration->setContainer($this->container);
  28. }
  29. return $migration;
  30. }
  31. }