Refactored RepositoryManager
Conflicts: Doctrine/RepositoryManager.php Manager/RepositoryManager.php
This commit is contained in:
parent
bb87a0be74
commit
47440b59bb
|
@ -4,7 +4,6 @@ namespace FOQ\ElasticaBundle\Manager;
|
||||||
|
|
||||||
use Doctrine\Common\Annotations\Reader;
|
use Doctrine\Common\Annotations\Reader;
|
||||||
use FOQ\ElasticaBundle\Finder\FinderInterface;
|
use FOQ\ElasticaBundle\Finder\FinderInterface;
|
||||||
use FOQ\ElasticaBundle\Repository;
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
/**
|
/**
|
||||||
* @author Richard Miller <info@limethinking.co.uk>
|
* @author Richard Miller <info@limethinking.co.uk>
|
||||||
|
@ -46,36 +45,30 @@ class RepositoryManager implements RepositoryManagerInterface
|
||||||
throw new RuntimeException(sprintf('No search finder configured for %s', $entityName));
|
throw new RuntimeException(sprintf('No search finder configured for %s', $entityName));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setRepositoryFromAnnotation($entityName);
|
$repositoryName = $this->getRepositoryName($entityName);
|
||||||
|
if (!class_exists($repositoryName)) {
|
||||||
if (isset($this->entities[$entityName]['repositoryName'])) {
|
throw new RuntimeException(sprintf('%s repository for %s does not exist', $repositoryName, $entityName));
|
||||||
|
|
||||||
$repositoryName = $this->entities[$entityName]['repositoryName'];
|
|
||||||
if (!class_exists($repositoryName)) {
|
|
||||||
throw new RuntimeException(sprintf('%s repository for %s does not exist', $repositoryName, $entityName));
|
|
||||||
}
|
|
||||||
$repository = new $repositoryName($this->entities[$entityName]['finder']);
|
|
||||||
$this->repositories[$entityName] = $repository;
|
|
||||||
return $repository;
|
|
||||||
}
|
}
|
||||||
|
$repository = new $repositoryName($this->entities[$entityName]['finder']);
|
||||||
$repository = new Repository($this->entities[$entityName]['finder']);
|
|
||||||
$this->repositories[$entityName] = $repository;
|
$this->repositories[$entityName] = $repository;
|
||||||
|
|
||||||
return $repository;
|
return $repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setRepositoryFromAnnotation($realEntityName)
|
protected function getRepositoryName($realEntityName)
|
||||||
{
|
{
|
||||||
if (isset($this->entities[$realEntityName]['repositoryName'])) {
|
if (isset($this->entities[$realEntityName]['repositoryName'])) {
|
||||||
return;
|
return $this->entities[$realEntityName]['repositoryName'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$refClass = new \ReflectionClass($realEntityName);
|
$refClass = new \ReflectionClass($realEntityName);
|
||||||
$annotation = $this->reader->getClassAnnotation($refClass, 'FOQ\\ElasticaBundle\\Configuration\\Search');
|
$annotation = $this->reader->getClassAnnotation($refClass, 'FOQ\\ElasticaBundle\\Configuration\\Search');
|
||||||
if ($annotation) {
|
if ($annotation) {
|
||||||
$this->entities[$realEntityName]['repositoryName']
|
$this->entities[$realEntityName]['repositoryName']
|
||||||
= $annotation->repositoryClass;
|
= $annotation->repositoryClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 'FOQ\ElasticaBundle\Repository';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue