protected function execute(InputInterface $input, OutputInterface $output) { // validate bundle if (!preg_match('/Bundle$/', $bundle = $input->getArgument('bundle'))) { throw new \InvalidArgumentException('The bundle must end with Bundle'); } // validate that the namespace is at least one level deep if (false === strpos($bundle, '\\')) { throw new \InvalidArgumentException('The bundle must contain the vendor with quotes, exemple "vendors\\MyBundle"'); } if (!is_dir($bundleDir = 'src/' . strtr($bundle, '\\', '/'))) { throw new \RuntimeException(sprintf('The directory %s doesn\'t exists, are you sure that it is the correct bundle ?', $bundleDir)); } // validate namespace $namespace = $bundle . '\\Tests'; $path = $input->getArgument('path'); if (isset($path)) { $namespace .= '\\' . $path; } $namespace = strtr($namespace, '/', '\\'); if (preg_match('/[^A-Za-z0-9_\\\\-]/', $namespace)) { throw new \InvalidArgumentException('The namespace contains invalid characters.'); } if (!preg_match('/Test$/', $filename = $input->getArgument('filename'))) { throw new \InvalidArgumentException('The filename musts end with Test'); } $targetFile = 'src/' . strtr($bundle, '\\', '/') . '/Tests/' . $path . '/' . $filename . '.php'; if (file_exists($targetFile)) { throw new \RuntimeException(sprintf('The "%s" test file already exists.', $targetFile)); } $filesystem = $this->container->get('filesystem'); $filesystem->copy(__DIR__ . '/../Resources/skeleton/UnitTestCase.php', $targetFile); Mustache::renderFile($targetFile, array('namespace' => $namespace, 'className' => $filename)); $output->writeln('<info>[File+]</info> ' . $targetFile); }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { $finder = new Finder(); if (iterator_count($finder->in(getcwd()))) { throw new \RuntimeException('The current directory is not empty.'); } $parameters = array('class' => $input->getOption('name'), 'application' => strtolower($input->getOption('name')), 'format' => $input->getOption('format')); $filesystem = new Filesystem(); $skeletonDir = __DIR__ . '/../../skeleton'; $appPath = getcwd() . '/' . $input->getOption('app-path'); $srcPath = getcwd() . '/' . $input->getOption('src-path'); $webPath = getcwd() . '/' . $input->getOption('web-path'); $filesystem->mirror($skeletonDir . '/application/generic', $appPath); $filesystem->mirror($skeletonDir . '/application/' . $input->getOption('format'), $appPath); $filesystem->mirror($skeletonDir . '/src', $srcPath); Mustache::renderDir($appPath, $parameters); $filesystem->chmod($appPath . '/console', 0777); $filesystem->chmod($appPath . '/logs', 0777); $filesystem->chmod($appPath . '/cache', 0777); $filesystem->rename($appPath . '/Kernel.php', $appPath . '/' . $input->getOption('name') . 'Kernel.php'); $filesystem->rename($appPath . '/Cache.php', $appPath . '/' . $input->getOption('name') . 'Cache.php'); $filesystem->copy($skeletonDir . '/web/front_controller.php', $file = $webPath . '/' . (file_exists($webPath . '/index.php') ? strtolower($input->getOption('name')) : 'index') . '.php'); Mustache::renderFile($file, $parameters); $filesystem->copy($skeletonDir . '/web/front_controller_debug.php', $file = $webPath . '/' . strtolower($input->getOption('name')) . '_dev.php'); Mustache::renderFile($file, $parameters); }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { if (file_exists($targetDir = $input->getArgument('path'))) { throw new \RuntimeException(sprintf('The directory "%s" already exists.', $targetDir)); } if (!file_exists($webDir = $input->getArgument('web_path'))) { mkdir($webDir, 0777, true); } $parameters = array('class' => $input->getArgument('name'), 'application' => strtolower($input->getArgument('name')), 'format' => $input->getOption('format')); $filesystem = new Filesystem(); $filesystem->mirror(__DIR__ . '/../Resources/skeleton/application/generic', $targetDir); $filesystem->mirror(__DIR__ . '/../Resources/skeleton/application/' . $input->getOption('format'), $targetDir); Mustache::renderDir($targetDir, $parameters); $filesystem->chmod($targetDir . '/console', 0777); $filesystem->chmod($targetDir . '/logs', 0777); $filesystem->chmod($targetDir . '/cache', 0777); $filesystem->rename($targetDir . '/Kernel.php', $targetDir . '/' . $input->getArgument('name') . 'Kernel.php'); $filesystem->rename($targetDir . '/Cache.php', $targetDir . '/' . $input->getArgument('name') . 'Cache.php'); $filesystem->copy(__DIR__ . '/../Resources/skeleton/web/front_controller.php', $file = $webDir . '/' . (file_exists($webDir . '/index.php') ? strtolower($input->getArgument('name')) : 'index') . '.php'); Mustache::renderFile($file, $parameters); $filesystem->copy(__DIR__ . '/../Resources/skeleton/web/front_controller_debug.php', $file = $webDir . '/' . strtolower($input->getArgument('name')) . '_dev.php'); Mustache::renderFile($file, $parameters); }
public function testRenderFile() { Mustache::renderFile($this->dir.'/template.txt', array('me' => 'Fabien')); $this->assertEquals('Hello Fabien', file_get_contents($this->dir.'/template.txt'), '::renderFile() renders a file'); }