5 * Contains \Drupal\Console\Command\Generate\RouteSubscriber.
8 namespace Drupal\Console\Command\Generate;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Command\Shared\ModuleTrait;
14 use Drupal\Console\Generator\RouteSubscriberGenerator;
15 use Drupal\Console\Command\Shared\ConfirmationTrait;
16 use Symfony\Component\Console\Command\Command;
17 use Drupal\Console\Core\Style\DrupalStyle;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Utils\ChainQueue;
20 use Drupal\Console\Core\Command\Shared\CommandTrait;
23 * Class RouteSubscriberCommand
25 * @package Drupal\Console\Command\Generate
27 class RouteSubscriberCommand extends Command
30 use ConfirmationTrait;
36 protected $extensionManager;
39 * @var RouteSubscriberGenerator
46 protected $chainQueue;
49 * RouteSubscriberCommand constructor.
51 * @param Manager $extensionManager
52 * @param RouteSubscriberGenerator $generator
53 * @param ChainQueue $chainQueue
55 public function __construct(
56 Manager $extensionManager,
57 RouteSubscriberGenerator $generator,
58 ChainQueue $chainQueue
60 $this->extensionManager = $extensionManager;
61 $this->generator = $generator;
62 $this->chainQueue = $chainQueue;
63 parent::__construct();
69 protected function configure()
72 ->setName('generate:routesubscriber')
73 ->setDescription($this->trans('commands.generate.routesubscriber.description'))
74 ->setHelp($this->trans('commands.generate.routesubscriber.description'))
78 InputOption::VALUE_REQUIRED,
79 $this->trans('commands.common.options.module')
84 InputOption::VALUE_REQUIRED,
85 $this->trans('commands.generate.routesubscriber.options.name')
90 InputOption::VALUE_REQUIRED,
91 $this->trans('commands.generate.routesubscriber.options.class')
98 protected function execute(InputInterface $input, OutputInterface $output)
100 $output = new DrupalStyle($input, $output);
102 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
103 if (!$this->confirmGeneration($output)) {
107 $module = $input->getOption('module');
108 $name = $input->getOption('name');
109 $class = $input->getOption('class');
111 $this->generator->generate($module, $name, $class);
113 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
121 protected function interact(InputInterface $input, OutputInterface $output)
123 $io = new DrupalStyle($input, $output);
126 $module = $input->getOption('module');
128 // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
129 $module = $this->moduleQuestion($io);
130 $input->setOption('module', $module);
134 $name = $input->getOption('name');
137 $this->trans('commands.generate.routesubscriber.questions.name'),
138 $module.'.route_subscriber'
140 $input->setOption('name', $name);
144 $class = $input->getOption('class');
147 $this->trans('commands.generate.routesubscriber.questions.class'),
150 $input->setOption('class', $class);
154 protected function createGenerator()
156 return new RouteSubscriberGenerator();