Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / PluginSkeletonCommand.php
index f1fb5ee18cb8e033a41a051ea9a8e83b05f84519..30f84b631d0b53339cbb6cb55a37bfcac5f35f6c 100644 (file)
@@ -11,13 +11,11 @@ use Drupal\Console\Generator\PluginSkeletonGenerator;
 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\Command\Shared\ModuleTrait;
 use Drupal\Console\Command\Shared\ConfirmationTrait;
 use Drupal\Console\Command\Shared\ServicesTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
 use Drupal\Console\Extension\Manager;
-use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
 use Drupal\Console\Core\Utils\StringConverter;
 use Drupal\Console\Core\Utils\ChainQueue;
 use Drupal\Console\Utils\Validator;
@@ -27,21 +25,20 @@ use Drupal\Console\Utils\Validator;
  *
  * @package Drupal\Console\Command\Generate
  */
-class PluginSkeletonCommand extends Command
+class PluginSkeletonCommand extends ContainerAwareCommand
 {
     use ModuleTrait;
     use ConfirmationTrait;
     use ServicesTrait;
-    use ContainerAwareCommandTrait;
 
     /**
- * @var Manager
-*/
    * @var Manager
+     */
     protected $extensionManager;
 
     /**
- * @var PluginSkeletonGenerator
-*/
    * @var PluginSkeletonGenerator
+     */
     protected $generator;
 
     /**
@@ -50,8 +47,8 @@ class PluginSkeletonCommand extends Command
     protected $stringConverter;
 
     /**
- * @var Validator
-*/
    * @var Validator
+     */
     protected $validator;
 
     /**
@@ -111,32 +108,28 @@ class PluginSkeletonCommand extends Command
                 'plugin-id',
                 null,
                 InputOption::VALUE_REQUIRED,
-                $this->trans('commands.generate.plugin.options.plugin-id')
+                $this->trans('commands.generate.plugin.skeleton.options.plugin')
             )
             ->addOption(
                 'class',
                 null,
                 InputOption::VALUE_OPTIONAL,
-                $this->trans('commands.generate.plugin.block.options.class')
+                $this->trans('commands.generate.plugin.skeleton.options.class')
             )
             ->addOption(
                 'services',
                 null,
                 InputOption::VALUE_OPTIONAL| InputOption::VALUE_IS_ARRAY,
                 $this->trans('commands.common.options.services')
-            );
+            )->setAliases(['gps']);
     }
-
     /**
      * {@inheritdoc}
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-        $plugins = $this->getPlugins();
-
-        // @see use Drupal\Console\Command\ConfirmationTrait::confirmGeneration
-        if (!$this->confirmGeneration($io)) {
+        // @see use Drupal\Console\Command\ConfirmationTrait::confirmOperation
+        if (!$this->confirmOperation()) {
             return 1;
         }
 
@@ -145,6 +138,8 @@ class PluginSkeletonCommand extends Command
         $pluginId = $input->getOption('plugin-id');
         $plugin = ucfirst($this->stringConverter->underscoreToCamelCase($pluginId));
 
+        $plugins = $this->getPlugins();
+
         // Confirm that plugin.manager is available
         if (!$this->validator->validatePluginManagerServiceExist($pluginId, $plugins)) {
             throw new \Exception(
@@ -156,7 +151,7 @@ class PluginSkeletonCommand extends Command
         }
 
         if (array_key_exists($pluginId, $this->pluginGeneratorsImplemented)) {
-            $io->warning(
+            $this->getIo()->warning(
                 sprintf(
                     $this->trans('commands.generate.plugin.skeleton.messages.plugin-generator-implemented'),
                     $pluginId,
@@ -165,14 +160,21 @@ class PluginSkeletonCommand extends Command
             );
         }
 
-        $className = $input->getOption('class');
+        $className = $this->validator->validateClassName($input->getOption('class'));
         $services = $input->getOption('services');
 
         // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices
         $buildServices = $this->buildServices($services);
         $pluginMetaData = $this->getPluginMetadata($pluginId);
 
-        $this->generator->generate($module, $pluginId, $plugin, $className, $pluginMetaData, $buildServices);
+        $this->generator->generate([
+            'module' => $module,
+            'plugin_id' => $pluginId,
+            'plugin' => $plugin,
+            'class_name' => $className,
+            'services' => $buildServices,
+            'plugin_metadata' => $pluginMetaData,
+        ]);
 
         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
 
@@ -181,19 +183,13 @@ class PluginSkeletonCommand extends Command
 
     protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
-        $module = $input->getOption('module');
-        if (!$module) {
-            // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
-            $module = $this->moduleQuestion($io);
-            $input->setOption('module', $module);
-        }
+        // --module option
+        $this->getModuleOption();
 
         $pluginId = $input->getOption('plugin-id');
         if (!$pluginId) {
             $plugins = $this->getPlugins();
-            $pluginId = $io->choiceNoList(
+            $pluginId = $this->getIo()->choiceNoList(
                 $this->trans('commands.generate.plugin.skeleton.questions.plugin'),
                 $plugins
             );
@@ -201,7 +197,7 @@ class PluginSkeletonCommand extends Command
         }
 
         if (array_key_exists($pluginId, $this->pluginGeneratorsImplemented)) {
-            $io->warning(
+            $this->getIo()->warning(
                 sprintf(
                     $this->trans('commands.generate.plugin.skeleton.messages.plugin-dont-exist'),
                     $pluginId,
@@ -213,7 +209,7 @@ class PluginSkeletonCommand extends Command
         // --class option
         $class = $input->getOption('class');
         if (!$class) {
-            $class = $io->ask(
+            $class = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.skeleton.options.class'),
                 sprintf('%s%s', 'Default', ucfirst($this->stringConverter->underscoreToCamelCase($pluginId))),
                 function ($class) {
@@ -227,7 +223,7 @@ class PluginSkeletonCommand extends Command
         // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
         $services = $input->getOption('services');
         if (!$services) {
-            $services = $this->servicesQuestion($io);
+            $services = $this->servicesQuestion();
             $input->setOption('services', $services);
         }
     }