Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / BreakPointCommand.php
index bb53df8ef7c7c94c52717b573aeef5d88fec617e..0f0c2fa5491dfb514b1ea91cade9560e0d0de959 100644 (file)
@@ -7,28 +7,27 @@
 
 namespace Drupal\Console\Command\Generate;
 
-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\Core\Extension\ThemeHandler;
-use Drupal\Console\Command\Shared\ThemeRegionTrait;
-use Drupal\Console\Command\Shared\ThemeBreakpointTrait;
+use Drupal\Console\Command\Shared\ArrayInputTrait;
 use Drupal\Console\Command\Shared\ConfirmationTrait;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
-use Drupal\Console\Utils\Validator;
+use Drupal\Console\Command\Shared\ThemeBreakpointTrait;
+use Drupal\Console\Core\Command\Command;
 use Drupal\Console\Core\Utils\StringConverter;
 use Drupal\Console\Generator\BreakPointGenerator;
+use Drupal\Console\Utils\Validator;
+use Drupal\Core\Extension\ThemeHandler;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
 
 /**
+ * Class BreakPointCommand
  *
+ * @package Drupal\Console\Command\Generate
  */
 class BreakPointCommand extends Command
 {
-    use CommandTrait;
+    use ArrayInputTrait;
     use ConfirmationTrait;
-    use ThemeRegionTrait;
     use ThemeBreakpointTrait;
 
     /**
@@ -51,10 +50,9 @@ class BreakPointCommand extends Command
      */
     protected $themeHandler;
 
-
     /**
- * @var Validator
-*/
    * @var Validator
+     */
     protected $validator;
 
     /**
@@ -66,7 +64,7 @@ class BreakPointCommand extends Command
      * BreakPointCommand constructor.
      *
      * @param BreakPointGenerator $generator
-     * @param $appRoot
+     * @param string              $appRoot
      * @param ThemeHandler        $themeHandler
      * @param Validator           $validator
      * @param StringConverter     $stringConverter
@@ -104,9 +102,9 @@ class BreakPointCommand extends Command
             ->addOption(
                 'breakpoints',
                 null,
-                InputOption::VALUE_OPTIONAL,
+                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
                 $this->trans('commands.generate.breakpoint.options.breakpoints')
-            );
+            )->setAliases(['gb']);
     }
 
     /**
@@ -114,24 +112,27 @@ class BreakPointCommand 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;
         }
 
         $validators = $this->validator;
         // we must to ensure theme exist
         $machine_name = $validators->validateMachineName($input->getOption('theme'));
-        $theme_path = $drupal_root . $input->getOption('theme');
+        $theme = $input->getOption('theme');
         $breakpoints = $input->getOption('breakpoints');
+        $noInteraction = $input->getOption('no-interaction');
+        // Parse nested data.
+        if ($noInteraction) {
+            $breakpoints = $this->explodeInlineArray($breakpoints);
+        }
 
-        $this->generator->generate(
-            $theme_path,
-            $breakpoints,
-            $machine_name
-        );
+        $this->generator->generate([
+            'theme' => $theme,
+            'breakpoints' => $breakpoints,
+            'machine_name' => $machine_name,
+        ]);
 
         return 0;
     }
@@ -141,32 +142,31 @@ class BreakPointCommand extends Command
      */
     protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
-        $drupalRoot = $this->appRoot;
-
-        // --base-theme option.
-        $base_theme = $input->getOption('theme');
+        // --theme option.
+        $theme = $input->getOption('theme');
 
-        if (!$base_theme) {
+        if (!$theme) {
             $themeHandler = $this->themeHandler;
             $themes = $themeHandler->rebuildThemeData();
-            $themes['classy'] ='';
+            $themes['classy'] = '';
 
             uasort($themes, 'system_sort_modules_by_info_name');
 
-            $base_theme = $io->choiceNoList(
+            $theme = $this->getIo()->choiceNoList(
                 $this->trans('commands.generate.breakpoint.questions.theme'),
                 array_keys($themes)
             );
-            $input->setOption('theme', $base_theme);
+            $input->setOption('theme', $theme);
         }
 
         // --breakpoints option.
         $breakpoints = $input->getOption('breakpoints');
         if (!$breakpoints) {
-            $breakpoints = $this->breakpointQuestion($io);
+            $breakpoints = $this->breakpointQuestion();
             $input->setOption('breakpoints', $breakpoints);
+        } else {
+            $breakpoints = $this->explodeInlineArray($breakpoints);
         }
+        $input->setOption('breakpoints', $breakpoints);
     }
 }