Source of file MakeViews.php
Size: 2,691 Bytes - Last Modified: 2023-11-16T22:56:03+01:00
/home/websites/teicee/packagist/site/phpdoc/conf/../vendor/teicee/make-bundle/src/Maker/MakeViews.php
| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | <?phpnamespace TIC\MakeBundle\Maker; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Doctrine\Common\Annotations\Annotation; use Symfony\Bundle\MakerBundle\Util\ClassNameDetails; use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper; /** * */final class MakeViews extends BaseMaker {private $doctrineHelper; public function __construct(DoctrineHelper $doctrineHelper) { parent::__construct(); $this->doctrineHelper = $doctrineHelper; } /** * Configure the command: set description, input arguments, options, etc. */protected function ticConfigure(Command $command) { $command->addArgument('name', InputArgument::OPTIONAL, "Nom, chemin ou classname du controller CRUD correspondant"); $command->addOption('split', null, InputOption::VALUE_NONE, "Séparer les actions create & update"); } /** * Called after normal code generation: allows you to do anything. */protected function ticGenerate(InputInterface $input) { $inputName = $this->fixClassName($input->getArgument('name')); $this->io->title("Construction des templates des vues CRUD : '$inputName'"); // détermination des variables à utiliser $variables = $this->getVariablesFromName($inputName); $doctrineDetails = $this->doctrineHelper->createDoctrineDetails($variables['item_class']); // affichage des valeurs des variables $this->io->section("Paramètres utilisés :"); $this->io->table(["Variable","Valeur"], self::hash2list($variables)); if (null === $doctrineDetails) throw new RuntimeCommandException("Entité introuvable : " . $variables['item_class']); if ($this->test) return; if (! $this->confirm("Lancer la construction ?")) return; $results = array(); // construction Twig templates if ($this->twig) { $this->io->section("Construction des templates..."); $tpls = ['base', 'list', '_list_table', 'show', '_show_main']; $tpls = array_merge($tpls, $input->getOption('split') ? ['create', 'update'] : ['form']); $paths = $this->ticGenerateTemplates('crud', $tpls, $variables + [ 'entity_key' => $doctrineDetails->getIdentifier(), 'entity_fields' => $doctrineDetails->getDisplayFields(), # 'ctrl_path' => $controllerPath,]); $this->io->success("Génération des views twig : " . implode(", ", $tpls)); foreach ($tpls as $id => $tpl) $results[] = [ "Template '$tpl'", $paths[$id] ]; } // récapitulatif des fichiers générés return $this->summary($results); } } |