1 | <?php |
||
18 | final class Persister implements PersisterInterface |
||
19 | { |
||
20 | const IDENTIFIER_KEY = '_id'; |
||
21 | const POLYMORPHIC_KEY = '_type'; |
||
22 | const PERSISTER_KEY = 'mongodb'; |
||
23 | |||
24 | /** |
||
25 | * Provides a map of changeset methods. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $changeSetMethods = [ |
||
30 | 'attributes' => ['getAttribute', 'getAttributeDbValue'], |
||
31 | 'hasOne' => ['getRelationship', 'getHasOneDbValue'], |
||
32 | 'hasMany' => ['getRelationship', 'getHasManyDbValue'], |
||
33 | 'embedOne' => ['getEmbed', 'getEmbedOneDbValue'], |
||
34 | 'embedMany' => ['getEmbed', 'getEmbedManyDbValue'], |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * The raw result hydrator. |
||
39 | * |
||
40 | * @var Hydrator |
||
41 | */ |
||
42 | private $hydrator; |
||
43 | |||
44 | /** |
||
45 | * @var SchemaManager |
||
46 | */ |
||
47 | private $schemaManager; |
||
48 | |||
49 | /** |
||
50 | * @var StorageMetadataFactory |
||
51 | */ |
||
52 | private $smf; |
||
53 | |||
54 | /** |
||
55 | * The query service. |
||
56 | * |
||
57 | * @var Query |
||
58 | */ |
||
59 | private $query; |
||
60 | |||
61 | /** |
||
62 | * Constructor. |
||
63 | * |
||
64 | * @param Query $query |
||
65 | * @param StorageMetadataFactory $smf |
||
66 | * @param Hydrator $hydrator |
||
67 | */ |
||
68 | public function __construct(Query $query, StorageMetadataFactory $smf, Hydrator $hydrator, SchemaManager $schemaManager) |
||
75 | |||
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | */ |
||
79 | public function all(EntityMetadata $metadata, Store $store, array $identifiers = [], array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
||
85 | |||
86 | /** |
||
87 | * {@inheritDoc} |
||
88 | */ |
||
89 | public function convertId($identifier, $strategy = null) |
||
93 | |||
94 | /** |
||
95 | * {@inheritDoc} |
||
96 | * @todo Optimize the changeset to query generation. |
||
97 | */ |
||
98 | public function create(Model $model) |
||
105 | |||
106 | /** |
||
107 | * {@inheritDoc} |
||
108 | */ |
||
109 | public function createSchemata(EntityMetadata $metadata) |
||
115 | |||
116 | /** |
||
117 | * {@inheritDoc} |
||
118 | */ |
||
119 | public function syncSchemata(EntityMetadata $metadata) |
||
125 | |||
126 | /** |
||
127 | * {@inheritDoc} |
||
128 | */ |
||
129 | public function delete(Model $model) |
||
136 | |||
137 | /** |
||
138 | * {@inheritDoc} |
||
139 | */ |
||
140 | public function extractType(EntityMetadata $metadata, array $data) |
||
144 | |||
145 | /** |
||
146 | * {@inheritDoc} |
||
147 | */ |
||
148 | public function generateId($strategy = null) |
||
155 | |||
156 | /** |
||
157 | * @return Formatter |
||
158 | */ |
||
159 | public function getFormatter() |
||
163 | |||
164 | /** |
||
165 | * @return Hydrator |
||
166 | */ |
||
167 | public function getHydrator() |
||
171 | |||
172 | /** |
||
173 | * {@inheritDoc} |
||
174 | */ |
||
175 | public function getIdentifierKey() |
||
179 | |||
180 | /** |
||
181 | * {@inheritDoc} |
||
182 | */ |
||
183 | public function getPersistenceMetadataFactory() |
||
187 | |||
188 | /** |
||
189 | * {@inheritDoc} |
||
190 | */ |
||
191 | public function getPersisterKey() |
||
195 | |||
196 | /** |
||
197 | * {@inheritDoc} |
||
198 | */ |
||
199 | public function getPolymorphicKey() |
||
203 | |||
204 | /** |
||
205 | * @return Query |
||
206 | */ |
||
207 | public function getQuery() |
||
211 | |||
212 | /** |
||
213 | * {@inheritDoc} |
||
214 | */ |
||
215 | public function inverse(EntityMetadata $owner, EntityMetadata $rel, Store $store, array $identifiers, $inverseField) |
||
221 | |||
222 | /** |
||
223 | * {@inheritDoc} |
||
224 | */ |
||
225 | public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
||
230 | |||
231 | /** |
||
232 | * {@inheritDoc} |
||
233 | */ |
||
234 | public function retrieve(EntityMetadata $metadata, $identifier, Store $store) |
||
240 | |||
241 | /** |
||
242 | * {@inheritDoc} |
||
243 | * @todo Optimize the changeset to query generation. |
||
244 | */ |
||
245 | public function update(Model $model) |
||
258 | |||
259 | /** |
||
260 | * Appends the change set values to a database object based on the provided handler. |
||
261 | * |
||
262 | * @param Model $model |
||
263 | * @param array $obj |
||
264 | * @param Closure $handler |
||
265 | * @return array |
||
266 | */ |
||
267 | private function appendChangeSet(Model $model, array $obj, Closure $handler) |
||
282 | |||
283 | /** |
||
284 | * Creates the database insert object for a Model. |
||
285 | * |
||
286 | * @param Model $model |
||
287 | * @return array |
||
288 | */ |
||
289 | private function createInsertObj(Model $model) |
||
300 | |||
301 | /** |
||
302 | * Creates the database update object for a Model. |
||
303 | * |
||
304 | * @param Model $model |
||
305 | * @return array |
||
306 | */ |
||
307 | private function createUpdateObj(Model $model) |
||
311 | |||
312 | /** |
||
313 | * Gets the change set handler Closure for create. |
||
314 | * |
||
315 | * @return Closure |
||
316 | */ |
||
317 | private function getCreateChangeSetHandler() |
||
326 | |||
327 | /** |
||
328 | * Gets the change set handler Closure for update. |
||
329 | * |
||
330 | * @return Closure |
||
331 | */ |
||
332 | private function getUpdateChangeSetHandler() |
||
344 | } |
||
345 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: