1 | <?php |
||
28 | class ORM extends Component implements ORMInterface, SingletonInterface |
||
29 | { |
||
30 | /** |
||
31 | * Memory section to store ORM schema. |
||
32 | */ |
||
33 | const MEMORY = 'orm.schema'; |
||
34 | |||
35 | /** |
||
36 | * @invisible |
||
37 | * @var EntityCache|null |
||
38 | */ |
||
39 | private $cache = null; |
||
40 | |||
41 | /** |
||
42 | * @var LocatorInterface |
||
43 | */ |
||
44 | private $locator; |
||
45 | |||
46 | /** |
||
47 | * Already created instantiators. |
||
48 | * |
||
49 | * @invisible |
||
50 | * @var InstantiatorInterface[] |
||
51 | */ |
||
52 | private $instantiators = []; |
||
53 | |||
54 | /** |
||
55 | * ORM schema. |
||
56 | * |
||
57 | * @invisible |
||
58 | * @var array |
||
59 | */ |
||
60 | private $schema = []; |
||
61 | |||
62 | /** |
||
63 | * @var DatabaseManager |
||
64 | */ |
||
65 | protected $manager; |
||
66 | |||
67 | /** |
||
68 | * @var RelationsConfig |
||
69 | */ |
||
70 | protected $config; |
||
71 | |||
72 | /** |
||
73 | * @invisible |
||
74 | * @var MemoryInterface |
||
75 | */ |
||
76 | protected $memory; |
||
77 | |||
78 | /** |
||
79 | * Container defines working scope for all Documents and DocumentEntities. |
||
80 | * |
||
81 | * @var ContainerInterface |
||
82 | */ |
||
83 | protected $container; |
||
84 | |||
85 | /** |
||
86 | * @param DatabaseManager $manager |
||
87 | * @param RelationsConfig $config |
||
88 | * @param LocatorInterface|null $locator |
||
89 | * @param EntityCache|null $cache |
||
90 | * @param MemoryInterface|null $memory |
||
91 | * @param ContainerInterface|null $container |
||
92 | */ |
||
93 | public function __construct( |
||
115 | |||
116 | /** |
||
117 | * Create version of ORM with different initial cache or disabled cache. |
||
118 | * |
||
119 | * @param EntityCache|null $cache |
||
120 | * |
||
121 | * @return ORM |
||
122 | */ |
||
123 | public function withCache(EntityCache $cache = null): ORM |
||
130 | |||
131 | /** |
||
132 | * Check if ORM has associated entity cache. |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function hasCache(): bool |
||
140 | |||
141 | /** |
||
142 | * Create instance of ORM SchemaBuilder. |
||
143 | * |
||
144 | * @param bool $locate Set to true to automatically locate available records and record sources |
||
145 | * sources in a project files (based on tokenizer scope). |
||
146 | * |
||
147 | * @return SchemaBuilder |
||
148 | * |
||
149 | * @throws SchemaException |
||
150 | */ |
||
151 | public function schemaBuilder(bool $locate = true): SchemaBuilder |
||
170 | |||
171 | /** |
||
172 | * Specify behaviour schema for ORM to be used. Attention, you have to call renderSchema() |
||
173 | * prior to passing builder into this method. |
||
174 | * |
||
175 | * @param SchemaBuilder $builder |
||
176 | * @param bool $remember Set to true to remember packed schema in memory. |
||
177 | */ |
||
178 | public function buildSchema(SchemaBuilder $builder, bool $remember = false) |
||
186 | |||
187 | /** |
||
188 | * {@inheritdoc} |
||
189 | */ |
||
190 | public function define(string $class, int $property) |
||
207 | |||
208 | /** |
||
209 | * {@inheritdoc} |
||
210 | */ |
||
211 | public function selector(string $class): RecordSelector |
||
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | public function table(string $class): Table |
||
228 | |||
229 | /** |
||
230 | * {@inheritdoc} |
||
231 | */ |
||
232 | public function make( |
||
268 | |||
269 | /** |
||
270 | * {@inheritdoc} |
||
271 | */ |
||
272 | public function makeLoader(string $class, string $relation): LoaderInterface |
||
297 | |||
298 | public function makeRelation(string $class, string $relation): RelationInterface |
||
302 | |||
303 | /** |
||
304 | * When ORM is cloned we are automatically cloning it's cache as well to create |
||
305 | * new isolated area. Basically we have cache enabled per selection. |
||
306 | * |
||
307 | * @see RecordSelector::getIterator() |
||
308 | */ |
||
309 | public function __clone() |
||
314 | |||
315 | /** |
||
316 | * Get object responsible for class instantiation. |
||
317 | * |
||
318 | * @param string $class |
||
319 | * |
||
320 | * @return InstantiatorInterface |
||
321 | */ |
||
322 | protected function instantiator(string $class): InstantiatorInterface |
||
341 | |||
342 | /** |
||
343 | * Load packed schema from memory. |
||
344 | * |
||
345 | * @return array |
||
346 | */ |
||
347 | protected function loadSchema(): array |
||
351 | |||
352 | /** |
||
353 | * Get ODM specific factory. |
||
354 | * |
||
355 | * @return FactoryInterface |
||
356 | */ |
||
357 | protected function getFactory(): FactoryInterface |
||
365 | } |
||
366 |