1 | <?php |
||
19 | class OdmGenerator implements GeneratorInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $documentTemplate; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $documentRepositoryTemplate; |
||
30 | |||
31 | public function __construct() |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function generate(OutputInterface $output, BundleMetadata $bundleMetadata): void |
||
46 | |||
47 | public function getDocumentTemplate(): string |
||
51 | |||
52 | public function getDocumentRepositoryTemplate(): string |
||
56 | |||
57 | protected function generateMappingDocumentFiles(OutputInterface $output, BundleMetadata $bundleMetadata): string |
||
93 | |||
94 | protected function generateDocumentFiles(OutputInterface $output, BundleMetadata $bundleMetadata): string |
||
95 | { |
||
96 | $output->writeln(' - Generating document files'); |
||
97 | |||
98 | $names = $bundleMetadata->getOdmMetadata()->getDocumentNames(); |
||
99 | |||
100 | foreach ($names as $name) { |
||
101 | $extendedName = $name; |
||
102 | |||
103 | $dest_file = sprintf('%s/%s.php', $bundleMetadata->getOdmMetadata()->getExtendedDocumentDirectory(), $name); |
||
104 | $src_file = sprintf('%s/%s.php', $bundleMetadata->getOdmMetadata()->getDocumentDirectory(), $extendedName); |
||
105 | |||
106 | if (!is_file($src_file)) { |
||
107 | $extendedName = 'Base'.$name; |
||
108 | $src_file = sprintf('%s/%s.php', $bundleMetadata->getOdmMetadata()->getDocumentDirectory(), $extendedName); |
||
109 | |||
110 | if (!is_file($src_file)) { |
||
111 | $output->writeln(sprintf(' ! <info>%s</info>', $extendedName)); |
||
112 | |||
113 | continue; |
||
114 | } |
||
115 | } |
||
116 | |||
117 | if (is_file($dest_file)) { |
||
118 | $output->writeln(sprintf(' ~ <info>%s</info>', $name)); |
||
119 | } else { |
||
120 | $output->writeln(sprintf(' + <info>%s</info>', $name)); |
||
121 | |||
122 | $string = Mustache::replace($this->getDocumentTemplate(), [ |
||
123 | 'extended_namespace' => $bundleMetadata->getExtendedNamespace(), |
||
124 | 'name' => $extendedName, |
||
125 | 'class' => $name, |
||
126 | 'extended_name' => $name === $extendedName ? 'Base'.$name : $extendedName, |
||
127 | 'namespace' => $bundleMetadata->getNamespace(), |
||
128 | ]); |
||
129 | |||
130 | file_put_contents($dest_file, $string); |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | |||
135 | protected function generateDocumentRepositoryFiles(OutputInterface $output, BundleMetadata $bundleMetadata): string |
||
174 | } |
||
175 |