public function testGenerateAnnotation()
 {
     $generator = new BundleGenerator($this->filesystem, __DIR__ . '/../../Resources/skeleton/bundle');
     $generator->generate('Foo\\BarBundle', 'FooBarBundle', $this->tmpDir, 'annotation', false);
     $this->assertFalse(file_exists($this->tmpDir . '/Foo/BarBundle/Resources/config/routing.yml'));
     $this->assertFalse(file_exists($this->tmpDir . '/Foo/BarBundle/Resources/config/routing.xml'));
     $content = file_get_contents($this->tmpDir . '/Foo/BarBundle/Controller/DefaultController.php');
     $this->assertContains('@Route("/hello/{name}"', $content);
 }
Example #2
0
 /**
  * Base constructor
  *
  * @param Filesystem $filesystem
  * @param string     $skeletonDir
  */
 public function __construct(Filesystem $filesystem, $skeletonDir, $bundleSkeletonDir = null)
 {
     $this->filesystem = $filesystem;
     $this->skeletonDir = $skeletonDir;
     $this->bundleSkeletonDir = $bundleSkeletonDir;
     parent::__construct($filesystem, $skeletonDir);
 }
 /**
  * @Route("/bundle", name="_generator_bundle")
  * @Template()
  */
 public function generateAction()
 {
     $request = $this->get('request');
     $bundle = new Bundle();
     $form = $this->get('form.factory')->create(new GenerateBundleType(), $bundle);
     if ('POST' == $request->getMethod()) {
         $form->bindRequest($request);
         if ($form->isValid()) {
             $namespace = $bundle->namespace_vendor . "\\" . $bundle->namespace_bundle;
             $dir = '/' === substr($bundle->dir, -1, 1) ? $bundle->dir : $bundle->dir . '/';
             if (!$this->get('filesystem')->isAbsolutePath($dir)) {
                 $dir = dirname($this->get('kernel')->getRootDir()) . '/' . $dir;
             }
             $generator = new BundleGenerator($this->get('filesystem'), $this->get('kernel')->locateResource('@SensioGeneratorBundle/Resources/skeleton/bundle'));
             $generator->generate($namespace, $bundle->bundle_name, $dir, $bundle->format, $bundle->structure);
             $request->getSession()->setFlash('notice', 'Your bundle has been generated.');
             return new RedirectResponse($this->generateUrl('_generator'));
         }
     }
     return array('form' => $form->createView());
 }
 public function testExistingEmptyDirIsFine()
 {
     $this->filesystem->mkdir($this->tmpDir . '/Foo/BarBundle');
     $generator = new BundleGenerator($this->filesystem, __DIR__ . '/../../Resources/skeleton/bundle');
     $generator->generate('Foo\\BarBundle', 'FooBarBundle', $this->tmpDir, 'yml', false);
 }
 protected function getGenerator()
 {
     $generator = new BundleGenerator($this->filesystem);
     $generator->setSkeletonDirs(__DIR__ . '/../../Resources/skeleton');
     return $generator;
 }
Example #6
0
 private function getInteractiveParameters(BundleGenerator $generator, InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelper('dialog');
     $formatter = $this->getHelper('formatter');
     $output->writeln($formatter->formatBlock('Welcome to the Symfony2 bundle generator', 'bg=blue;fg=white', true));
     // namespace
     $output->writeln(array('', 'Each bundle is hosted under a namespace (like <comment>Acme/Bundle/BlogBundle</comment>).', 'The namespace should begin with a "vendor" name like your company name, your', 'project name, or your client name, followed by one or more optional category', 'sub-namespaces, and it should end with the bundle name itself', '(which must have <comment>Bundle</comment> as a suffix).', ''));
     $namespace = $dialog->askAndValidate($output, $this->getQuestion('Bundle namespace', $input->getOption('namespace')), array($generator, 'validateNamespace'), false, $input->getOption('namespace'));
     $namespace = $generator->validateNamespace($namespace);
     // bundle name
     $bundle = $input->getOption('bundleName') ?: strtr($namespace, array('\\' => ''));
     $output->writeln(array('', 'In your code, a bundle is often referenced by its name. It can be the', 'concatenation of all namespace parts but it\'s really up to you to come', 'up with a unique name (a good practice is to start with the vendor name).', 'Based on the namespace, we suggest <comment>' . $bundle . '</comment>.', ''));
     $bundle = $dialog->askAndValidate($output, $this->getQuestion('Bundle name', $bundle), array($generator, 'validateBundleName'), false, $bundle);
     $bundle = $generator->validateBundleName($bundle);
     // target dir
     $dir = $input->getOption('dir') ?: dirname($this->container->getParameter('kernel.root_dir')) . '/src';
     $output->writeln(array('', 'The bundle can be generated anywhere, but remember to update the autoloader', 'accordingly. The suggested defaults uses the standard conventions.', ''));
     $dir = $dialog->askAndValidate($output, $this->getQuestion('Target directory', $dir), function ($dir) use($generator, $bundle, $namespace) {
         return $generator->validateTargetDir($dir, $bundle, $namespace);
     }, false, $dir);
     $dir = $generator->validateTargetDir($dir, $bundle, $namespace);
     // format
     $format = $input->getOption('format') ?: 'annotation';
     $output->writeln(array('', 'Determine the format to use for the generated configuration.', ''));
     $format = $dialog->askAndValidate($output, $this->getQuestion('Configuration format (yml, xml, php, or annotation)', $format), array($generator, 'validateFormat'), false, $format);
     $format = $generator->validateFormat($format);
     // optional files to generate
     $files = array();
     $output->writeln(array('', 'To help you getting started faster, the command can generate some', 'code snippets for you.', ''));
     if ($dialog->askConfirmation($output, $this->getQuestion('Do you want to generate a simple controller with a template', 'yes', '?'), true)) {
         $files[] = 'controller';
     }
     // FIXME: add more options
     // Controller with template and routing
     // Unit test, functional test (if controller)
     // config avec un service / parameters
     // CLI command
     // Doc avec .rst
     // Translations
     // assets
     // summary
     $output->writeln(array('', $formatter->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a \"<info>%s\\%s</info>\" bundle\nin \"<info>%s</info>\" using the \"<info>%s</info>\" format.", $namespace, $bundle, $dir, $format), ''));
     if (!$dialog->askConfirmation($output, $this->getQuestion('Do you confirm generation', 'no', '?'), false)) {
         $output->writeln('<error>Command aborted</error>');
         return false;
     }
     return array($namespace, $bundle, $dir, $format);
 }
 public function generate($namespace, $bundleName, $dir, $format, $structure)
 {
     return parent::generate($namespace, $bundleName, $dir, $format, $structure);
 }