/** * @param string $path * @return MigrationInterface */ private function loadMigrationClass($path) { $class = Migration::classFromFilename($path); if (!class_exists($class, false)) { if (!file_exists($path)) { throw new \RuntimeException("Migration file {$path} was not found"); } require $path; if (!class_exists($class, false)) { throw new \RuntimeException("Migration file {$path} doesn't define a class named {$class}"); } } return $this->injector->make($class); }
/** * Print a list of all migrations of a specific module, along with their current status * * @param string $moduleName [optional] The target module (vendor-name/package-name syntax). * If not specified, the user will be prompted for it * @param array $options * @option $format|f The output format. Allowed values: 'json|text'. If not specified, text is output. * @return int Status code */ function migrateStatus($moduleName = null, $options = ['format|f' => 'text']) { $this->setupModule($moduleName); $migrations = $this->migrationsAPI->status(); $formattedMig = map($migrations, function ($mig) { return [$mig[Migration::date], Migration::toDateStr($mig[Migration::date]), $mig[Migration::name], $mig[Migration::status]]; }); switch (get($options, 'format', 'text')) { case 'json': $this->io->writeln(json_encode(array_values($migrations), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); break; case 'text': if ($formattedMig) { $this->io->table(['Version', 'Date', 'Name', 'Status'], $formattedMig, [15, 20, 40, 8]); } else { $this->io->cancel('The module has no migrations'); } break; default: $this->io->error('Invalid format'); } return 0; }