|
@@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputOption;
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
use Doctrine\ORM\Tools\EntityRepositoryGenerator;
|
|
|
+use Symfony\Bundle\DoctrineBundle\Mapping\MetadataFactory;
|
|
|
|
|
|
/**
|
|
|
* Generate entity classes from mapping information
|
|
@@ -69,87 +70,39 @@ EOT
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
{
|
|
|
+ $manager = new MetadataFactory($this->container->get('doctrine'));
|
|
|
+
|
|
|
try {
|
|
|
$bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('name'));
|
|
|
|
|
|
$output->writeln(sprintf('Generating entities for bundle "<info>%s</info>"', $bundle->getName()));
|
|
|
- list($metadatas, $namespace, $path) = $this->getBundleInfo($bundle);
|
|
|
+ $metadata = $manager->getBundleMetadata($bundle);
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
$name = strtr($input->getArgument('name'), '/', '\\');
|
|
|
|
|
|
- if (false !== strpos($name, ':')) {
|
|
|
- $name = $this->getAliasedClassName($name);
|
|
|
+ if (false !== $pos = strpos($name, ':')) {
|
|
|
+ $name = $this->container->get('doctrine')->getEntityNamespace(substr($name, 0, $pos)).'\\'.substr($name, $pos + 1);
|
|
|
}
|
|
|
|
|
|
if (class_exists($name)) {
|
|
|
$output->writeln(sprintf('Generating entity "<info>%s</info>"', $name));
|
|
|
- list($metadatas, $namespace, $path) = $this->getClassInfo($name, $input->getOption('path'));
|
|
|
+ $metadata = $manager->getClassMetadata($name, $input->getOption('path'));
|
|
|
} else {
|
|
|
$output->writeln(sprintf('Generating entities for namespace "<info>%s</info>"', $name));
|
|
|
- list($metadatas, $namespace, $path) = $this->getNamespaceInfo($name, $input->getOption('path'));
|
|
|
+ $metadata = $manager->getNamespaceMetadata($name, $input->getOption('path'));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$generator = $this->getEntityGenerator();
|
|
|
$generator->setBackupExisting(!$input->getOption('no-backup'));
|
|
|
$repoGenerator = new EntityRepositoryGenerator();
|
|
|
- foreach ($metadatas as $metadata) {
|
|
|
- $output->writeln(sprintf(' > generating <comment>%s</comment>', $metadata->name));
|
|
|
- $generator->generate(array($metadata), $path);
|
|
|
-
|
|
|
- if ($metadata->customRepositoryClassName) {
|
|
|
- if (false === strpos($metadata->customRepositoryClassName, $namespace)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ foreach ($metadata->getMetadata() as $m) {
|
|
|
+ $output->writeln(sprintf(' > generating <comment>%s</comment>', $m->name));
|
|
|
+ $generator->generate(array($m), $metadata->getPath());
|
|
|
|
|
|
- $repoGenerator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $path);
|
|
|
+ if ($m->customRepositoryClassName && false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())) {
|
|
|
+ $repoGenerator->writeEntityRepositoryClass($m->customRepositoryClassName, $metadata->getPath());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private function getBundleInfo($bundle)
|
|
|
- {
|
|
|
- $namespace = $bundle->getNamespace();
|
|
|
- if (!$metadatas = $this->findMetadatasByNamespace($namespace)) {
|
|
|
- throw new \RuntimeException(sprintf('Bundle "%s" does not contain any mapped entities.', $bundle->getName()));
|
|
|
- }
|
|
|
-
|
|
|
- $path = $this->findBasePathForClass($bundle->getName(), $bundle->getNamespace(), $bundle->getPath());
|
|
|
-
|
|
|
- return array($metadatas, $bundle->getNamespace(), $path);
|
|
|
- }
|
|
|
-
|
|
|
- private function getClassInfo($class, $path)
|
|
|
- {
|
|
|
- if (!$metadatas = $this->findMetadatasByClass($class)) {
|
|
|
- throw new \RuntimeException(sprintf('Entity "%s" is not a mapped entity.', $class));
|
|
|
- }
|
|
|
-
|
|
|
- if (class_exists($class)) {
|
|
|
- $r = $metadatas[$class]->getReflectionClass();
|
|
|
- $path = $this->findBasePathForClass($class, $r->getNamespacename(), dirname($r->getFilename()));
|
|
|
- } elseif (!$path) {
|
|
|
- throw new \RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $class));
|
|
|
- }
|
|
|
-
|
|
|
- return array($metadatas, $r->getNamespacename(), $path);
|
|
|
- }
|
|
|
-
|
|
|
- private function getNamespaceInfo($namespace, $path)
|
|
|
- {
|
|
|
- if (!$metadatas = $this->findMetadatasByNamespace($namespace)) {
|
|
|
- throw new \RuntimeException(sprintf('Namespace "%s" does not contain any mapped entities.', $namespace));
|
|
|
- }
|
|
|
-
|
|
|
- $first = reset($metadatas);
|
|
|
- $class = key($metadatas);
|
|
|
- if (class_exists($class)) {
|
|
|
- $r = $first->getReflectionClass();
|
|
|
- $path = $this->findBasePathForClass($namespace, $r->getNamespacename(), dirname($r->getFilename()));
|
|
|
- } elseif (!$path) {
|
|
|
- throw new \RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $class));
|
|
|
- }
|
|
|
-
|
|
|
- return array($metadatas, $namespace, $path);
|
|
|
- }
|
|
|
}
|