1 | <?php |
||
21 | class EntityManagerRegistry extends AbstractManagerRegistry |
||
22 | { |
||
23 | /** |
||
24 | * Simple array container |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $container; |
||
28 | |||
29 | /** |
||
30 | * Fetches/creates the given services. |
||
31 | * |
||
32 | * A service in this context is connection or a manager instance. |
||
33 | * |
||
34 | * @param string $name The name of the service. |
||
35 | * @return object The instance of the given service. |
||
36 | */ |
||
37 | 26 | protected function getService($name) |
|
38 | { |
||
39 | 26 | if (!isset($this->container[$name])) |
|
40 | 26 | { |
|
41 | throw new \InvalidArgumentException(sprintf('Service named "%s" does not exist.', $name)); |
||
42 | } |
||
43 | 26 | return $this->container[$name]; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * Resets the given services. |
||
48 | * |
||
49 | * A service in this context is connection or a manager instance. |
||
50 | * |
||
51 | * @param string $name The name of the service. |
||
52 | * @return void |
||
53 | */ |
||
54 | protected function resetService($name) |
||
58 | |||
59 | /** |
||
60 | * Resolves a registered namespace alias to the full namespace. |
||
61 | * |
||
62 | * This method looks for the alias in all registered object managers. |
||
63 | * |
||
64 | * @param string $alias The alias. |
||
65 | * @return string The full namespace. |
||
66 | * @throws ORMException |
||
67 | */ |
||
68 | public function getAliasNamespace($alias) |
||
69 | { |
||
70 | foreach (array_keys($this->getManagers()) as $name) { |
||
71 | try { |
||
72 | if (($em = $this->getManager($name)) instanceof EntityManager) |
||
73 | { |
||
74 | return $em->getConfiguration()->getEntityNamespace($alias); |
||
75 | } |
||
76 | } catch (ORMException $e) { |
||
77 | // If any exception is throw when attempting to retrieve then have our custom one thrown |
||
78 | } |
||
79 | } |
||
80 | throw ORMException::unknownEntityNamespace($alias); |
||
81 | } |
||
82 | |||
83 | |||
84 | /** |
||
85 | * Set the service container |
||
86 | * @param $container |
||
87 | */ |
||
88 | 31 | public function setContainer($container) |
|
92 | |||
93 | /** |
||
94 | * Get a simple manager registry if you only use one $em |
||
95 | * It's advised you either extend or implement your own version of AbstractManagerRegistry |
||
96 | * for custom handling of varied services |
||
97 | * @param EntityManager $em |
||
98 | * @return EntityManagerRegistry |
||
99 | */ |
||
100 | 31 | public static function getSimpleManagerRegistry(EntityManager $em) |
|
113 | |||
114 | } |