Skip to content

Commit 4285539

Browse files
committed
annotation support for make:controller
1 parent 35c5c77 commit 4285539

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/Maker/AbstractMaker.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ protected function addDependencies(array $dependencies, string $message = null):
4848
$message
4949
);
5050
}
51+
52+
protected function useAnnotations(): bool
53+
{
54+
return (version_compare(PHP_VERSION, '8') >= 0);
55+
}
5156
}

src/Maker/MakeController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
5858
$controllerClassNameDetails->getFullName(),
5959
'controller/Controller.tpl.php',
6060
[
61+
'use_annotations' => $this->useAnnotations(),
6162
'route_path' => Str::asRoutePath($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
6263
'route_name' => Str::asRouteName($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
6364
'with_template' => $this->isTwigInstalled() && !$noTemplate,

src/Resources/skeleton/controller/Controller.tpl.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
class <?= $class_name; ?> extends <?= $parent_class_name; ?><?= "\n" ?>
1010
{
11+
<?php if ($use_annotations) { ?>
12+
#[Route("<?= $route_path ?>", name="<?= $route_name ?>")]
13+
<?php } else { ?>
1114
/**
1215
* @Route("<?= $route_path ?>", name="<?= $route_name ?>")
1316
*/
17+
<?php } ?>
1418
public function index(): Response
1519
{
1620
<?php if ($with_template) { ?>

0 commit comments

Comments
 (0)