vendor/doctrine/doctrine-migrations-bundle/Collector/MigrationsCollector.php line 47

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Bundle\MigrationsBundle\Collector;
  4. use Doctrine\DBAL\Exception;
  5. use Doctrine\Migrations\DependencyFactory;
  6. use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\DataCollector\DataCollector;
  10. class MigrationsCollector extends DataCollector
  11. {
  12.     /** @var DependencyFactory */
  13.     private $dependencyFactory;
  14.     /** @var MigrationsFlattener */
  15.     private $flattener;
  16.     public function __construct(DependencyFactory $dependencyFactoryMigrationsFlattener $migrationsFlattener)
  17.     {
  18.         $this->dependencyFactory $dependencyFactory;
  19.         $this->flattener $migrationsFlattener;
  20.     }
  21.     public function collect(Request $requestResponse $response\Throwable $exception null)
  22.     {
  23.         if (!empty($this->data)) {
  24.             return;
  25.         }
  26.         $metadataStorage $this->dependencyFactory->getMetadataStorage();
  27.         $planCalculator $this->dependencyFactory->getMigrationPlanCalculator();
  28.         try {
  29.             $executedMigrations $metadataStorage->getExecutedMigrations();
  30.         } catch (Exception $dbalException) {
  31.             $this->dependencyFactory->getLogger()->error(
  32.                 'error while trying to collect executed migrations',
  33.                 ['exception' => $dbalException]
  34.             );
  35.             return;
  36.         }
  37.         $availableMigrations $planCalculator->getMigrations();
  38.         $this->data['available_migrations_count'] = count($availableMigrations);
  39.         $unavailableMigrations $executedMigrations->unavailableSubset($availableMigrations);
  40.         $this->data['unavailable_migrations_count'] = count($unavailableMigrations);
  41.         $newMigrations $availableMigrations->newSubset($executedMigrations);
  42.         $this->data['new_migrations'] = $this->flattener->flattenAvailableMigrations($newMigrations);
  43.         $this->data['executed_migrations'] = $this->flattener->flattenExecutedMigrations($executedMigrations$availableMigrations);
  44.         $this->data['storage'] = get_class($metadataStorage);
  45.         $configuration $this->dependencyFactory->getConfiguration();
  46.         $storage $configuration->getMetadataStorageConfiguration();
  47.         if ($storage instanceof TableMetadataStorageConfiguration) {
  48.             $this->data['table'] = $storage->getTableName();
  49.             $this->data['column'] = $storage->getVersionColumnName();
  50.         }
  51.         $connection $this->dependencyFactory->getConnection();
  52.         $this->data['driver'] = get_class($connection->getDriver());
  53.         $this->data['name'] = $connection->getDatabase();
  54.         $this->data['namespaces'] = $configuration->getMigrationDirectories();
  55.     }
  56.     /**
  57.      * @return string
  58.      */
  59.     public function getName()
  60.     {
  61.         return 'doctrine_migrations';
  62.     }
  63.     public function getData()
  64.     {
  65.         return $this->data;
  66.     }
  67.     public function reset()
  68.     {
  69.         $this->data = [];
  70.     }
  71. }