1 | <?php |
||
34 | class ODM extends Component implements ODMInterface, SingletonInterface |
||
35 | { |
||
36 | /** |
||
37 | * Memory section to store ODM schema. |
||
38 | */ |
||
39 | const MEMORY = 'odm.schema'; |
||
40 | |||
41 | /** |
||
42 | * Already created instantiators. |
||
43 | * |
||
44 | * @invisible |
||
45 | * @var InstantiatorInterface[] |
||
46 | */ |
||
47 | private $instantiators = []; |
||
48 | |||
49 | /** |
||
50 | * ODM schema. |
||
51 | * |
||
52 | * @invisible |
||
53 | * @var array |
||
54 | */ |
||
55 | private $schema = []; |
||
56 | |||
57 | /** |
||
58 | * @var MongoManager |
||
59 | */ |
||
60 | protected $manager; |
||
61 | |||
62 | /** |
||
63 | * @var LocatorInterface |
||
64 | */ |
||
65 | protected $locator; |
||
66 | |||
67 | /** |
||
68 | * @invisible |
||
69 | * @var MemoryInterface |
||
70 | */ |
||
71 | protected $memory; |
||
72 | |||
73 | /** |
||
74 | * Container defines working scope for all Documents and DocumentEntities. |
||
75 | * |
||
76 | * @var ContainerInterface |
||
77 | */ |
||
78 | protected $container; |
||
79 | |||
80 | /** |
||
81 | * @param MongoManager $manager |
||
82 | * @param LocatorInterface $locator |
||
83 | * @param MemoryInterface $memory |
||
84 | * @param ContainerInterface $container |
||
85 | */ |
||
86 | public function __construct( |
||
101 | |||
102 | /** |
||
103 | * Create instance of ORM SchemaBuilder. |
||
104 | * |
||
105 | * @param bool $locate Set to true to automatically locate available documents and document |
||
106 | * sources in a project files (based on tokenizer scope). |
||
107 | * |
||
108 | * @return SchemaBuilder |
||
109 | * |
||
110 | * @throws SchemaException |
||
111 | */ |
||
112 | public function schemaBuilder(bool $locate = true): SchemaBuilder |
||
131 | |||
132 | /** |
||
133 | * Specify behaviour schema for ODM to be used. |
||
134 | * |
||
135 | * @param SchemaBuilder $builder |
||
136 | * @param bool $remember Set to true to remember packed schema in memory. |
||
137 | */ |
||
138 | public function setSchema(SchemaBuilder $builder, bool $remember = false) |
||
139 | { |
||
140 | $this->schema = $builder->packSchema(); |
||
141 | |||
142 | if ($remember) { |
||
143 | $this->memory->saveData(static::MEMORY, $this->schema); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | public function define(string $class, int $property) |
||
168 | |||
169 | /** |
||
170 | * Get source (selection repository) for specific entity class. |
||
171 | * |
||
172 | * @param string $class |
||
173 | * |
||
174 | * @return DocumentSource |
||
175 | */ |
||
176 | public function source(string $class): DocumentSource |
||
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | public function selector(string $class): DocumentSelector |
||
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | public function collection(string $class): Collection |
||
221 | |||
222 | /** |
||
223 | * {@inheritdoc} |
||
224 | */ |
||
225 | public function make( |
||
232 | |||
233 | /** |
||
234 | * Get object responsible for class instantiation. |
||
235 | * |
||
236 | * @param string $class |
||
237 | * |
||
238 | * @return InstantiatorInterface |
||
239 | */ |
||
240 | protected function instantiator(string $class): InstantiatorInterface |
||
259 | |||
260 | /** |
||
261 | * Load packed schema from memory. |
||
262 | * |
||
263 | * @return array |
||
264 | */ |
||
265 | protected function loadSchema(): array |
||
269 | |||
270 | /** |
||
271 | * Get ODM specific factory. |
||
272 | * |
||
273 | * @return FactoryInterface |
||
274 | */ |
||
275 | protected function getFactory(): FactoryInterface |
||
283 | |||
284 | /** |
||
285 | * Create valid MongoId (ObjectID now) object based on string or id provided from client side. |
||
286 | * |
||
287 | * @param mixed $mongoID String or MongoId object. |
||
288 | * |
||
289 | * @return ObjectID|null |
||
290 | */ |
||
291 | public static function mongoID($mongoID) |
||
312 | } |