| 1: | <?php |
| 2: | namespace TIC\MakeBundle\Maker; |
| 3: | |
| 4: | use Symfony\Component\Console\Command\Command; |
| 5: | use Symfony\Component\Console\Input\InputInterface; |
| 6: | use Symfony\Component\Console\Input\InputArgument; |
| 7: | |
| 8: | use Symfony\Bundle\MakerBundle\Util\ClassNameDetails; |
| 9: | use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; |
| 10: | use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper; |
| 11: | use TIC\MakeBundle\Renderer\FormTypeRenderer; |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | final class MakeForm extends BaseMaker |
| 17: | { |
| 18: | private $doctrineHelper; |
| 19: | private $formTypeRenderer; |
| 20: | |
| 21: | public function __construct(DoctrineHelper $doctrineHelper, FormTypeRenderer $formTypeRenderer) |
| 22: | { |
| 23: | parent::__construct(); |
| 24: | $this->doctrineHelper = $doctrineHelper; |
| 25: | $this->formTypeRenderer = $formTypeRenderer; |
| 26: | } |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | protected function ticConfigure(Command $command) |
| 32: | { |
| 33: | $command->addArgument('name', InputArgument::OPTIONAL, "Nom, chemin ou classname du formulaire (<folder?>/entity)"); |
| 34: | } |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | protected function ticGenerate(InputInterface $input) |
| 40: | { |
| 41: | $inputName = $this->fixClassName($input->getArgument('name')); |
| 42: | $this->io->title("Construction du formulaire : '$inputName'"); |
| 43: | |
| 44: | |
| 45: | $variables = $this->getVariablesFromName($inputName, "Type"); |
| 46: | $doctrineDetails = $this->doctrineHelper->createDoctrineDetails($variables['item_class']); |
| 47: | $entityDetails = new ClassNameDetails($variables['item_class'], ''); |
| 48: | $formDetails = new ClassNameDetails($variables['form_class'], ''); |
| 49: | |
| 50: | |
| 51: | $this->io->section("Paramètres utilisés :"); |
| 52: | $this->io->table(["Variable","Valeur"], self::hash2list($variables)); |
| 53: | if (null === $doctrineDetails) |
| 54: | throw new RuntimeCommandException("Entité introuvable : " . $variables['item_class']); |
| 55: | if ($this->test) return; |
| 56: | |
| 57: | if (! $this->confirm("Lancer la construction ?")) return; |
| 58: | $results = array(); |
| 59: | |
| 60: | |
| 61: | $this->io->section("Construction du formulaire..."); |
| 62: | $formPath = $this->ticGenerateFormType($this->formTypeRenderer, $formDetails, $doctrineDetails, $entityDetails); |
| 63: | $results[] = [ $variables['form_class'], $formPath ]; |
| 64: | $this->io->success("Génération du FormType : " . $variables['form_class']); |
| 65: | |
| 66: | |
| 67: | return $this->summary($results); |
| 68: | } |
| 69: | |
| 70: | } |
| 71: | |