setAliases(['generate']) ->setDescription('Generate a blank migration class.') ->addOption( 'namespace', null, InputOption::VALUE_REQUIRED, 'The namespace to use for the migration (must be in the list of configured namespaces)' ) ->setHelp(<<%command.name% command generates a blank migration class: %command.full_name% EOT ); parent::configure(); } protected function execute(InputInterface $input, OutputInterface $output): int { $configuration = $this->getDependencyFactory()->getConfiguration(); $migrationGenerator = $this->getDependencyFactory()->getMigrationGenerator(); $namespace = $input->getOption('namespace'); if ($namespace === '') { $namespace = null; } $dirs = $configuration->getMigrationDirectories(); if ($namespace === null) { $namespace = key($dirs); } elseif (! isset($dirs[$namespace])) { throw new Exception(sprintf('Path not defined for the namespace %s', $namespace)); } assert(is_string($namespace)); $fqcn = $this->getDependencyFactory()->getClassNameGenerator()->generateClassName($namespace); $path = $migrationGenerator->generateMigration($fqcn); $this->io->text([ sprintf('Generated new migration class to "%s"', $path), '', sprintf( 'To run just this migration for testing purposes, you can use migrations:execute --up \'%s\'', $fqcn ), '', sprintf( 'To revert the migration you can use migrations:execute --down \'%s\'', $fqcn ), '', ]); return 0; } }