5 * Contains \Drupal\Console\Command\Generate\EventSubscriberCommand.
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\ServicesTrait;
14 use Drupal\Console\Command\Shared\ModuleTrait;
15 use Drupal\Console\Generator\EventSubscriberGenerator;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Command\Shared\EventsTrait;
18 use Symfony\Component\Console\Command\Command;
19 use Drupal\Console\Core\Style\DrupalStyle;
20 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
21 use Drupal\Console\Core\Utils\StringConverter;
22 use Drupal\Console\Extension\Manager;
23 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
24 use Drupal\Console\Core\Utils\ChainQueue;
26 class EventSubscriberCommand extends Command
31 use ConfirmationTrait;
32 use ContainerAwareCommandTrait;
37 protected $extensionManager;
40 * @var EventSubscriberGenerator
45 * @var StringConverter
47 protected $stringConverter;
50 * @var EventDispatcherInterface
52 protected $eventDispatcher;
57 protected $chainQueue;
60 * EventSubscriberCommand constructor.
62 * @param Manager $extensionManager
63 * @param EventSubscriberGenerator $generator
64 * @param StringConverter $stringConverter
65 * @param EventDispatcherInterface $eventDispatcher
66 * @param ChainQueue $chainQueue
68 public function __construct(
69 Manager $extensionManager,
70 EventSubscriberGenerator $generator,
71 StringConverter $stringConverter,
72 EventDispatcherInterface $eventDispatcher,
73 ChainQueue $chainQueue
75 $this->extensionManager = $extensionManager;
76 $this->generator = $generator;
77 $this->stringConverter = $stringConverter;
78 $this->eventDispatcher = $eventDispatcher;
79 $this->chainQueue = $chainQueue;
80 parent::__construct();
86 protected function configure()
89 ->setName('generate:event:subscriber')
90 ->setDescription($this->trans('commands.generate.event.subscriber.description'))
91 ->setHelp($this->trans('commands.generate.event.subscriber.description'))
92 ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
96 InputOption::VALUE_OPTIONAL,
97 $this->trans('commands.generate.service.options.name')
102 InputOption::VALUE_OPTIONAL,
103 $this->trans('commands.generate.service.options.class')
108 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
109 $this->trans('commands.common.options.events')
114 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
115 $this->trans('commands.common.options.services')
122 protected function execute(InputInterface $input, OutputInterface $output)
124 $io = new DrupalStyle($input, $output);
126 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
127 if (!$this->confirmGeneration($io)) {
131 $module = $input->getOption('module');
132 $name = $input->getOption('name');
133 $class = $input->getOption('class');
134 $events = $input->getOption('events');
135 $services = $input->getOption('services');
137 // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices
138 $buildServices = $this->buildServices($services);
140 $this->generator->generate($module, $name, $class, $events, $buildServices);
142 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
148 protected function interact(InputInterface $input, OutputInterface $output)
150 $io = new DrupalStyle($input, $output);
153 $module = $input->getOption('module');
155 // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
156 $module = $this->moduleQuestion($io);
157 $input->setOption('module', $module);
160 // --service-name option
161 $name = $input->getOption('name');
164 $this->trans('commands.generate.service.questions.service-name'),
165 sprintf('%s.default', $module)
167 $input->setOption('name', $name);
171 $class = $input->getOption('class');
174 $this->trans('commands.generate.event.subscriber.questions.class'),
177 $input->setOption('class', $class);
181 $events = $input->getOption('events');
183 // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
184 $events = $this->eventsQuestion($io);
185 $input->setOption('events', $events);
189 $services = $input->getOption('services');
191 // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
192 $services = $this->servicesQuestion($io);
193 $input->setOption('services', $services);