Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / PluginMigrateProcessCommand.php
index 20ba70a60a939542b9302c3aa9ce1266b3c4cd80..8a1585b5690d08db38fb883c443a9b2ca78e7a31 100644 (file)
@@ -7,24 +7,22 @@
 
 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 Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\ContainerAwareCommand;
 use Drupal\Console\Generator\PluginMigrateProcessGenerator;
 use Drupal\Console\Command\Shared\ModuleTrait;
 use Drupal\Console\Command\Shared\ConfirmationTrait;
-use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
 use Drupal\Console\Extension\Manager;
 use Drupal\Console\Core\Utils\StringConverter;
-use Drupal\Console\Core\Style\DrupalStyle;
 use Drupal\Console\Core\Utils\ChainQueue;
 
-class PluginMigrateProcessCommand extends Command
+class PluginMigrateProcessCommand extends ContainerAwareCommand
 {
     use ModuleTrait;
     use ConfirmationTrait;
-    use ContainerAwareCommandTrait;
 
     /**
      * @var PluginMigrateProcessGenerator
@@ -46,6 +44,11 @@ class PluginMigrateProcessCommand extends Command
      */
     protected $stringConverter;
 
+    /**
+     * @var Validator
+     */
+    protected $validator;
+
     /**
      * PluginBlockCommand constructor.
      *
@@ -53,17 +56,20 @@ class PluginMigrateProcessCommand extends Command
      * @param ChainQueue                    $chainQueue
      * @param Manager                       $extensionManager
      * @param StringConverter               $stringConverter
+     * @param Validator                     $validator
      */
     public function __construct(
         PluginMigrateProcessGenerator $generator,
         ChainQueue $chainQueue,
         Manager $extensionManager,
-        StringConverter $stringConverter
+        StringConverter $stringConverter,
+        Validator $validator
     ) {
         $this->generator = $generator;
         $this->chainQueue = $chainQueue;
         $this->extensionManager = $extensionManager;
         $this->stringConverter = $stringConverter;
+        $this->validator = $validator;
         parent::__construct();
     }
 
@@ -73,7 +79,12 @@ class PluginMigrateProcessCommand extends Command
             ->setName('generate:plugin:migrate:process')
             ->setDescription($this->trans('commands.generate.plugin.migrate.process.description'))
             ->setHelp($this->trans('commands.generate.plugin.migrate.process.help'))
-            ->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(
                 'class',
                 null,
@@ -85,7 +96,7 @@ class PluginMigrateProcessCommand extends Command
                 null,
                 InputOption::VALUE_OPTIONAL,
                 $this->trans('commands.generate.plugin.migrate.process.options.plugin-id')
-            );
+            )->setAliases(['gpmp']);
     }
 
     /**
@@ -93,18 +104,20 @@ class PluginMigrateProcessCommand 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');
-        $class_name = $input->getOption('class');
+        $class_name = $this->validator->validateClassName($input->getOption('class'));
         $plugin_id = $input->getOption('plugin-id');
 
-        $this->generator->generate($module, $class_name, $plugin_id);
+        $this->generator->generate([
+          'module' => $module,
+          'class_name' => $class_name,
+          'plugin_id' => $plugin_id,
+        ]);
 
         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
     }
@@ -114,22 +127,18 @@ class PluginMigrateProcessCommand extends Command
      */
     protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         // 'module-name' 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();
 
         // 'class-name' option
         $class = $input->getOption('class');
         if (!$class) {
-            $class = $io->ask(
+            $class = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.migrate.process.questions.class'),
-                ucfirst($this->stringConverter->underscoreToCamelCase($module))
+                ucfirst($this->stringConverter->underscoreToCamelCase($module)),
+                function ($class) {
+                    return $this->validator->validateClassName($class);
+                }
             );
             $input->setOption('class', $class);
         }
@@ -137,7 +146,7 @@ class PluginMigrateProcessCommand extends Command
         // 'plugin-id' option.
         $pluginId = $input->getOption('plugin-id');
         if (!$pluginId) {
-            $pluginId = $io->ask(
+            $pluginId = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.migrate.source.questions.plugin-id'),
                 $this->stringConverter->camelCaseToUnderscore($class)
             );