1 | <?php |
||
27 | final class Orm |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var MappersMap|EntityMapperInterface[] |
||
32 | */ |
||
33 | private $mappers; |
||
34 | |||
35 | /** |
||
36 | * @var Orm |
||
37 | */ |
||
38 | private static $instance; |
||
39 | |||
40 | /** |
||
41 | * @var AdaptersMap |
||
42 | */ |
||
43 | private $adapters; |
||
44 | |||
45 | /** |
||
46 | * @var RepositoryMap |
||
47 | */ |
||
48 | private $repositories; |
||
49 | |||
50 | /** |
||
51 | * Initialize Orm registry with empty lists |
||
52 | */ |
||
53 | 2 | private function __construct() |
|
59 | |||
60 | /** |
||
61 | * Avoid clone on a singleton |
||
62 | * @codeCoverageIgnore |
||
63 | */ |
||
64 | private function __clone() |
||
68 | |||
69 | /** |
||
70 | * Gets a ORM registry instance |
||
71 | * |
||
72 | * @return Orm |
||
73 | */ |
||
74 | 16 | public static function getInstance() |
|
81 | |||
82 | /** |
||
83 | * Retrieves the mapper for provided entity |
||
84 | * |
||
85 | * If mapper does not exists it will be created and stored in the |
||
86 | * mapper map. |
||
87 | * |
||
88 | * @param String $entity |
||
89 | * @return EntityMapper |
||
90 | */ |
||
91 | 6 | public static function getMapper($entity) |
|
95 | |||
96 | /** |
||
97 | * Gets repository for provided entity class name |
||
98 | * |
||
99 | * @param string $entityClass FQ entity class name |
||
100 | * |
||
101 | * @return EntityRepository |
||
102 | * |
||
103 | * @throws InvalidArgumentException If provide class name is not |
||
104 | * from a class that implements the EntityInterface interface. |
||
105 | */ |
||
106 | 8 | public static function getRepository($entityClass) |
|
110 | |||
111 | /** |
||
112 | * Gets repository for provided entity class name |
||
113 | * |
||
114 | * @param string $entityClass FQ entity class name |
||
115 | * |
||
116 | * @return EntityRepository |
||
117 | * |
||
118 | * @throws InvalidArgumentException If provide class name is not |
||
119 | * from a class that implements the EntityInterface interface. |
||
120 | */ |
||
121 | 8 | public function getRepositoryFor($entityClass) |
|
134 | |||
135 | /** |
||
136 | * Creates a repository for provided entity class name |
||
137 | * |
||
138 | * @param string $entityClass |
||
139 | * @return EntityRepository |
||
140 | */ |
||
141 | 2 | private function createRepository($entityClass) |
|
153 | |||
154 | /** |
||
155 | * Retrieves the mapper for provided entity |
||
156 | * |
||
157 | * If mapper does not exists it will be created and stored in the |
||
158 | * mapper map. |
||
159 | * |
||
160 | * @param string $entity |
||
161 | * @return EntityMapper |
||
162 | */ |
||
163 | 8 | public function getMapperFor($entity) |
|
169 | |||
170 | /** |
||
171 | * Sets default adapter |
||
172 | * |
||
173 | * @param AdapterInterface $adapter |
||
174 | * @return $this|Orm|self |
||
175 | */ |
||
176 | 10 | public function setDefaultAdapter(AdapterInterface $adapter) |
|
180 | |||
181 | /** |
||
182 | * Sets an adapter mapped with alias name |
||
183 | * |
||
184 | * @param string $alias |
||
185 | * @param AdapterInterface $adapter |
||
186 | * |
||
187 | * @return $this|Orm|self |
||
188 | */ |
||
189 | 10 | public function setAdapter($alias, AdapterInterface $adapter) |
|
194 | |||
195 | /** |
||
196 | * Creates entity map for provided entity |
||
197 | * |
||
198 | * @param string $entity |
||
199 | * @return EntityMapper |
||
200 | */ |
||
201 | 4 | private function createMapper($entity) |
|
213 | |||
214 | /** |
||
215 | * Gets the adapter alias for current working entity |
||
216 | * |
||
217 | * @param string $entity |
||
218 | * |
||
219 | * @return EntityDescriptor|string |
||
220 | */ |
||
221 | 6 | private function getAdapterAlias($entity) |
|
229 | } |