|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Sensio\Bundle\GeneratorBundle\Command; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Console\Input\InputArgument; |
|
|
15 |
use Symfony\Component\Console\Input\InputOption; |
|
|
16 |
use Symfony\Component\Console\Input\InputInterface; |
|
|
17 |
use Symfony\Component\Console\Output\OutputInterface; |
|
|
18 |
use Symfony\Component\Console\Output\Output; |
|
|
19 |
use Symfony\Component\Console\Command\Command; |
|
|
20 |
use Symfony\Bundle\DoctrineBundle\Mapping\MetadataFactory; |
|
|
21 |
use Sensio\Bundle\GeneratorBundle\Generator\DoctrineFormGenerator; |
|
|
22 |
|
|
|
23 |
/** |
|
|
24 |
* Generates a form type class for a given Doctrine entity. |
|
|
25 |
* |
|
|
26 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
27 |
* @author Hugo Hamon <hugo.hamon@sensio.com> |
|
|
28 |
*/ |
|
|
29 |
class GenerateDoctrineFormCommand extends GenerateDoctrineCommand |
|
|
30 |
{ |
|
|
31 |
/** |
|
|
32 |
* @see Command |
|
|
33 |
*/ |
|
|
34 |
protected function configure() |
|
|
35 |
{ |
|
|
36 |
$this |
|
|
37 |
->setDefinition(array( |
|
|
38 |
new InputArgument('entity', InputArgument::REQUIRED, 'The entity class name to initialize (shortcut notation)'), |
|
|
39 |
)) |
|
|
40 |
->setDescription('Generates a form type class based on a Doctrine entity') |
|
|
41 |
->setHelp(<<<EOT |
|
|
42 |
The <info>doctrine:generate:form</info> command generates a form class based on a Doctrine entity. |
|
|
43 |
|
|
|
44 |
<info>php app/console doctrine:generate:form AcmeBlogBundle:Post</info> |
|
|
45 |
EOT |
|
|
46 |
) |
|
|
47 |
->setName('doctrine:generate:form') |
|
|
48 |
->setAliases(array('generate:doctrine:form')) |
|
|
49 |
; |
|
|
50 |
} |
|
|
51 |
|
|
|
52 |
/** |
|
|
53 |
* @see Command |
|
|
54 |
*/ |
|
|
55 |
protected function execute(InputInterface $input, OutputInterface $output) |
|
|
56 |
{ |
|
|
57 |
$entity = Validators::validateEntityName($input->getArgument('entity')); |
|
|
58 |
list($bundle, $entity) = $this->parseShortcutNotation($entity); |
|
|
59 |
|
|
|
60 |
$entityClass = $this->getContainer()->get('doctrine')->getEntityNamespace($bundle).'\\'.$entity; |
|
|
61 |
$metadata = $this->getEntityMetadata($entityClass); |
|
|
62 |
$bundle = $this->getApplication()->getKernel()->getBundle($bundle); |
|
|
63 |
|
|
|
64 |
$generator = new DoctrineFormGenerator($this->getContainer()->get('filesystem'), __DIR__.'/../Resources/skeleton/form'); |
|
|
65 |
$generator->generate($bundle, $entity, $metadata[0]); |
|
|
66 |
|
|
|
67 |
$output->writeln(sprintf( |
|
|
68 |
'The new %s.php class file has been created under %s.', |
|
|
69 |
$generator->getClassName(), |
|
|
70 |
$generator->getClassPath() |
|
|
71 |
)); |
|
|
72 |
} |
|
|
73 |
} |