X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FTwigExtensionCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FTwigExtensionCommand.php;h=eb147859e80858cbd7efb235650e421e317c1ca4;hp=182f408b866d1441390c50fe5c783d4f74b87dc8;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/drupal/console/src/Command/Generate/TwigExtensionCommand.php b/vendor/drupal/console/src/Command/Generate/TwigExtensionCommand.php index 182f408b8..eb147859e 100644 --- a/vendor/drupal/console/src/Command/Generate/TwigExtensionCommand.php +++ b/vendor/drupal/console/src/Command/Generate/TwigExtensionCommand.php @@ -6,12 +6,12 @@ namespace Drupal\Console\Command\Generate; -use Symfony\Component\Console\Command\Command; +use Drupal\Console\Core\Command\ContainerAwareCommand; use Drupal\Console\Command\Shared\ConfirmationTrait; use Drupal\Console\Command\Shared\ModuleTrait; use Drupal\Console\Command\Shared\ServicesTrait; use Drupal\Console\Generator\TwigExtensionGenerator; -use Drupal\Console\Core\Style\DrupalStyle; +use Drupal\Console\Utils\Validator; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -19,28 +19,26 @@ use Drupal\Console\Extension\Manager; use Drupal\Console\Core\Utils\ChainQueue; use Drupal\Console\Utils\Site; use Drupal\Console\Core\Utils\StringConverter; -use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait; /** * Class TwigExtensionCommand * * @package Drupal\Console\Command\Generate */ -class TwigExtensionCommand extends Command +class TwigExtensionCommand extends ContainerAwareCommand { use ModuleTrait; use ServicesTrait; use ConfirmationTrait; - use ContainerAwareCommandTrait; /** - * @var Manager -*/ + * @var Manager + */ protected $extensionManager; /** - * @var TwigExtensionGenerator -*/ + * @var TwigExtensionGenerator + */ protected $generator; /** @@ -53,6 +51,11 @@ class TwigExtensionCommand extends Command */ protected $stringConverter; + /** + * @var Validator + */ + protected $validator; + /** * @var ChainQueue */ @@ -65,6 +68,7 @@ class TwigExtensionCommand extends Command * @param Manager $extensionManager * @param TwigExtensionGenerator $generator * @param StringConverter $stringConverter + * @param Validator $validator * @param ChainQueue $chainQueue */ public function __construct( @@ -72,19 +76,21 @@ class TwigExtensionCommand extends Command TwigExtensionGenerator $generator, Site $site, StringConverter $stringConverter, + Validator $validator, ChainQueue $chainQueue ) { $this->extensionManager = $extensionManager; $this->generator = $generator; $this->site = $site; $this->stringConverter = $stringConverter; + $this->validator = $validator; $this->chainQueue = $chainQueue; parent::__construct(); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ protected function configure() { $this @@ -114,24 +120,22 @@ class TwigExtensionCommand extends Command null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.common.options.services') - ); + )->setAliases(['gte']); } /** - * {@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'); $name = $input->getOption('name'); - $class = $input->getOption('class'); + $class = $this->validator->validateClassName($input->getOption('class')); $services = $input->getOption('services'); // Add renderer service as first parameter. array_unshift($services, 'renderer'); @@ -139,7 +143,12 @@ class TwigExtensionCommand extends Command // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices $build_services = $this->buildServices($services); - $this->generator->generate($module, $name, $class, $build_services); + $this->generator->generate([ + 'module' => $module, + 'name' => $name, + 'class' => $class, + 'services' => $build_services, + ]); $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); @@ -147,25 +156,18 @@ class TwigExtensionCommand extends Command } /** - * {@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(); // --name option $name = $input->getOption('name'); if (!$name) { - $name = $io->ask( - $this->trans('commands.generate.twig.extension.questions.twig-extension'), + $name = $this->getIo()->ask( + $this->trans('commands.generate.twig.extension.questions.name'), $module.'.twig.extension' ); $input->setOption('name', $name); @@ -174,9 +176,12 @@ class TwigExtensionCommand extends Command // --class option $class = $input->getOption('class'); if (!$class) { - $class = $io->ask( + $class = $this->getIo()->ask( $this->trans('commands.common.options.class'), - 'DefaultTwigExtension' + 'DefaultTwigExtension', + function ($class) { + return $this->validator->validateClassName($class); + } ); $input->setOption('class', $class); } @@ -185,7 +190,7 @@ class TwigExtensionCommand 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); } }