PhpFile.php 954 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Migrations\Configuration\Migration;
  4. use Doctrine\Migrations\Configuration\Configuration;
  5. use Doctrine\Migrations\Configuration\Exception\FileNotFound;
  6. use function assert;
  7. use function file_exists;
  8. use function is_array;
  9. final class PhpFile extends ConfigurationFile
  10. {
  11. public function getConfiguration(): Configuration
  12. {
  13. if (! file_exists($this->file)) {
  14. throw FileNotFound::new($this->file);
  15. }
  16. $config = require $this->file;
  17. if ($config instanceof Configuration) {
  18. return $config;
  19. }
  20. assert(is_array($config));
  21. if (isset($config['migrations_paths'])) {
  22. $config['migrations_paths'] = $this->getDirectoriesRelativeToFile(
  23. $config['migrations_paths'],
  24. $this->file
  25. );
  26. }
  27. return (new ConfigurationArray($config))->getConfiguration();
  28. }
  29. }