| 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: | use Symfony\Component\Console\Input\InputOption; |
| 8: | |
| 9: | use Symfony\Component\Filesystem\Filesystem; |
| 10: | use Symfony\Component\Finder\Finder; |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | final class MakeBundle extends BaseMaker |
| 16: | { |
| 17: | protected static $skelPath = __DIR__.'/../../acme/'; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | protected function ticConfigure(Command $command) |
| 23: | { |
| 24: | $command->addArgument('name', InputArgument::OPTIONAL, "Nom, chemin ou classname du bundle"); |
| 25: | } |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | protected function ticGenerate(InputInterface $input) |
| 31: | { |
| 32: | $inputName = $this->fixClassName($input->getArgument('name')); |
| 33: | $this->io->title("Construction du bundle : '$inputName'"); |
| 34: | |
| 35: | |
| 36: | $parts = explode("\\", preg_replace('/Bundle$/', '', $inputName)); |
| 37: | $bundle_name = array_pop($parts); |
| 38: | $vendor_path = empty($parts) ? "TIC" : implode("\\", $parts); |
| 39: | $vendor_name = str_replace("\\", "", $vendor_path); |
| 40: | $bundle_class = $vendor_path . "\\" . $bundle_name; |
| 41: | dump($parts, $bundle_name, $vendor_path, $vendor_name); |
| 42: | |
| 43: | |
| 44: | $variables = array( |
| 45: | 'TIC\\Acme' => $vendor_path . "\\" . $bundle_name, |
| 46: | 'TIC\\\\Acme' => str_replace("\\", "\\\\", $vendor_path . "\\" . $bundle_name), |
| 47: | 'TICAcme' => $vendor_name . $bundle_name, |
| 48: | 'ticacme' => strtolower($vendor_name . $bundle_name), |
| 49: | 'tic_acme' => strtolower(str_replace("\\", "_", $bundle_class)), |
| 50: | 'TIC Acme' => str_replace("\\", " ", $bundle_class), |
| 51: | 'Acme' => $bundle_name, |
| 52: | 'acme' => strtolower($bundle_name), |
| 53: | 'target_dir' => $this->generator->getRootDirectory() . "/lib/" . $vendor_name . $bundle_name . "Bundle/", |
| 54: | ); |
| 55: | |
| 56: | |
| 57: | $this->io->section("Paramètres utilisés :"); |
| 58: | $this->io->table(["Variable","Valeur"], self::hash2list($variables)); |
| 59: | if ($this->test) return; |
| 60: | |
| 61: | if (! $this->confirm("Lancer la construction ?")) return; |
| 62: | $results = array(); |
| 63: | |
| 64: | |
| 65: | $fs = new Filesystem(); |
| 66: | $finder = new Finder(); |
| 67: | $finder->files()->in(self::$skelPath); |
| 68: | foreach ($finder as $file) { |
| 69: | $folder = $variables['target_dir'] . $file->getRelativePath(); |
| 70: | $fs->mkdir($folder); |
| 71: | |
| 72: | $src = $file->getRealPath(); |
| 73: | $dst = $folder . '/' . str_replace(array_keys($variables), array_values($variables), $file->getFilename()); |
| 74: | file_put_contents($dst, str_replace(array_keys($variables), array_values($variables), file_get_contents($src))); |
| 75: | |
| 76: | $results[] = [ $file->getRelativePathname(), $dst ]; |
| 77: | } |
| 78: | |
| 79: | |
| 80: | return $this->summary($results); |
| 81: | } |
| 82: | |
| 83: | } |
| 84: | |