Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make:entity ApiResource question not called when entity pass as an argument #975

Open
weaverryan opened this issue Sep 21, 2021 · 0 comments · May be fixed by #1600
Open

make:entity ApiResource question not called when entity pass as an argument #975

weaverryan opened this issue Sep 21, 2021 · 0 comments · May be fixed by #1600

Comments

@weaverryan
Copy link
Member

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:

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 -

$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:
$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:
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 (

if ($input->getArgument('name')) {
return;
}
) statement should not have a return... the first two sections should probably just be moved inside of it:
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant