Skip to content

Commit c13323d

Browse files
committed
Add class question to middelware generator
1 parent fd64158 commit c13323d

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

scripts/run-sut-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ if [ $TARGET_TEST = all -o $TARGET_TEST = service ]; then
189189
$DCG d8:service:custom -d $MODULE_DIR -a '{"name":"Zippo","machine_name":"zippo", "service_name":"zippo.foo","class":"Foo","di":"Yes"}'
190190
$DCG d8:service:event-subscriber -d $MODULE_DIR -a '{"name":"Zippo","machine_name":"zippo","class":"ZippoSubscriber"}'
191191
$DCG d8:service:logger -d $MODULE_DIR -a '{"name":"Zippo","machine_name":"zippo","class":"FileLog"}'
192-
$DCG d8:service:middleware -d $MODULE_DIR -a '{"name":"Dcg service","machine_name":"zippo"}'
192+
$DCG d8:service:middleware -d $MODULE_DIR -a '{"name":"Dcg service","machine_name":"zippo","class":"ZippoMiddleware"}'
193193
$DCG d8:service:param-converter -d $MODULE_DIR -a '{"name":"Zippo","machine_name":"zippo","parameter_type":"example","class":"ExampleParamConverter"}'
194194
$DCG d8:service:route-subscriber -d $MODULE_DIR -a '{"name":"Zippo","machine_name":"zippo"}'
195195
$DCG d8:service:theme-negotiator -d $MODULE_DIR -a '{"name":"Zippo","machine_name":"zippo","class":"ZippoThemeNegotiator"}'

src/Command/Drupal_8/Service/Middleware.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use DrupalCodeGenerator\Utils;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Question\Question;
910

1011
/**
1112
* Implements d8:service:middleware command.
@@ -20,9 +21,14 @@ class Middleware extends BaseGenerator {
2021
* {@inheritdoc}
2122
*/
2223
protected function interact(InputInterface $input, OutputInterface $output) {
23-
$questions = Utils::defaultQuestions();
24-
$vars = &$this->collectVars($input, $output, $questions);
25-
$vars['class'] = Utils::camelize($vars['machine_name']) . 'Middleware';
24+
$questions = Utils::moduleQuestions();
25+
26+
$default_class = function ($vars) {
27+
return Utils::camelize($vars['machine_name']) . 'Middleware';
28+
};
29+
$questions['class'] = new Question('Class', $default_class);
30+
$questions['class']->setValidator([Utils::class, 'validateClassName']);
31+
$this->collectVars($input, $output, $questions);
2632

2733
$this->addFile()
2834
->path('src/{class}.php')

tests/dcg/Generator/Drupal_8/Service/MiddlewareTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class MiddlewareTest extends GeneratorBaseTest {
1414
protected $interaction = [
1515
'Module name [%default_name%]:' => 'Foo',
1616
'Module machine name [foo]:' => 'foo',
17+
'Class [FooMiddleware]:' => 'FooMiddleware',
1718
];
1819

1920
protected $fixtures = [

0 commit comments

Comments
 (0)