public function setUp() { $dir = __DIR__ . '/fixtures/'; $this->dir = sys_get_temp_dir() . '/mustache'; $filesystem = new Filesystem(); $filesystem->mirror($dir, $this->dir); }
/** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { if (!is_dir($input->getArgument('target'))) { throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target'))); } $filesystem = new Filesystem(); foreach ($this->container->getKernelService()->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath() . '/Resources/public')) { $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $bundle->getNamespacePrefix(), $bundle->getName())); $targetDir = $input->getArgument('target') . '/bundles/' . preg_replace('/bundle$/', '', strtolower($bundle->getName())); $filesystem->remove($targetDir); mkdir($targetDir, 0777, true); $filesystem->mirror($originDir, $targetDir); } } }
/** * @see Command * * @throws \InvalidArgumentException When namespace doesn't end with Bundle * @throws \RuntimeException When bundle can't be executed */ protected function execute(InputInterface $input, OutputInterface $output) { if (!preg_match('/Bundle$/', $namespace = $input->getArgument('namespace'))) { throw new \InvalidArgumentException('The namespace must end with Bundle.'); } $dirs = $this->container->getKernelService()->getBundleDirs(); $tmp = str_replace('\\', '/', $namespace); $namespace = str_replace('/', '\\', dirname($tmp)); $bundle = basename($tmp); if (!isset($dirs[$namespace])) { throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle (%s not defined).', $namespace)); } $dir = $dirs[$namespace]; $output->writeln(sprintf('Initializing bundle "<info>%s</info>" in "<info>%s</info>"', $bundle, realpath($dir))); if (file_exists($targetDir = $dir . '/' . $bundle)) { throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle)); } $filesystem = new Filesystem(); $filesystem->mirror(__DIR__ . '/../Resources/skeleton/bundle', $targetDir); Mustache::renderDir($targetDir, array('namespace' => $namespace, 'bundle' => $bundle)); rename($targetDir . '/Bundle.php', $targetDir . '/' . $bundle . '.php'); }
/** * @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('yaml') ? 'yaml' : 'xml'; $filesystem = new Filesystem(); $filesystem->mirror(__DIR__ . '/../Resources/skeleton/application/' . $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); }