1 | <?php |
||
19 | class OrmGenerator implements GeneratorInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $entityTemplate; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $entityRepositoryTemplate; |
||
30 | |||
31 | public function __construct() |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function generate(OutputInterface $output, BundleMetadata $bundleMetadata): void |
||
46 | |||
47 | public function generateMappingEntityFiles(OutputInterface $output, BundleMetadata $bundleMetadata): void |
||
74 | |||
75 | public function generateEntityFiles(OutputInterface $output, BundleMetadata $bundleMetadata): void |
||
76 | { |
||
77 | $output->writeln(' - Generating entity files'); |
||
78 | |||
79 | $names = $bundleMetadata->getOrmMetadata()->getEntityNames(); |
||
80 | |||
81 | foreach ($names as $name) { |
||
82 | $extendedName = $name; |
||
83 | |||
84 | $dest_file = sprintf('%s/%s.php', $bundleMetadata->getOrmMetadata()->getExtendedEntityDirectory(), $name); |
||
85 | $src_file = sprintf('%s/%s.php', $bundleMetadata->getOrmMetadata()->getEntityDirectory(), $extendedName); |
||
86 | |||
87 | if (!is_file($src_file)) { |
||
88 | $extendedName = 'Base'.$name; |
||
89 | $src_file = sprintf('%s/%s.php', $bundleMetadata->getOrmMetadata()->getEntityDirectory(), $extendedName); |
||
90 | |||
91 | if (!is_file($src_file)) { |
||
92 | $output->writeln(sprintf(' ! <info>%s</info>', $extendedName)); |
||
93 | |||
94 | continue; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | if (is_file($dest_file)) { |
||
99 | $output->writeln(sprintf(' ~ <info>%s</info>', $name)); |
||
100 | } else { |
||
101 | $output->writeln(sprintf(' + <info>%s</info>', $name)); |
||
102 | |||
103 | $string = Mustache::replace($this->getEntityTemplate(), [ |
||
104 | 'extended_namespace' => $bundleMetadata->getExtendedNamespace(), |
||
105 | 'name' => $extendedName, |
||
106 | 'class' => $name, |
||
107 | 'extended_name' => $name === $extendedName ? 'Base'.$name : $extendedName, |
||
108 | 'namespace' => $bundleMetadata->getNamespace(), |
||
109 | ]); |
||
110 | |||
111 | file_put_contents($dest_file, $string); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | |||
116 | public function generateEntityRepositoryFiles(OutputInterface $output, BundleMetadata $bundleMetadata): void |
||
147 | |||
148 | public function getEntityTemplate(): string |
||
152 | |||
153 | public function getEntityRepositoryTemplate(): string |
||
157 | } |
||
158 |