X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FCommand%2FDrupal_8%2FService%2FCustom.php;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FCommand%2FDrupal_8%2FService%2FCustom.php;h=77697bf1121f9a750dc95c99d28ca027ee73f59d;hp=786343395698b9ff8d6e350a8be7f76a03613349;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/Service/Custom.php b/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/Service/Custom.php index 786343395..77697bf11 100644 --- a/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/Service/Custom.php +++ b/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/Service/Custom.php @@ -6,6 +6,7 @@ use DrupalCodeGenerator\Command\BaseGenerator; use DrupalCodeGenerator\Utils; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\Question; /** @@ -24,19 +25,22 @@ class Custom extends BaseGenerator { protected function interact(InputInterface $input, OutputInterface $output) { $questions = Utils::defaultQuestions(); $questions['service_name'] = new Question('Service name', '{machine_name}.example'); - $questions['service_name']->setValidator(function ($value) { - if (!preg_match('/^[a-z][a-z0-9_\.]*[a-z0-9]$/', $value)) { - throw new \UnexpectedValueException('The value is not correct service name.'); - } - return $value; - }); + $questions['service_name']->setValidator([Utils::class, 'validateServiceName']); + $default_class = function ($vars) { - return Utils::camelize($vars['service_name']); + $service = preg_replace('/^' . $vars['machine_name'] . '/', '', $vars['service_name']); + return Utils::camelize($service); }; $questions['class'] = new Question('Class', $default_class); + $questions['class']->setValidator([Utils::class, 'validateClassName']); $this->collectVars($input, $output, $questions); + $di_question = new ConfirmationQuestion('Would you like to inject dependencies?'); + if ($this->ask($input, $output, $di_question)) { + $this->collectServices($input, $output); + } + $this->addFile() ->path('src/{class}.php') ->template('d8/service/custom.twig');