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 SchemaLocator |
||
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 EntityCache|null $cache |
||
89 | * @param LocatorInterface|null $locator |
||
90 | * @param MemoryInterface|null $memory |
||
91 | * @param ContainerInterface|null $container |
||
92 | */ |
||
93 | public function __construct( |
||
114 | |||
115 | /** |
||
116 | * Create version of ORM with different initial cache or disabled cache. |
||
117 | * |
||
118 | * @param EntityCache|null $cache |
||
119 | * |
||
120 | * @return ORM |
||
121 | */ |
||
122 | public function withCache(EntityCache $cache = null): ORM |
||
129 | |||
130 | /** |
||
131 | * Check if ORM has associated entity cache. |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function hasCache(): bool |
||
139 | |||
140 | /** |
||
141 | * Create instance of ORM SchemaBuilder. |
||
142 | * |
||
143 | * @param bool $locate Set to true to automatically locate available records and record sources |
||
144 | * sources in a project files (based on tokenizer scope). |
||
145 | * |
||
146 | * @return SchemaBuilder |
||
147 | * |
||
148 | * @throws SchemaException |
||
149 | */ |
||
150 | public function schemaBuilder(bool $locate = true): SchemaBuilder |
||
169 | |||
170 | /** |
||
171 | * Specify behaviour schema for ORM to be used. Attention, you have to call renderSchema() |
||
172 | * prior to passing builder into this method. |
||
173 | * |
||
174 | * @param SchemaBuilder $builder |
||
175 | * @param bool $remember Set to true to remember packed schema in memory. |
||
176 | */ |
||
177 | public function buildSchema(SchemaBuilder $builder, bool $remember = false) |
||
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | public function define(string $class, int $property) |
||
206 | |||
207 | /** |
||
208 | * {@inheritdoc} |
||
209 | */ |
||
210 | public function selector(string $class): RecordSelector |
||
215 | |||
216 | /** |
||
217 | * {@inheritdoc} |
||
218 | */ |
||
219 | public function table(string $class): Table |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | public function make( |
||
267 | |||
268 | /** |
||
269 | * {@inheritdoc} |
||
270 | */ |
||
271 | public function makeLoader(string $class, string $relation): LoaderInterface |
||
296 | |||
297 | /** |
||
298 | * When ORM is cloned we are automatically cloning it's cache as well to create |
||
299 | * new isolated area. Basically we have cache enabled per selection. |
||
300 | * |
||
301 | * @see RecordSelector::getIterator() |
||
302 | */ |
||
303 | public function __clone() |
||
308 | |||
309 | /** |
||
310 | * Get object responsible for class instantiation. |
||
311 | * |
||
312 | * @param string $class |
||
313 | * |
||
314 | * @return InstantiatorInterface |
||
315 | */ |
||
316 | protected function instantiator(string $class): InstantiatorInterface |
||
335 | |||
336 | /** |
||
337 | * Load packed schema from memory. |
||
338 | * |
||
339 | * @return array |
||
340 | */ |
||
341 | protected function loadSchema(): array |
||
345 | |||
346 | /** |
||
347 | * Get ODM specific factory. |
||
348 | * |
||
349 | * @return FactoryInterface |
||
350 | */ |
||
351 | protected function getFactory(): FactoryInterface |
||
359 | } |
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.