namespace Drupal\Console\Command\Generate;
+use Drupal\Console\Utils\Validator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Generator\RouteSubscriberGenerator;
use Drupal\Console\Command\Shared\ConfirmationTrait;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Style\DrupalStyle;
+use Drupal\Console\Core\Command\Command;
use Drupal\Console\Extension\Manager;
use Drupal\Console\Core\Utils\ChainQueue;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
/**
* Class RouteSubscriberCommand
{
use ModuleTrait;
use ConfirmationTrait;
- use CommandTrait;
/**
- * @var Manager
-*/
+ * @var Manager
+ */
protected $extensionManager;
/**
- * @var RouteSubscriberGenerator
-*/
+ * @var RouteSubscriberGenerator
+ */
protected $generator;
/**
*/
protected $chainQueue;
+ /**
+ * @var Validator
+ */
+ protected $validator;
+
/**
* RouteSubscriberCommand constructor.
*
* @param Manager $extensionManager
* @param RouteSubscriberGenerator $generator
* @param ChainQueue $chainQueue
+ * @param Validator $validator
*/
public function __construct(
Manager $extensionManager,
RouteSubscriberGenerator $generator,
- ChainQueue $chainQueue
+ ChainQueue $chainQueue,
+ Validator $validator
) {
$this->extensionManager = $extensionManager;
$this->generator = $generator;
$this->chainQueue = $chainQueue;
+ $this->validator = $validator;
parent::__construct();
}
null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.routesubscriber.options.class')
- );
+ )->setAliases(['gr']);
}
/**
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $output = new DrupalStyle($input, $output);
-
- // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
- if (!$this->confirmGeneration($output)) {
+ // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
+ if (!$this->confirmOperation()) {
return 1;
}
$module = $input->getOption('module');
$name = $input->getOption('name');
- $class = $input->getOption('class');
+ $class = $this->validator->validateClassName($input->getOption('class'));
- $this->generator->generate($module, $name, $class);
+ $this->generator->generate([
+ 'module' => $module,
+ 'name' => $name,
+ 'class' => $class,
+ ]);
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
// --module option
- $module = $input->getOption('module');
- if (!$module) {
- // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
- $module = $this->moduleQuestion($io);
- $input->setOption('module', $module);
- }
+ $module = $this->getModuleOption();
// --name option
$name = $input->getOption('name');
if (!$name) {
- $name = $io->ask(
+ $name = $this->getIo()->ask(
$this->trans('commands.generate.routesubscriber.questions.name'),
$module.'.route_subscriber'
);
// --class option
$class = $input->getOption('class');
if (!$class) {
- $class = $io->ask(
+ $class = $this->getIo()->ask(
$this->trans('commands.generate.routesubscriber.questions.class'),
- 'RouteSubscriber'
+ 'RouteSubscriber',
+ function ($class) {
+ return $this->validator->validateClassName($class);
+ }
);
$input->setOption('class', $class);
}
}
-
- protected function createGenerator()
- {
- return new RouteSubscriberGenerator();
- }
}