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