Source of file MakeBundle.php
Size: 3,108 Bytes - Last Modified: 2023-11-16T22:56:03+01:00
/home/websites/teicee/packagist/site/phpdoc/conf/../vendor/teicee/make-bundle/src/Maker/MakeBundle.php
| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 | <?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 Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; /** * */final class MakeBundle extends BaseMaker {protected static $skelPath = __DIR__.'/../../acme/'; /** * Configure the command: set description, input arguments, options, etc. */protected function ticConfigure(Command $command) { $command->addArgument('name', InputArgument::OPTIONAL, "Nom, chemin ou classname du bundle"); } /** * 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 du bundle : '$inputName'"); // ex: TIC\DemoBundle, TIC\Demo, DemoBundle, Demo $parts = explode("\\", preg_replace('/Bundle$/', '', $inputName)); $bundle_name = array_pop($parts); $vendor_path = empty($parts) ? "TIC" : implode("\\", $parts); $vendor_name = str_replace("\\", "", $vendor_path); $bundle_class = $vendor_path . "\\" . $bundle_name; dump($parts, $bundle_name, $vendor_path, $vendor_name); // détermination des variables à utiliser $variables = array( 'TIC\\Acme' => $vendor_path . "\\" . $bundle_name, 'TIC\\\\Acme' => str_replace("\\", "\\\\", $vendor_path . "\\" . $bundle_name), 'TICAcme' => $vendor_name . $bundle_name, // TICAcme, @TICAcme, TICAcmeBundle, TICAcmeExtension 'ticacme' => strtolower($vendor_name . $bundle_name), // ticacme, ticacme_ (routes), ticacme. (trans) 'tic_acme' => strtolower(str_replace("\\", "_", $bundle_class)), // tic_acme (tables) 'TIC Acme' => str_replace("\\", " ", $bundle_class), // TIC Acme (docs) 'Acme' => $bundle_name, 'acme' => strtolower($bundle_name), 'target_dir' => $this->generator->getRootDirectory() . "/lib/" . $vendor_name . $bundle_name . "Bundle/", ); // affichage des valeurs des variables $this->io->section("Paramètres utilisés :"); $this->io->table(["Variable","Valeur"], self::hash2list($variables)); if ($this->test) return; if (! $this->confirm("Lancer la construction ?")) return; $results = array(); // génération des fichiers du bundle $fs = new Filesystem(); $finder = new Finder(); $finder->files()->in(self::$skelPath); foreach ($finder as $file) { $folder = $variables['target_dir'] . $file->getRelativePath(); $fs->mkdir($folder); $src = $file->getRealPath(); $dst = $folder . '/' . str_replace(array_keys($variables), array_values($variables), $file->getFilename()); file_put_contents($dst, str_replace(array_keys($variables), array_values($variables), file_get_contents($src))); $results[] = [ $file->getRelativePathname(), $dst ]; } // récapitulatif des fichiers générés return $this->summary($results); } } |