Completed
Pull Request — master (#1119)
by Alessandro
06:26
created

RepositoryManager::addEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace FOS\ElasticaBundle\Doctrine;
4
5
use Doctrine\Common\Annotations\Reader;
6
use Doctrine\Common\Persistence\ManagerRegistry;
7
use FOS\ElasticaBundle\Finder\FinderInterface;
8
use FOS\ElasticaBundle\Manager\RepositoryManager as BaseManager;
9
use FOS\ElasticaBundle\Manager\RepositoryManagerInterface;
10
11
/**
12
 * @author Richard Miller <[email protected]>
13
 *
14
 * Allows retrieval of basic or custom repository for mapped Doctrine
15
 * entities/documents.
16
 *
17
 * @deprecated
18
 */
19
class RepositoryManager implements RepositoryManagerInterface
20
{
21
    /** @var array */
22
    protected $entities = array();
23
    
24
    /** @var array */
25
    protected $repositories = array();
26
    
27
    /** @var ManagerRegistry */
28
    protected $managerRegistry;
29
30 5
    /**
31
     * @var RepositoryManagerInterface
32 5
     */
33 5
    private $repositoryManager;
34 5
35
    /**
36
     * @param ManagerRegistry $managerRegistry
37
     * @param RepositoryManagerInterface $repositoryManager
38
     */
39
    public function __construct(ManagerRegistry $managerRegistry, RepositoryManagerInterface $repositoryManager)
40
    {
41 5
        $this->managerRegistry = $managerRegistry;
42
        $this->repositoryManager = $repositoryManager;
43 5
    }
44 5
45 1
    /**
46 1
     * @inheritDoc
47
     */
48
    public function addType($indexTypeName, FinderInterface $finder, $repositoryName = null)
49 5
    {
50
        throw new \LogicException(__METHOD__.' should not be called. Call addType on the main repository manager');
51
    }
52
53
    public function addEntity($entityName, $indexTypeName)
54
    {
55
        $this->entities[$entityName] = $indexTypeName;
56
    }
57
58
    /**
59
     * Returns custom repository if one specified otherwise returns a basic repository.
60
     *
61
     * {@inheritdoc}
62
     */
63
    public function getRepository($entityName)
64
    {
65
        $realEntityName = $entityName;
66
        if (strpos($entityName, ':') !== false) {
67
            list($namespaceAlias, $simpleClassName) = explode(':', $entityName);
68
            $realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias).'\\'.$simpleClassName;
69
        }
70
71
        if (isset($this->entities[$realEntityName])) {
72
            $realEntityName = $this->entities[$realEntityName];
73
        }
74
75
        return $this->repositoryManager->getRepository($realEntityName);
76
    }
77
}
78