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

RepositoryManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 59
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addType() 0 4 1
A addEntity() 0 4 1
A getRepository() 0 14 3
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