2011-12-23 16:29:01 +01:00
|
|
|
<?php
|
|
|
|
|
2013-03-27 18:44:06 +01:00
|
|
|
namespace FOS\ElasticaBundle\Doctrine;
|
2011-12-23 16:29:01 +01:00
|
|
|
|
|
|
|
use Doctrine\Common\Annotations\Reader;
|
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry;
|
2013-03-27 18:44:06 +01:00
|
|
|
use FOS\ElasticaBundle\Manager\RepositoryManager as BaseManager;
|
2011-12-23 16:29:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Richard Miller <info@limethinking.co.uk>
|
|
|
|
*
|
|
|
|
* Allows retrieval of basic or custom repository for mapped Doctrine
|
|
|
|
* entities/documents.
|
|
|
|
*/
|
|
|
|
class RepositoryManager extends BaseManager
|
|
|
|
{
|
|
|
|
protected $entities = array();
|
|
|
|
protected $repositories = array();
|
|
|
|
protected $managerRegistry;
|
|
|
|
|
|
|
|
public function __construct(ManagerRegistry $managerRegistry, Reader $reader)
|
|
|
|
{
|
|
|
|
$this->managerRegistry = $managerRegistry;
|
2011-12-24 15:44:37 +01:00
|
|
|
parent::__construct($reader);
|
2011-12-23 16:29:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-12 11:20:00 +01:00
|
|
|
* Return repository for entity.
|
2011-12-23 16:29:01 +01:00
|
|
|
*
|
|
|
|
* Returns custom repository if one specified otherwise
|
2013-04-26 14:15:57 +02:00
|
|
|
* returns a basic repository.
|
2011-12-23 16:29:01 +01:00
|
|
|
*/
|
|
|
|
public function getRepository($entityName)
|
|
|
|
{
|
|
|
|
$realEntityName = $entityName;
|
|
|
|
if (strpos($entityName, ':') !== false) {
|
|
|
|
list($namespaceAlias, $simpleClassName) = explode(':', $entityName);
|
2015-03-12 11:20:00 +01:00
|
|
|
$realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias).'\\'.$simpleClassName;
|
2011-12-23 16:29:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getRepository($realEntityName);
|
|
|
|
}
|
|
|
|
}
|