Skip to content

Commit d3ca5d4

Browse files
fix(controller): delete doctrine-annotation dependencie
1 parent 4daae2f commit d3ca5d4

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/Command/MakeTwcController.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Bundle\MakerBundle\InputConfiguration;
2121
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
2222
use Symfony\Bundle\MakerBundle\Str;
23+
use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil;
2324
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
2425
use Symfony\Bundle\TwigBundle\TwigBundle;
2526
use Symfony\Component\Console\Command\Command;
@@ -34,22 +35,21 @@
3435

3536
final class MakeTwcController extends AbstractMaker
3637
{
37-
/**
38-
* @var ContextGenerator
39-
*/
40-
private $contextGenerator;
4138

42-
/**
43-
* @var FileManager
44-
*/
45-
private $fileManager;
4639

4740
public function __construct(
48-
ContextGenerator $contextGenerator,
49-
FileManager $fileManager
41+
private ContextGenerator $contextGenerator,
42+
private FileManager $fileManager,
43+
private ?PhpCompatUtil $phpCompatUtil = null,
44+
5045
) {
51-
$this->contextGenerator = $contextGenerator;
52-
$this->fileManager = $fileManager;
46+
if (null !== $phpCompatUtil) {
47+
@trigger_deprecation(
48+
'symfony/maker-bundle',
49+
'1.55.0',
50+
sprintf('Initializing MakeCommand while providing an instance of "%s" is deprecated. The $phpCompatUtil param will be removed in a future version.', PhpCompatUtil::class)
51+
);
52+
}
5353
}
5454

5555
public static function getCommandName(): string
@@ -68,6 +68,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
6868
->setDescription('Creates a new controller class')
6969
->addArgument('controller-class', InputArgument::OPTIONAL, sprintf('Choose a name for your controller class (e.g. <fg=yellow>%sController</>)', Str::asClassName(Str::getRandomTerm())))
7070
->addOption('no-template', null, InputOption::VALUE_NONE, 'Use this option to disable template generation')
71+
->addOption('invokable', 'i', InputOption::VALUE_NONE, 'Use this option to create an invokable controller')
7172
->addOption('context', 'c', InputOption::VALUE_OPTIONAL, 'your context config to generate on your target')
7273
;
7374
}
@@ -90,6 +91,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
9091
);
9192

9293
$noTemplate = $input->getOption('no-template');
94+
$isInvokable = (bool) $input->getOption('invokable');
95+
9396
$dirDefault = Str::asFilePath($controllerClassNameDetails->getRelativeNameWithoutSuffix());
9497

9598
$dirTemplate = $this->contextGenerator->getDirTemplateByContext(
@@ -113,12 +116,13 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
113116
'use_statements' => $useStatements,
114117
'route_path' => Str::asRoutePath($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
115118
'route_name' => Str::asRouteName($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
116-
'with_template' => $this->isTwigInstalled() && !$noTemplate,
119+
'with_template' => $withTemplate,
120+
'method_name' => $isInvokable ? '__invoke' : 'index',
117121
'template_name' => $templateName,
118122
]
119123
);
120124

121-
if ($this->isTwigInstalled() && !$noTemplate && !$templateExist) {
125+
if ($withTemplate) {
122126
$generator->generateTemplate(
123127
$templateName,
124128
'controller/twig_template.tpl.php',
@@ -138,10 +142,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
138142

139143
public function configureDependencies(DependencyBuilder $dependencies): void
140144
{
141-
$dependencies->addClassDependency(
142-
Annotation::class,
143-
'doctrine/annotations'
144-
);
145145
}
146146

147147
private function isTwigInstalled(): bool

0 commit comments

Comments
 (0)