1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Doctrine Bundle |
5
|
|
|
* |
6
|
|
|
* The code was originally distributed inside the Symfony framework. |
7
|
|
|
* |
8
|
|
|
* (c) Fabien Potencier <[email protected]> |
9
|
|
|
* (c) Doctrine Project, Benjamin Eberlei <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Doctrine\Bundle\DoctrineBundle; |
16
|
|
|
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
18
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
19
|
|
|
use Symfony\Bridge\Doctrine\ManagerRegistry; |
20
|
|
|
use Doctrine\ORM\ORMException; |
21
|
|
|
use Doctrine\ORM\EntityManager; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* References all Doctrine connections and entity managers in a given Container. |
25
|
|
|
* |
26
|
|
|
* @author Fabien Potencier <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class Registry extends ManagerRegistry implements RegistryInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Construct. |
32
|
|
|
* |
33
|
|
|
* @param ContainerInterface $container |
34
|
|
|
* @param array $connections |
35
|
|
|
* @param array $entityManagers |
36
|
|
|
* @param string $defaultConnection |
37
|
|
|
* @param string $defaultEntityManager |
38
|
|
|
*/ |
39
|
|
|
public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager) |
40
|
|
|
{ |
41
|
|
|
$this->setContainer($container); |
42
|
|
|
|
43
|
|
|
parent::__construct('ORM', $connections, $entityManagers, $defaultConnection, $defaultEntityManager, 'Doctrine\ORM\Proxy\Proxy'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Gets the default entity manager name. |
48
|
|
|
* |
49
|
|
|
* @return string The default entity manager name |
50
|
|
|
* |
51
|
|
|
* @deprecated |
52
|
|
|
*/ |
53
|
|
|
public function getDefaultEntityManagerName() |
54
|
|
|
{ |
55
|
|
|
@trigger_error('getDefaultEntityManagerName is deprecated since Symfony 2.1. Use getDefaultManagerName instead', E_USER_DEPRECATED); |
|
|
|
|
56
|
|
|
|
57
|
|
|
return $this->getDefaultManagerName(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Gets a named entity manager. |
62
|
|
|
* |
63
|
|
|
* @param string $name The entity manager name (null for the default one) |
|
|
|
|
64
|
|
|
* |
65
|
|
|
* @return EntityManager |
66
|
|
|
* |
67
|
|
|
* @deprecated |
68
|
|
|
*/ |
69
|
|
|
public function getEntityManager($name = null) |
70
|
|
|
{ |
71
|
|
|
@trigger_error('getEntityManager is deprecated since Symfony 2.1. Use getManager instead', E_USER_DEPRECATED); |
|
|
|
|
72
|
|
|
|
73
|
|
|
return $this->getManager($name); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Gets an array of all registered entity managers |
78
|
|
|
* |
79
|
|
|
* @return EntityManager[] an array of all EntityManager instances |
|
|
|
|
80
|
|
|
* |
81
|
|
|
* @deprecated |
82
|
|
|
*/ |
83
|
|
|
public function getEntityManagers() |
84
|
|
|
{ |
85
|
|
|
@trigger_error('getEntityManagers is deprecated since Symfony 2.1. Use getManagers instead', E_USER_DEPRECATED); |
|
|
|
|
86
|
|
|
|
87
|
|
|
return $this->getManagers(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Resets a named entity manager. |
92
|
|
|
* |
93
|
|
|
* This method is useful when an entity manager has been closed |
94
|
|
|
* because of a rollbacked transaction AND when you think that |
95
|
|
|
* it makes sense to get a new one to replace the closed one. |
96
|
|
|
* |
97
|
|
|
* Be warned that you will get a brand new entity manager as |
98
|
|
|
* the existing one is not usable anymore. This means that any |
99
|
|
|
* other object with a dependency on this entity manager will |
100
|
|
|
* hold an obsolete reference. You can inject the registry instead |
101
|
|
|
* to avoid this problem. |
102
|
|
|
* |
103
|
|
|
* @param string $name The entity manager name (null for the default one) |
|
|
|
|
104
|
|
|
* |
105
|
|
|
* @return EntityManager |
|
|
|
|
106
|
|
|
* |
107
|
|
|
* @deprecated |
108
|
|
|
*/ |
109
|
|
|
public function resetEntityManager($name = null) |
110
|
|
|
{ |
111
|
|
|
@trigger_error('resetEntityManager is deprecated since Symfony 2.1. Use resetManager instead', E_USER_DEPRECATED); |
|
|
|
|
112
|
|
|
|
113
|
|
|
$this->resetManager($name); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Resolves a registered namespace alias to the full namespace. |
118
|
|
|
* |
119
|
|
|
* This method looks for the alias in all registered entity managers. |
120
|
|
|
* |
121
|
|
|
* @param string $alias The alias |
122
|
|
|
* |
123
|
|
|
* @return string The full namespace |
124
|
|
|
* |
125
|
|
|
* @deprecated |
126
|
|
|
*/ |
127
|
|
|
public function getEntityNamespace($alias) |
128
|
|
|
{ |
129
|
|
|
@trigger_error('getEntityNamespace is deprecated since Symfony 2.1. Use getAliasNamespace instead', E_USER_DEPRECATED); |
|
|
|
|
130
|
|
|
|
131
|
|
|
return $this->getAliasNamespace($alias); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Resolves a registered namespace alias to the full namespace. |
136
|
|
|
* |
137
|
|
|
* This method looks for the alias in all registered entity managers. |
138
|
|
|
* |
139
|
|
|
* @param string $alias The alias |
140
|
|
|
* |
141
|
|
|
* @return string The full namespace |
142
|
|
|
* |
143
|
|
|
* @see Configuration::getEntityNamespace |
144
|
|
|
*/ |
145
|
|
|
public function getAliasNamespace($alias) |
146
|
|
|
{ |
147
|
|
|
foreach (array_keys($this->getManagers()) as $name) { |
148
|
|
|
try { |
149
|
|
|
return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias); |
|
|
|
|
150
|
|
|
} catch (ORMException $e) { |
|
|
|
|
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
throw ORMException::unknownEntityNamespace($alias); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Gets all connection names. |
159
|
|
|
* |
160
|
|
|
* @return array An array of connection names |
161
|
|
|
* |
162
|
|
|
* @deprecated |
163
|
|
|
*/ |
164
|
|
|
public function getEntityManagerNames() |
165
|
|
|
{ |
166
|
|
|
@trigger_error('getEntityManagerNames is deprecated since Symfony 2.1. Use getManagerNames instead', E_USER_DEPRECATED); |
|
|
|
|
167
|
|
|
|
168
|
|
|
return $this->getManagerNames(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Gets the entity manager associated with a given class. |
173
|
|
|
* |
174
|
|
|
* @param string $class A Doctrine Entity class name |
175
|
|
|
* |
176
|
|
|
* @return EntityManager|null |
|
|
|
|
177
|
|
|
* |
178
|
|
|
* @deprecated |
179
|
|
|
*/ |
180
|
|
|
public function getEntityManagerForClass($class) |
181
|
|
|
{ |
182
|
|
|
@trigger_error('getEntityManagerForClass is deprecated since Symfony 2.1. Use getManagerForClass instead', E_USER_DEPRECATED); |
|
|
|
|
183
|
|
|
|
184
|
|
|
return $this->getManagerForClass($class); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: