14 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
14 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
15 use Symfony\Component\Console\Input\InputArgument; |
15 use Symfony\Component\Console\Input\InputArgument; |
16 use Symfony\Component\Console\Input\InputInterface; |
16 use Symfony\Component\Console\Input\InputInterface; |
17 use Symfony\Component\Console\Input\InputOption; |
17 use Symfony\Component\Console\Input\InputOption; |
18 use Symfony\Component\Console\Output\OutputInterface; |
18 use Symfony\Component\Console\Output\OutputInterface; |
19 use Mandango\Mondator\Definition\Definition; |
|
20 use Mandango\Mondator\Definition\Property; |
|
21 use Mandango\Mondator\Definition\Method; |
|
22 use Mandango\Mondator\Dumper; |
|
23 |
19 |
24 class GenerateDocumentClassCommand extends ContainerAwareCommand |
20 class GenerateDocumentClassCommand extends ContainerAwareCommand |
25 { |
21 { |
26 protected function configure() |
22 protected function configure() |
27 { |
23 { |
40 if(is_null($path) || strlen($path) == 0) |
36 if(is_null($path) || strlen($path) == 0) |
41 { |
37 { |
42 $path = realpath($this->getContainer()->get('kernel')->getRootDir()."/../src"); |
38 $path = realpath($this->getContainer()->get('kernel')->getRootDir()."/../src"); |
43 } |
39 } |
44 |
40 |
45 $definition = new Definition('IRI\Bundle\WikiTagBundle\Entity\Document'); |
41 $schema_utils = $this->getContainer()->get("wikitag.shema_utils"); |
46 |
42 |
47 $definition->setParentClass('\IRI\Bundle\WikiTagBundle\Model\Document'); |
43 $classCode = $schema_utils->generateDocumentClass(); |
48 |
|
49 $fields = $this->getContainer()->getParameter('wiki_tag.fields'); |
|
50 foreach ( $fields as $name => $field_def) |
|
51 { |
|
52 $property = new Property("private", $name, NULL); |
|
53 $definition->addProperty($property); |
|
54 |
|
55 $get_method = new Method("public", "get".ucfirst($name), NULL, <<<EOF |
|
56 return \$this->$name; |
|
57 EOF |
|
58 ); |
|
59 $definition->addMethod($get_method); |
|
60 |
|
61 $set_method = new Method("public", "set".ucfirst($name), "\$$name", <<<EOF |
|
62 \$this->$name = \$$name; |
|
63 EOF |
|
64 ); |
|
65 $definition->addMethod($set_method); |
|
66 |
|
67 } |
|
68 |
|
69 $dumper = new Dumper($definition); |
|
70 $classCode = $dumper->dump(); |
|
71 |
44 |
72 if($input->getOption('simulate')) |
45 if($input->getOption('simulate')) |
73 { |
46 { |
74 $output->writeln($classCode); |
47 $output->writeln($classCode); |
75 } |
48 } |