Skip to content

Commit 860d340

Browse files
committed
WIP Add --no-template option for make:controller command
1 parent 352f77a commit 860d340

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Maker/MakeController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Console\Command\Command;
2222
use Symfony\Component\Console\Input\InputArgument;
2323
use Symfony\Component\Console\Input\InputInterface;
24+
use Symfony\Component\Console\Input\InputOption;
2425

2526
/**
2627
* @author Javier Eguiluz <[email protected]>
@@ -38,6 +39,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
3839
$command
3940
->setDescription('Creates a new controller class')
4041
->addArgument('controller-class', InputArgument::OPTIONAL, sprintf('Choose a name for your controller class (e.g. <fg=yellow>%sController</>)', Str::asClassName(Str::getRandomTerm())))
42+
->addOption('--no-template', '-n', InputOption::VALUE_OPTIONAL)
4143
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeController.txt'))
4244
;
4345
}
@@ -50,19 +52,20 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
5052
'Controller'
5153
);
5254

55+
$withTemplate = !$input->getOption('--no-template');
5356
$templateName = Str::asFilePath($controllerClassNameDetails->getRelativeNameWithoutSuffix()).'/index.html.twig';
5457
$controllerPath = $generator->generateController(
5558
$controllerClassNameDetails->getFullName(),
5659
'controller/Controller.tpl.php',
5760
[
5861
'route_path' => Str::asRoutePath($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
5962
'route_name' => Str::asRouteName($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
60-
'twig_installed' => $this->isTwigInstalled(),
63+
'twig_installed' => $this->isTwigInstalled() && $withTemplate,
6164
'template_name' => $templateName,
6265
]
6366
);
6467

65-
if ($this->isTwigInstalled()) {
68+
if ($this->isTwigInstalled() && $withTemplate) {
6669
$generator->generateFile(
6770
'templates/'.$templateName,
6871
'controller/twig_template.tpl.php',

tests/Maker/FunctionalTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ public function getCommandTests()
121121
->deleteFile('templates/base.html.twig')
122122
];
123123

124+
yield 'controller_without_template' => [MakerTestDetails::createTest(
125+
$this->getMakerInstance(MakeController::class),
126+
[
127+
// controller class name
128+
'FooTwig',
129+
// option to disable template generation
130+
'--no-template'
131+
])
132+
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeController')
133+
->addExtraDependencies('twig')
134+
->assert(function (string $output, string $directory) {
135+
// make sure the template was not configured
136+
$this->assertContainsCount('created: ', $output, 1);
137+
})
138+
];
139+
124140
yield 'controller_sub_namespace' => [MakerTestDetails::createTest(
125141
$this->getMakerInstance(MakeController::class),
126142
[

0 commit comments

Comments
 (0)