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

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.     /**
  22.      * @return void
  23.      */
  24.     public function collect(Request $requestResponse $response\Throwable $exception null)
  25.     {
  26.         if (!empty($this->data)) {
  27.             return;
  28.         }
  29.         $metadataStorage $this->dependencyFactory->getMetadataStorage();
  30.         $planCalculator $this->dependencyFactory->getMigrationPlanCalculator();
  31.         try {
  32.             $executedMigrations $metadataStorage->getExecutedMigrations();
  33.         } catch (Exception $dbalException) {
  34.             $this->dependencyFactory->getLogger()->error(
  35.                 'error while trying to collect executed migrations',
  36.                 ['exception' => $dbalException]
  37.             );
  38.             return;
  39.         }
  40.         $availableMigrations $planCalculator->getMigrations();
  41.         $this->data['available_migrations_count'] = count($availableMigrations);
  42.         $unavailableMigrations $executedMigrations->unavailableSubset($availableMigrations);
  43.         $this->data['unavailable_migrations_count'] = count($unavailableMigrations);
  44.         $newMigrations $availableMigrations->newSubset($executedMigrations);
  45.         $this->data['new_migrations'] = $this->flattener->flattenAvailableMigrations($newMigrations);
  46.         $this->data['executed_migrations'] = $this->flattener->flattenExecutedMigrations($executedMigrations$availableMigrations);
  47.         $this->data['storage'] = get_class($metadataStorage);
  48.         $configuration $this->dependencyFactory->getConfiguration();
  49.         $storage $configuration->getMetadataStorageConfiguration();
  50.         if ($storage instanceof TableMetadataStorageConfiguration) {
  51.             $this->data['table'] = $storage->getTableName();
  52.             $this->data['column'] = $storage->getVersionColumnName();
  53.         }
  54.         $connection $this->dependencyFactory->getConnection();
  55.         $this->data['driver'] = get_class($connection->getDriver());
  56.         $this->data['name'] = $connection->getDatabase();
  57.         $this->data['namespaces'] = $configuration->getMigrationDirectories();
  58.     }
  59.     /**
  60.      * @return string
  61.      */
  62.     public function getName()
  63.     {
  64.         return 'doctrine_migrations';
  65.     }
  66.     public function getData()
  67.     {
  68.         return $this->data;
  69.     }
  70.     /**
  71.      * @return void
  72.      */
  73.     public function reset()
  74.     {
  75.         $this->data = [];
  76.     }
  77. }