protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));
     try {
         $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('name'));
         $output->writeln(sprintf('Generating entities for bundle "<info>%s</info>"', $bundle->getName()));
         $metadata = $manager->getBundleMetadata($bundle);
     } catch (\InvalidArgumentException $e) {
         $name = strtr($input->getArgument('name'), '/', '\\');
         if (false !== ($pos = strpos($name, ':'))) {
             $name = $this->getContainer()->get('doctrine')->getEntityNamespace(substr($name, 0, $pos)) . '\\' . substr($name, $pos + 1);
         }
         if (class_exists($name)) {
             $output->writeln(sprintf('Generating entity "<info>%s</info>"', $name));
             $metadata = $manager->getClassMetadata($name, $input->getOption('path'));
         } else {
             $output->writeln(sprintf('Generating entities for namespace "<info>%s</info>"', $name));
             $metadata = $manager->getNamespaceMetadata($name, $input->getOption('path'));
         }
     }
     $generator = $this->getEntityGenerator();
     $generator->setBackupExisting(!$input->getOption('no-backup'));
     $repoGenerator = new EntityRepositoryGenerator();
     foreach ($metadata->getMetadata() as $m) {
         $output->writeln(sprintf('  > generating <comment>%s</comment>', $m->name));
         $generator->generate(array($m), $metadata->getPath());
         if ($m->customRepositoryClassName && false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())) {
             $repoGenerator->writeEntityRepositoryClass($m->customRepositoryClassName, $metadata->getPath());
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));
     try {
         $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('name'));
         $output->writeln(sprintf('Generating entities for bundle "<info>%s</info>"', $bundle->getName()));
         $metadata = $manager->getBundleMetadata($bundle);
     } catch (\InvalidArgumentException $e) {
         $name = strtr($input->getArgument('name'), '/', '\\');
         if (false !== ($pos = strpos($name, ':'))) {
             $name = $this->getContainer()->get('doctrine')->getEntityNamespace(substr($name, 0, $pos)) . '\\' . substr($name, $pos + 1);
         }
         if (class_exists($name)) {
             $output->writeln(sprintf('Generating entity "<info>%s</info>"', $name));
             $metadata = $manager->getClassMetadata($name, $input->getOption('path'));
         } else {
             $output->writeln(sprintf('Generating entities for namespace "<info>%s</info>"', $name));
             $metadata = $manager->getNamespaceMetadata($name, $input->getOption('path'));
         }
     }
     $generator = $this->getEntityGenerator();
     $backupExisting = !$input->getOption('no-backup');
     $generator->setBackupExisting($backupExisting);
     $repoGenerator = new EntityRepositoryGenerator();
     foreach ($metadata->getMetadata() as $m) {
         if ($backupExisting) {
             $basename = substr($m->name, strrpos($m->name, '\\') + 1);
             $output->writeln(sprintf('  > backing up <comment>%s.php</comment> to <comment>%s.php~</comment>', $basename, $basename));
         }
         // Getting the metadata for the entity class once more to get the correct path if the namespace has multiple occurrences
         try {
             $entityMetadata = $manager->getClassMetadata($m->getName(), $input->getOption('path'));
         } catch (\RuntimeException $e) {
             // fall back to the bundle metadata when no entity class could be found
             $entityMetadata = $metadata;
         }
         $output->writeln(sprintf('  > generating <comment>%s</comment>', $m->name));
         $generator->generate(array($m), $entityMetadata->getPath());
         if ($m->customRepositoryClassName && false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())) {
             $repoGenerator->writeEntityRepositoryClass($m->customRepositoryClassName, $metadata->getPath());
         }
     }
 }