1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\ElasticaBundle\Doctrine; |
13
|
|
|
|
14
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
15
|
|
|
use FOS\ElasticaBundle\Finder\FinderInterface; |
16
|
|
|
use FOS\ElasticaBundle\Manager\RepositoryManagerInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Richard Miller <[email protected]> |
20
|
|
|
* |
21
|
|
|
* Allows retrieval of basic or custom repository for mapped Doctrine |
22
|
|
|
* entities/documents |
23
|
|
|
*/ |
24
|
|
|
class RepositoryManager implements RepositoryManagerInterface |
25
|
|
|
{ |
26
|
|
|
/** @var array */ |
27
|
|
|
protected $entities = []; |
28
|
|
|
|
29
|
|
|
/** @var array */ |
30
|
|
|
protected $repositories = []; |
31
|
|
|
|
32
|
|
|
/** @var ManagerRegistry */ |
33
|
|
|
protected $managerRegistry; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var RepositoryManagerInterface |
37
|
|
|
*/ |
38
|
|
|
private $repositoryManager; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ManagerRegistry $managerRegistry |
42
|
|
|
* @param RepositoryManagerInterface $repositoryManager |
43
|
|
|
*/ |
44
|
1 |
|
public function __construct(ManagerRegistry $managerRegistry, RepositoryManagerInterface $repositoryManager) |
45
|
|
|
{ |
46
|
1 |
|
$this->managerRegistry = $managerRegistry; |
47
|
1 |
|
$this->repositoryManager = $repositoryManager; |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function addType($indexTypeName, FinderInterface $finder, $repositoryName = null) |
54
|
|
|
{ |
55
|
|
|
throw new \LogicException(__METHOD__.' should not be called. Call addType on the main repository manager'); |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
public function addEntity($entityName, $indexTypeName) |
59
|
|
|
{ |
60
|
1 |
|
$this->entities[$entityName] = $indexTypeName; |
61
|
1 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns custom repository if one specified otherwise returns a basic repository. |
65
|
|
|
* |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
1 |
|
public function getRepository($entityName) |
69
|
|
|
{ |
70
|
1 |
|
$realEntityName = $entityName; |
71
|
1 |
|
if (false !== strpos($entityName, ':')) { |
72
|
|
|
list($namespaceAlias, $simpleClassName) = explode(':', $entityName); |
73
|
|
|
$realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias).'\\'.$simpleClassName; |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
if (isset($this->entities[$realEntityName])) { |
77
|
1 |
|
$realEntityName = $this->entities[$realEntityName]; |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
return $this->repositoryManager->getRepository($realEntityName); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function hasRepository($typeName): bool |
84
|
|
|
{ |
85
|
|
|
return $this->repositoryManager->hasRepository($typeName); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|