-
-
Notifications
You must be signed in to change notification settings - Fork 424
Description
Described well here: https://symfonycasts.com/screencast/api-platform/api-resource#comment-5541407296
Basically, if you pass the entity class name to make:entity
- e.g. bin/console make:entity CheeseListing
, then it does NOT ask:
Mark this class as an API Platform resource?
The problem is that, in interact()
, if the name
argument is passed, we immediately return:
maker-bundle/src/Maker/MakeEntity.php
Lines 97 to 101 in 884f10d
public function interact(InputInterface $input, ConsoleStyle $io, Command $command) | |
{ | |
if ($input->getArgument('name')) { | |
return; | |
} |
That should not happen. If the name
argument is passed, then:
A) We obviously should not ask for the entity name -
maker-bundle/src/Maker/MakeEntity.php
Lines 115 to 119 in 884f10d
$argument = $command->getDefinition()->getArgument('name'); | |
$question = $this->createEntityClassQuestion($argument->getDescription()); | |
$entityClassName = $io->askQuestion($question); | |
$input->setArgument('name', $entityClassName); |
B) We should also not ask for it here:
maker-bundle/src/Maker/MakeEntity.php
Lines 104 to 110 in 884f10d
$io->block([ | |
'This command will generate any missing methods (e.g. getters & setters) for a class or all classes in a namespace.', | |
'To overwrite any existing methods, re-run this command with the --overwrite flag', | |
], null, 'fg=yellow'); | |
$classOrNamespace = $io->ask('Enter a class or namespace to regenerate', $this->getEntityNamespace(), [Validator::class, 'notBlank']); | |
$input->setArgument('name', $classOrNamespace); |
C) But we should ask about the api-resource and broadcast:
maker-bundle/src/Maker/MakeEntity.php
Lines 121 to 143 in 884f10d
if ( | |
!$input->getOption('api-resource') && | |
class_exists(ApiResource::class) && | |
!class_exists($this->generator->createClassNameDetails($entityClassName, 'Entity\\')->getFullName()) | |
) { | |
$description = $command->getDefinition()->getOption('api-resource')->getDescription(); | |
$question = new ConfirmationQuestion($description, false); | |
$isApiResource = $io->askQuestion($question); | |
$input->setOption('api-resource', $isApiResource); | |
} | |
if ( | |
!$input->getOption('broadcast') && | |
class_exists(Broadcast::class) && | |
!class_exists($this->generator->createClassNameDetails($entityClassName, 'Entity\\')->getFullName()) | |
) { | |
$description = $command->getDefinition()->getOption('broadcast')->getDescription(); | |
$question = new ConfirmationQuestion($description, false); | |
$isBroadcast = $io->askQuestion($question); | |
$input->setOption('broadcast', $isBroadcast); | |
} |
So basically, this if (
maker-bundle/src/Maker/MakeEntity.php
Lines 99 to 101 in 884f10d
if ($input->getArgument('name')) { | |
return; | |
} |
return
... the first two sections should probably just be moved inside of it: maker-bundle/src/Maker/MakeEntity.php
Lines 103 to 119 in 884f10d
if ($input->getOption('regenerate')) { | |
$io->block([ | |
'This command will generate any missing methods (e.g. getters & setters) for a class or all classes in a namespace.', | |
'To overwrite any existing methods, re-run this command with the --overwrite flag', | |
], null, 'fg=yellow'); | |
$classOrNamespace = $io->ask('Enter a class or namespace to regenerate', $this->getEntityNamespace(), [Validator::class, 'notBlank']); | |
$input->setArgument('name', $classOrNamespace); | |
return; | |
} | |
$argument = $command->getDefinition()->getArgument('name'); | |
$question = $this->createEntityClassQuestion($argument->getDescription()); | |
$entityClassName = $io->askQuestion($question); | |
$input->setArgument('name', $entityClassName); |
Cheers!