Author: Fabien Potencier (fabien@symfony.com)
Author: Hugo Hamon (hugo.hamon@sensio.com)
Inheritance: extends Sensio\Bundle\GeneratorBundle\Generator\Generator
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $entity = Validators::validateEntityName($input->getArgument('entity'));
     list($bundle, $entity) = $this->parseShortcutNotation($entity);
     $entityClass = $this->getContainer()->get('doctrine')->getEntityNamespace($bundle) . '\\' . $entity;
     $metadata = $this->getEntityMetadata($entityClass);
     $bundle = $this->getApplication()->getKernel()->getBundle($bundle);
     $generator = new DoctrineFormGenerator($this->getContainer()->get('filesystem'), __DIR__ . '/../Resources/skeleton/form');
     $generator->generate($bundle, $entity, $metadata[0]);
     $output->writeln(sprintf('The new %s.php class file has been created under %s.', $generator->getClassName(), $generator->getClassPath()));
 }
 private function generateSubNamespacedEntityForm($overwrite)
 {
     $generator = new DoctrineFormGenerator($this->filesystem);
     $generator->setSkeletonDirs(__DIR__ . '/../../Resources/skeleton');
     $bundle = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface')->getMock();
     $bundle->expects($this->any())->method('getPath')->will($this->returnValue($this->tmpDir));
     $bundle->expects($this->any())->method('getNamespace')->will($this->returnValue('Foo\\BarBundle'));
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
     $metadata->identifier = array('id');
     $metadata->fieldMappings = array('title' => array('type' => 'string'), 'createdAt' => array('type' => 'date'), 'publishedAt' => array('type' => 'time'), 'updatedAt' => array('type' => 'datetime'));
     $metadata->associationMappings = $metadata->fieldMappings;
     $generator->generate($bundle, 'Blog\\Post', $metadata, $overwrite);
 }
 public function testGenerate()
 {
     $generator = new DoctrineFormGenerator($this->filesystem, __DIR__ . '/../../Resources/skeleton/form');
     $bundle = $this->getMock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface');
     $bundle->expects($this->any())->method('getPath')->will($this->returnValue($this->tmpDir));
     $bundle->expects($this->any())->method('getNamespace')->will($this->returnValue('Foo\\BarBundle'));
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
     $metadata->identifier = array('id');
     $metadata->associationMappings = array('title' => array('type' => 'string'));
     $generator->generate($bundle, 'Post', $metadata);
     $this->assertTrue(file_exists($this->tmpDir . '/Form/PostType.php'));
     $content = file_get_contents($this->tmpDir . '/Form/PostType.php');
     $this->assertContains('->add(\'title\')', $content);
     $this->assertContains('class PostType extends AbstractType', $content);
 }
 /**
  * @Route("/form", name="_generator_form")
  * @Template()
  */
 public function generateAction()
 {
     $request = $this->get('request');
     $formEntity = new Form();
     $form = $this->get('form.factory')->create(new GenerateFormType(), $formEntity);
     if ('POST' == $request->getMethod()) {
         $form->bindRequest($request);
         if ($form->isValid()) {
             $bundle = $this->get('kernel')->getBundle($formEntity->bundle_name);
             $entityClass = $bundle->getNamespace() . '\\Entity\\' . $formEntity->entity_name;
             $metadata = $this->getEntityMetadata($entityClass);
             $generator = new DoctrineFormGenerator($this->get('filesystem'), $this->get('kernel')->locateResource('@SensioGeneratorBundle/Resources/skeleton/form'));
             $generator->generate($bundle, $formEntity->entity_name, $metadata[0]);
             $request->getSession()->setFlash('notice', sprintf("Your form based on entity '%s' has been generated.", $formEntity->entity_name));
             return new RedirectResponse($this->generateUrl('_generator'));
         }
     }
     return array('form' => $form->createView());
 }