Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / RouteSubscriberCommand.php
index 1085ea46941d6fba0056769843a7f92a662d482c..1ca175b11c1c6c3feaa935bfaf11cf2a1dd5a4c9 100644 (file)
@@ -7,17 +7,16 @@
 
 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
@@ -28,16 +27,15 @@ class RouteSubscriberCommand extends Command
 {
     use ModuleTrait;
     use ConfirmationTrait;
-    use CommandTrait;
 
     /**
- * @var Manager
-*/
    * @var Manager
+     */
     protected $extensionManager;
 
     /**
- * @var RouteSubscriberGenerator
-*/
    * @var RouteSubscriberGenerator
+     */
     protected $generator;
 
     /**
@@ -45,21 +43,29 @@ class RouteSubscriberCommand extends Command
      */
     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();
     }
 
@@ -89,7 +95,7 @@ class RouteSubscriberCommand extends Command
                 null,
                 InputOption::VALUE_REQUIRED,
                 $this->trans('commands.generate.routesubscriber.options.class')
-            );
+            )->setAliases(['gr']);
     }
 
     /**
@@ -97,18 +103,20 @@ class RouteSubscriberCommand extends Command
      */
     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']);
 
@@ -120,20 +128,13 @@ class RouteSubscriberCommand 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();
 
         // --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'
             );
@@ -143,16 +144,14 @@ class RouteSubscriberCommand extends Command
         // --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();
-    }
 }