/** * Gets an array of the database migrations. * * @throws \InvalidArgumentException * @return AbstractMigration[] */ public function getMigrations() { if (null === $this->migrations) { $config = $this->getConfig(); $phpFiles = glob($config->getMigrationPath() . DIRECTORY_SEPARATOR . '*.php'); // filter the files to only get the ones that match our naming scheme $fileNames = array(); /** @var AbstractMigration[] $versions */ $versions = array(); foreach ($phpFiles as $filePath) { if (Util::isValidMigrationFileName(basename($filePath))) { $version = Util::getVersionFromFileName(basename($filePath)); if (isset($versions[$version])) { throw new \InvalidArgumentException(sprintf('Duplicate migration - "%s" has the same version as "%s"', $filePath, $versions[$version]->getVersion())); } // convert the filename to a class name $class = Util::mapFileNameToClassName(basename($filePath)); if (isset($fileNames[$class])) { throw new \InvalidArgumentException(sprintf('Migration "%s" has the same name as "%s"', basename($filePath), $fileNames[$class])); } $fileNames[$class] = basename($filePath); // load the migration file /** @noinspection PhpIncludeInspection */ require_once $filePath; if (!class_exists($class)) { throw new \InvalidArgumentException(sprintf('Could not find class "%s" in file "%s"', $class, $filePath)); } // instantiate it $migration = new $class($version); if (!$migration instanceof AbstractMigration) { throw new \InvalidArgumentException(sprintf('The class "%s" in file "%s" must extend \\Phinx\\Migration\\AbstractMigration', $class, $filePath)); } $migration->setOutput($this->getOutput()); $versions[$version] = $migration; } } ksort($versions); $this->setMigrations($versions); } return $this->migrations; }
/** * Gets an array of the database migrations. * * @throws \InvalidArgumentException * @return AbstractMigration[] */ public function getMigrations() { if (empty($this->_migrations)) { $fileNames = []; $versions = []; $phpFiles = glob($this->_config->getMigrationPath() . DIRECTORY_SEPARATOR . '*.php'); foreach ($phpFiles as $filePath) { if (Util::isValidMigrationFileName(basename($filePath))) { $version = Util::getVersionFromFileName(basename($filePath)); if (isset($versions[$version])) { throw new \InvalidArgumentException(__d('union_dev', 'Duplicate migration - "%s" has the same version as "%s"', $filePath, $versions[$version]->getVersion())); } // Convert the filename to a class name. $class = Util::mapFileNameToClassName(basename($filePath)); if (isset($fileNames[$class])) { throw new \InvalidArgumentException(__d('union_dev', 'Migration "%s" has the same name as "%s"', basename($filePath), $fileNames[$class])); } $fileNames[$class] = basename($filePath); // Load the migration file. /** @noinspection PhpIncludeInspection */ require_once $filePath; if (!class_exists($class)) { throw new \InvalidArgumentException(__d('union_dev', 'Could not find class "%s" in file "%s"', $class, $filePath)); } // Instantiate migration class. $migration = new $class($version); if (!$migration instanceof AbstractMigration) { throw new \InvalidArgumentException(__d('union_dev', 'The class "%s" in file "%s" must extend \\Phinx\\Migration\\AbstractMigration', $class, $filePath)); } $versions[$version] = $migration; } } ksort($versions); $this->_migrations = $versions; } return $this->_migrations; }