Create ChoiceElement

This commit is contained in:
Tim 2022-09-28 16:53:08 +02:00
parent 501175a1de
commit 9b61402760
3 changed files with 32 additions and 6 deletions

View File

@ -16,7 +16,7 @@ use Symfony\Component\Console\Style\SymfonyStyle;
abstract class AbstractEntityCommand extends Command
{
public function __construct(
private EntityManagerInterface $em,
protected readonly EntityManagerInterface $em,
)
{
parent::__construct();
@ -51,8 +51,8 @@ abstract class AbstractEntityCommand extends Command
$builder->setAll($entity);
$this->em->persist($entity);
if ($io->askQuestion(new ConfirmationQuestion(sprintf('Are you sure you want to create %s with above properties', $entity)))) {
$io->success(sprintf('Object "%s" (id: %s) stored successfully', $entity, $entity->getId()));
if ($io->askQuestion(new ConfirmationQuestion(sprintf('Are you sure you want to create "%s" with above properties', $entity)))) {
$io->success(sprintf('Object "%s" stored successfully', $entity));
}
} while ($io->askQuestion(new ConfirmationQuestion('Create another?', false)));
} elseif ($input->getOption('modify')) {

View File

@ -8,13 +8,16 @@ class BaseElement
{
public function getQuestion(): Question
{
$name = ucfirst(strtolower(implode(' ', preg_split('/(?=[A-Z])/', $this->getProperty()))));
return new Question($name);
return new Question($this->getPrettyProperty());
}
protected function getPrettyProperty(): string
{
return ucfirst(strtolower(implode(' ', preg_split('/(?=[A-Z])/', $this->getProperty()))));
}
public function __construct(
private readonly string $property,
private readonly array $config = [],
)
{
}

View File

@ -0,0 +1,23 @@
<?php
namespace Ardent\UtilBundle\EntityBuilder;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\Question;
class ChoiceElement extends BaseElement
{
public function getQuestion(): Question
{
return new ChoiceQuestion($this->getPrettyProperty(), $this->choices);
}
public function __construct(
string $property,
private readonly array $choices,
)
{
parent::__construct($property);
}
}