/**
  * @param OutputInterface $output
  * @param BundleMetadata  $bundleMetadata
  */
 protected function generateBundleFile(OutputInterface $output, BundleMetadata $bundleMetadata)
 {
     $file = sprintf('%s/Application%s.php', $bundleMetadata->getExtendedDirectory(), $bundleMetadata->getName());
     if (is_file($file)) {
         return;
     }
     $output->writeln(sprintf('  > generating bundle file <comment>%s</comment>', $file));
     $string = Mustache::replace($this->getBundleTemplate(), array('bundle' => $bundleMetadata->getName(), 'namespace' => $bundleMetadata->getExtendedNamespace()));
     file_put_contents($file, $string);
 }
 protected function writeSerializerFile(OutputInterface $output, BundleMetadata $bundleMetadata, $template, $destFile, $name)
 {
     if (is_file($destFile)) {
         $output->writeln(sprintf('   ~ <info>%s</info>', $name));
     } else {
         $output->writeln(sprintf('   + <info>%s</info>', $name));
         $string = Mustache::replace($template, array('name' => $name, 'namespace' => $bundleMetadata->getExtendedNamespace(), 'root_name' => strtolower(preg_replace('/[A-Z]/', '_\\0', $name))));
         file_put_contents($destFile, $string);
     }
 }
 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);
         }
     }
 }