protected function generateOrmSerializer(OutputInterface $output, BundleMetadata $bundleMetadata) { $names = $bundleMetadata->getOrmMetadata()->getEntityNames(); if (is_array($names) && count($names) > 0) { $output->writeln(' - Generating ORM serializer files'); foreach ($names as $name) { $destFile = sprintf('%s/Entity.%s.xml', $bundleMetadata->getOrmMetadata()->getExtendedSerializerDirectory(), $name); $this->writeSerializerFile($output, $bundleMetadata, $this->entitySerializerTemplate, $destFile, $name); } } }
public function testBundleMetadata() { $bundle = new \Sonata\AcmeBundle\SonataAcmeBundle(); $bundleMetadata = new BundleMetadata($bundle, array('application_dir' => 'app/Application')); $this->assertTrue($bundleMetadata->isExtendable()); $this->assertTrue($bundleMetadata->isValid()); $this->assertEquals('SonataAcmeBundle', $bundleMetadata->getName()); $this->assertEquals('Sonata', $bundleMetadata->getVendor()); $this->assertEquals('Sonata\\AcmeBundle', $bundleMetadata->getNamespace()); $this->assertEquals('app/Application/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory()); $this->assertEquals('Application\\Sonata\\AcmeBundle', $bundleMetadata->getExtendedNamespace()); $this->assertInstanceOf('Sonata\\EasyExtendsBundle\\Bundle\\OrmMetadata', $bundleMetadata->getOrmMetadata()); $this->assertInstanceOf('Sonata\\EasyExtendsBundle\\Bundle\\OdmMetadata', $bundleMetadata->getOdmMetadata()); $this->assertSame($bundle, $bundleMetadata->getBundle()); }
/** * @param OutputInterface $output * @param BundleMetadata $bundleMetadata */ public function generateEntityRepositoryFiles(OutputInterface $output, BundleMetadata $bundleMetadata) { $output->writeln(' - Generating entity repository files'); $names = $bundleMetadata->getOrmMetadata()->getEntityNames(); foreach ($names as $name) { $dest_file = sprintf('%s/%sRepository.php', $bundleMetadata->getOrmMetadata()->getExtendedEntityDirectory(), $name); $src_file = sprintf('%s/Base%sRepository.php', $bundleMetadata->getOrmMetadata()->getEntityDirectory(), $name); if (!is_file($src_file)) { $output->writeln(sprintf(' ! <info>%sRepository</info>', $name)); continue; } if (is_file($dest_file)) { $output->writeln(sprintf(' ~ <info>%sRepository</info>', $name)); } else { $output->writeln(sprintf(' + <info>%sRepository</info>', $name)); $string = Mustache::replace($this->getEntityRepositoryTemplate(), array('extended_namespace' => $bundleMetadata->getExtendedNamespace(), 'name' => $name, 'namespace' => $bundleMetadata->getNamespace())); file_put_contents($dest_file, $string); } } }