Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / EventSubscriberCommand.php
index 556e9bb20f489e609ff5609e1b1b1dea448212d7..ec62750b0488b2133c90590936466cfc2bc0858f 100644 (file)
@@ -7,6 +7,7 @@
 
 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;
@@ -15,21 +16,18 @@ use Drupal\Console\Command\Shared\ModuleTrait;
 use Drupal\Console\Generator\EventSubscriberGenerator;
 use Drupal\Console\Command\Shared\ConfirmationTrait;
 use Drupal\Console\Command\Shared\EventsTrait;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Style\DrupalStyle;
-use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
+use Drupal\Console\Core\Command\ContainerAwareCommand;
 use Drupal\Console\Core\Utils\StringConverter;
 use Drupal\Console\Extension\Manager;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Drupal\Console\Core\Utils\ChainQueue;
 
-class EventSubscriberCommand extends Command
+class EventSubscriberCommand extends ContainerAwareCommand
 {
     use EventsTrait;
     use ServicesTrait;
     use ModuleTrait;
     use ConfirmationTrait;
-    use ContainerAwareCommandTrait;
 
     /**
      * @var Manager
@@ -46,6 +44,11 @@ class EventSubscriberCommand extends Command
      */
     protected $stringConverter;
 
+    /**
+     * @var Validator
+     */
+    protected $validator;
+
     /**
      * @var EventDispatcherInterface
      */
@@ -62,6 +65,7 @@ class EventSubscriberCommand extends Command
      * @param Manager                  $extensionManager
      * @param EventSubscriberGenerator $generator
      * @param StringConverter          $stringConverter
+     * @param Validator                $validator
      * @param EventDispatcherInterface $eventDispatcher
      * @param ChainQueue               $chainQueue
      */
@@ -69,12 +73,14 @@ class EventSubscriberCommand extends Command
         Manager $extensionManager,
         EventSubscriberGenerator $generator,
         StringConverter $stringConverter,
+        Validator $validator,
         EventDispatcherInterface $eventDispatcher,
         ChainQueue $chainQueue
     ) {
         $this->extensionManager = $extensionManager;
         $this->generator = $generator;
         $this->stringConverter = $stringConverter;
+        $this->validator = $validator;
         $this->eventDispatcher = $eventDispatcher;
         $this->chainQueue = $chainQueue;
         parent::__construct();
@@ -89,18 +95,23 @@ class EventSubscriberCommand extends Command
             ->setName('generate:event:subscriber')
             ->setDescription($this->trans('commands.generate.event.subscriber.description'))
             ->setHelp($this->trans('commands.generate.event.subscriber.description'))
-            ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
+            ->addOption(
+                'module',
+                null,
+                InputOption::VALUE_REQUIRED,
+                $this->trans('commands.common.options.module')
+            )
             ->addOption(
                 'name',
                 null,
                 InputOption::VALUE_OPTIONAL,
-                $this->trans('commands.generate.service.options.name')
+                $this->trans('commands.generate.event.subscriber.options.name')
             )
             ->addOption(
                 'class',
                 null,
                 InputOption::VALUE_OPTIONAL,
-                $this->trans('commands.generate.service.options.class')
+                $this->trans('commands.generate.event.subscriber.options.class')
             )
             ->addOption(
                 'events',
@@ -113,7 +124,8 @@ class EventSubscriberCommand extends Command
                 null,
                 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
                 $this->trans('commands.common.options.services')
-            );
+            )
+            ->setAliases(['ges']);
     }
 
     /**
@@ -121,23 +133,27 @@ class EventSubscriberCommand extends Command
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
-        // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
-        if (!$this->confirmGeneration($io)) {
+        // @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'));
         $events = $input->getOption('events');
         $services = $input->getOption('services');
 
         // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices
         $buildServices = $this->buildServices($services);
 
-        $this->generator->generate($module, $name, $class, $events, $buildServices);
+        $this->generator->generate([
+            'module' => $module,
+            'name' => $name,
+            'class' => $class,
+            'events' => $events,
+            'services' => $buildServices,
+        ]);
 
         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
     }
@@ -147,20 +163,13 @@ class EventSubscriberCommand extends Command
      */
     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();
 
         // --service-name option
         $name = $input->getOption('name');
         if (!$name) {
-            $name = $io->ask(
+            $name = $this->getIo()->ask(
                 $this->trans('commands.generate.service.questions.service-name'),
                 sprintf('%s.default', $module)
             );
@@ -170,9 +179,12 @@ class EventSubscriberCommand extends Command
         // --class option
         $class = $input->getOption('class');
         if (!$class) {
-            $class = $io->ask(
+            $class = $this->getIo()->ask(
                 $this->trans('commands.generate.event.subscriber.questions.class'),
-                'DefaultSubscriber'
+                'DefaultSubscriber',
+                function ($class) {
+                    return $this->validator->validateClassName($class);
+                }
             );
             $input->setOption('class', $class);
         }
@@ -181,7 +193,7 @@ class EventSubscriberCommand extends Command
         $events = $input->getOption('events');
         if (!$events) {
             // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
-            $events = $this->eventsQuestion($io);
+            $events = $this->eventsQuestion();
             $input->setOption('events', $events);
         }
 
@@ -189,7 +201,7 @@ class EventSubscriberCommand extends Command
         $services = $input->getOption('services');
         if (!$services) {
             // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
-            $services = $this->servicesQuestion($io);
+            $services = $this->servicesQuestion();
             $input->setOption('services', $services);
         }
     }