Completed
Pull Request — master (#1125)
by
unknown
21:30
created

RepositoryManager::addEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
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
    /**
31
     * @var RepositoryManagerInterface
32
     */
33
    private $repositoryManager;
34
35
    /**
36
     * @param ManagerRegistry $managerRegistry
37
     * @param RepositoryManagerInterface $repositoryManager
38
     */
39 3
    public function __construct(ManagerRegistry $managerRegistry, RepositoryManagerInterface $repositoryManager)
40
    {
41 3
        $this->managerRegistry = $managerRegistry;
42 3
        $this->repositoryManager = $repositoryManager;
43 3
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function addType($indexTypeName, FinderInterface $finder, $repositoryName = null)
49
    {
50
        throw new \LogicException(__METHOD__.' should not be called. Call addType on the main repository manager');
51
    }
52
53 3
    public function addEntity($entityName, $indexTypeName)
54
    {
55 3
        $this->entities[$entityName] = $indexTypeName;
56 3
    }
57
58
    /**
59
     * Returns custom repository if one specified otherwise returns a basic repository.
60
     *
61
     * {@inheritdoc}
62
     */
63 3
    public function getRepository($entityName)
64
    {
65 3
        $realEntityName = $entityName;
66 3
        if (strpos($entityName, ':') !== false) {
67 1
            list($namespaceAlias, $simpleClassName) = explode(':', $entityName);
68 1
            $realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias).'\\'.$simpleClassName;
69
        }
70
71 3
        if (isset($this->entities[$realEntityName])) {
72 3
            $realEntityName = $this->entities[$realEntityName];
73
        }
74
75 3
        return $this->repositoryManager->getRepository($realEntityName);
76
    }
77
}
78