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

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