Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/Command/MakeCrudControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Maker\ClassMaker;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand All @@ -32,6 +33,7 @@ protected function configure(): void
{
$this
->setHelp($this->getCommandHelp())
->addArgument('doctrine_entity', InputArgument::OPTIONAL, 'Which Doctrine entity are you going to manage with this CRUD controller?')
;
}

Expand All @@ -46,10 +48,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return Command::FAILURE;
}
$entityFqcn = $io->choice(
'Which Doctrine entity are you going to manage with this CRUD controller?',
$doctrineEntitiesFqcn
);
if (null !== $input->getArgument('doctrine_entity')) {
$entityFqcn = $input->getArgument('doctrine_entity');
if (!\in_array($entityFqcn, $doctrineEntitiesFqcn, true)) {
$io->error(sprintf('The "%s" entity does not exist. Pick one of the existing entities: %s', $entityFqcn, implode(', ', $doctrineEntitiesFqcn)));

return Command::FAILURE;
}
} else {
$entityFqcn = $io->choice(
'Which Doctrine entity are you going to manage with this CRUD controller?',
$doctrineEntitiesFqcn
);
}
$entityClassName = u($entityFqcn)->afterLast('\\')->toString();
$controllerFileNamePattern = sprintf('%s{number}CrudController.php', $entityClassName);

Expand Down