X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FCacheContextCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FCacheContextCommand.php;h=3d29bdf6d6c207ec213cf57eb2d3e7c0e9b27899;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=474082006086f046e560fdf67c912a8d88d7de0e;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/vendor/drupal/console/src/Command/Generate/CacheContextCommand.php b/vendor/drupal/console/src/Command/Generate/CacheContextCommand.php index 474082006..3d29bdf6d 100644 --- a/vendor/drupal/console/src/Command/Generate/CacheContextCommand.php +++ b/vendor/drupal/console/src/Command/Generate/CacheContextCommand.php @@ -7,154 +7,164 @@ 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\CacheContextGenerator; use Drupal\Console\Command\Shared\ConfirmationTrait; -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\ChainQueue; use Drupal\Console\Extension\Manager; use Drupal\Console\Command\Shared\ServicesTrait; use Drupal\Console\Core\Utils\StringConverter; -class CacheContextCommand extends Command +class CacheContextCommand extends ContainerAwareCommand { use ModuleTrait; use ConfirmationTrait; - use ContainerAwareCommandTrait; use ServicesTrait; /** - * @var CacheContextGenerator - */ + * @var CacheContextGenerator + */ protected $generator; /** - * @var ChainQueue - */ + * @var ChainQueue + */ protected $chainQueue; /** - * @var Manager - */ + * @var Manager + */ protected $extensionManager; /** - * @var StringConverter - */ + * @var StringConverter + */ protected $stringConverter; /** - * CacheContextCommand constructor. - * - * @param CacheContextGenerator $generator - * @param ChainQueue $chainQueue - * @param Manager $extensionManager - * @param StringConverter $stringConverter - */ + * @var Validator + */ + protected $validator; + + /** + * CacheContextCommand constructor. + * + * @param CacheContextGenerator $generator + * @param ChainQueue $chainQueue + * @param Manager $extensionManager + * @param StringConverter $stringConverter + * @param Validator $validator + */ public function __construct( CacheContextGenerator $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(); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ protected function configure() { $this ->setName('generate:cache:context') ->setDescription($this->trans('commands.generate.cache.context.description')) ->setHelp($this->trans('commands.generate.cache.context.description')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) ->addOption( - 'cache_context', + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'cache-context', null, InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.cache.context.questions.name') + $this->trans('commands.generate.cache.context.options.name') ) ->addOption( 'class', null, InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.cache.context.questions.class') + $this->trans('commands.generate.cache.context.options.class') ) ->addOption( 'services', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.common.options.services') - ); + )->setAliases(['gcc']); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ 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'); - $cache_context = $input->getOption('cache_context'); - $class = $input->getOption('class'); + $cache_context = $input->getOption('cache-context'); + $class = $this->validator->validateClassName($input->getOption('class')); $services = $input->getOption('services'); // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices $buildServices = $this->buildServices($services); - $this->generator->generate($module, $cache_context, $class, $buildServices); + $this->generator->generate([ + 'module' => $module, + 'cache_context' => $cache_context, + 'class' => $class, + 'services' => $buildServices, + ]); $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ 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(); // --cache_context option - $cache_context = $input->getOption('cache_context'); + $cache_context = $input->getOption('cache-context'); if (!$cache_context) { - $cache_context = $io->ask( + $cache_context = $this->getIo()->ask( $this->trans('commands.generate.cache.context.questions.name'), sprintf('%s', $module) ); - $input->setOption('cache_context', $cache_context); + $input->setOption('cache-context', $cache_context); } // --class option $class = $input->getOption('class'); if (!$class) { - $class = $io->ask( + $class = $this->getIo()->ask( $this->trans('commands.generate.cache.context.questions.class'), - 'DefaultCacheContext' + 'DefaultCacheContext', + function ($class) { + return $this->validator->validateClassName($class); + } ); $input->setOption('class', $class); } @@ -163,7 +173,7 @@ class CacheContextCommand 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); } }