5 * Contains \Drupal\Console\Command\Generate\RouteSubscriber.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Utils\Validator;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Drupal\Console\Command\Shared\ModuleTrait;
15 use Drupal\Console\Generator\RouteSubscriberGenerator;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Core\Command\Command;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Utils\ChainQueue;
22 * Class RouteSubscriberCommand
24 * @package Drupal\Console\Command\Generate
26 class RouteSubscriberCommand extends Command
29 use ConfirmationTrait;
34 protected $extensionManager;
37 * @var RouteSubscriberGenerator
44 protected $chainQueue;
52 * RouteSubscriberCommand constructor.
54 * @param Manager $extensionManager
55 * @param RouteSubscriberGenerator $generator
56 * @param ChainQueue $chainQueue
57 * @param Validator $validator
59 public function __construct(
60 Manager $extensionManager,
61 RouteSubscriberGenerator $generator,
62 ChainQueue $chainQueue,
65 $this->extensionManager = $extensionManager;
66 $this->generator = $generator;
67 $this->chainQueue = $chainQueue;
68 $this->validator = $validator;
69 parent::__construct();
75 protected function configure()
78 ->setName('generate:routesubscriber')
79 ->setDescription($this->trans('commands.generate.routesubscriber.description'))
80 ->setHelp($this->trans('commands.generate.routesubscriber.description'))
84 InputOption::VALUE_REQUIRED,
85 $this->trans('commands.common.options.module')
90 InputOption::VALUE_REQUIRED,
91 $this->trans('commands.generate.routesubscriber.options.name')
96 InputOption::VALUE_REQUIRED,
97 $this->trans('commands.generate.routesubscriber.options.class')
98 )->setAliases(['gr']);
104 protected function execute(InputInterface $input, OutputInterface $output)
106 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
107 if (!$this->confirmOperation()) {
111 $module = $input->getOption('module');
112 $name = $input->getOption('name');
113 $class = $this->validator->validateClassName($input->getOption('class'));
115 $this->generator->generate([
121 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
129 protected function interact(InputInterface $input, OutputInterface $output)
132 $module = $this->getModuleOption();
135 $name = $input->getOption('name');
137 $name = $this->getIo()->ask(
138 $this->trans('commands.generate.routesubscriber.questions.name'),
139 $module.'.route_subscriber'
141 $input->setOption('name', $name);
145 $class = $input->getOption('class');
147 $class = $this->getIo()->ask(
148 $this->trans('commands.generate.routesubscriber.questions.class'),
151 return $this->validator->validateClassName($class);
154 $input->setOption('class', $class);