Create ChoiceElement
This commit is contained in:
		| @@ -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')) { | ||||
|   | ||||
| @@ -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 = [], | ||||
|     ) | ||||
|     { | ||||
|     } | ||||
|   | ||||
							
								
								
									
										23
									
								
								src/EntityBuilder/ChoiceElement.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/EntityBuilder/ChoiceElement.php
									
									
									
									
									
										Normal 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); | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user