1 | <?php |
||
31 | final class Orm |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * @var MappersMap|EntityMapperInterface[] |
||
36 | */ |
||
37 | private $mappers; |
||
38 | |||
39 | /** |
||
40 | * @var Orm |
||
41 | */ |
||
42 | private static $instance; |
||
43 | |||
44 | /** |
||
45 | * @var AdaptersMap |
||
46 | */ |
||
47 | private $adapters; |
||
48 | |||
49 | /** |
||
50 | * @var RepositoryMap |
||
51 | */ |
||
52 | private $repositories; |
||
53 | |||
54 | /** |
||
55 | * @var EmittersMap |
||
56 | */ |
||
57 | private $emitters; |
||
58 | |||
59 | /** |
||
60 | * Initialize Orm registry with empty lists |
||
61 | */ |
||
62 | 2 | private function __construct() |
|
69 | |||
70 | /** |
||
71 | * Avoid clone on a singleton |
||
72 | * @codeCoverageIgnore |
||
73 | */ |
||
74 | private function __clone() |
||
78 | |||
79 | /** |
||
80 | * Gets a ORM registry instance |
||
81 | * |
||
82 | * @return Orm |
||
83 | */ |
||
84 | 16 | public static function getInstance() |
|
91 | |||
92 | /** |
||
93 | * Retrieves the mapper for provided entity |
||
94 | * |
||
95 | * If mapper does not exists it will be created and stored in the |
||
96 | * mapper map. |
||
97 | * |
||
98 | * @param String $entity |
||
99 | * @return EntityMapper |
||
100 | */ |
||
101 | 6 | public static function getMapper($entity) |
|
105 | |||
106 | /** |
||
107 | * Gets repository for provided entity class name |
||
108 | * |
||
109 | * @param string $entityClass FQ entity class name |
||
110 | * |
||
111 | * @return EntityRepository |
||
112 | * |
||
113 | * @throws InvalidArgumentException If provide class name is not |
||
114 | * from a class that implements the EntityInterface interface. |
||
115 | */ |
||
116 | 8 | public static function getRepository($entityClass) |
|
120 | |||
121 | /** |
||
122 | * Gets event emitter for provided entity class |
||
123 | * |
||
124 | * @param string $entityClass FQ entity class name |
||
125 | * |
||
126 | * @return Emitter |
||
127 | */ |
||
128 | 4 | public static function getEmitter($entityClass) |
|
132 | |||
133 | /** |
||
134 | * Add a listener for an entity event. |
||
135 | * |
||
136 | * The $event parameter should be the event name, and the second should be |
||
137 | * the event listener. It may implement the League\Event\ListenerInterface |
||
138 | * or simply be "callable". In this case, the priority emitter also accepts |
||
139 | * an optional third parameter specifying the priority as an integer. You |
||
140 | * may use one of EmitterInterface predefined constants here if you want. |
||
141 | * |
||
142 | * @param string|EntityInterface $entityClass |
||
143 | * @param string $event |
||
144 | * @param ListenerInterface|callable $listener |
||
145 | * @param int $priority |
||
146 | * |
||
147 | * @return EmitterInterface |
||
148 | */ |
||
149 | public static function addListener( |
||
154 | |||
155 | /** |
||
156 | * Add a listener for an entity event. |
||
157 | * |
||
158 | * The $event parameter should be the event name, and the second should be |
||
159 | * the event listener. It may implement the League\Event\ListenerInterface |
||
160 | * or simply be "callable". In this case, the priority emitter also accepts |
||
161 | * an optional third parameter specifying the priority as an integer. You |
||
162 | * may use one of EmitterInterface predefined constants here if you want. |
||
163 | * |
||
164 | * @param string|EntityInterface $entityClass |
||
165 | * @param string $event |
||
166 | * @param ListenerInterface|callable $listener |
||
167 | * @param int $priority |
||
168 | * |
||
169 | * @return EmitterInterface |
||
170 | */ |
||
171 | public function addListenerFor( |
||
180 | |||
181 | /** |
||
182 | * Gets repository for provided entity class name |
||
183 | * |
||
184 | * @param string $entityClass FQ entity class name |
||
185 | * |
||
186 | * @return EntityRepository |
||
187 | * |
||
188 | * @throws InvalidArgumentException If provide class name is not |
||
189 | * from a class that implements the EntityInterface interface. |
||
190 | */ |
||
191 | 8 | public function getRepositoryFor($entityClass) |
|
204 | |||
205 | /** |
||
206 | * Creates a repository for provided entity class name |
||
207 | * |
||
208 | * @param string $entityClass |
||
209 | * @return EntityRepository |
||
210 | */ |
||
211 | 2 | private function createRepository($entityClass) |
|
223 | |||
224 | /** |
||
225 | * Retrieves the mapper for provided entity |
||
226 | * |
||
227 | * If mapper does not exists it will be created and stored in the |
||
228 | * mapper map. |
||
229 | * |
||
230 | * @param string $entity |
||
231 | * @return EntityMapper |
||
232 | */ |
||
233 | 8 | public function getMapperFor($entity) |
|
239 | |||
240 | /** |
||
241 | * Gets the event emitter for provided entity |
||
242 | * |
||
243 | * @param string $entity |
||
244 | * |
||
245 | * @return Emitter |
||
246 | */ |
||
247 | 4 | public function getEmitterFor($entity) |
|
253 | |||
254 | /** |
||
255 | * Sets default adapter |
||
256 | * |
||
257 | * @param AdapterInterface $adapter |
||
258 | * @return $this|Orm|self |
||
259 | */ |
||
260 | 10 | public function setDefaultAdapter(AdapterInterface $adapter) |
|
264 | |||
265 | /** |
||
266 | * Sets an adapter mapped with alias name |
||
267 | * |
||
268 | * @param string $alias |
||
269 | * @param AdapterInterface $adapter |
||
270 | * |
||
271 | * @return $this|Orm|self |
||
272 | */ |
||
273 | 10 | public function setAdapter($alias, AdapterInterface $adapter) |
|
278 | |||
279 | /** |
||
280 | * Creates entity map for provided entity |
||
281 | * |
||
282 | * @param string $entity |
||
283 | * @return EntityMapper |
||
284 | */ |
||
285 | 4 | private function createMapper($entity) |
|
297 | |||
298 | /** |
||
299 | * Creates an emitter for provided entity class name |
||
300 | * |
||
301 | * @param string $entity |
||
302 | * @return Emitter |
||
303 | */ |
||
304 | 2 | private function createEmitter($entity) |
|
310 | |||
311 | /** |
||
312 | * Gets the adapter alias for current working entity |
||
313 | * |
||
314 | * @param string $entity |
||
315 | * |
||
316 | * @return EntityDescriptor|string |
||
317 | */ |
||
318 | 6 | private function getAdapterAlias($entity) |
|
326 | } |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.