Complex classes like ClassMetadata often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ClassMetadata, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
56 | /* final */ class ClassMetadata implements BaseClassMetadata |
||
57 | { |
||
58 | /* The Id generator types. */ |
||
59 | /** |
||
60 | * AUTO means Doctrine will automatically create a new \MongoDB\BSON\ObjectId instance for us. |
||
61 | */ |
||
62 | public const GENERATOR_TYPE_AUTO = 1; |
||
63 | |||
64 | /** |
||
65 | * INCREMENT means a separate collection is used for maintaining and incrementing id generation. |
||
66 | * Offers full portability. |
||
67 | */ |
||
68 | public const GENERATOR_TYPE_INCREMENT = 2; |
||
69 | |||
70 | /** |
||
71 | * UUID means Doctrine will generate a uuid for us. |
||
72 | */ |
||
73 | public const GENERATOR_TYPE_UUID = 3; |
||
74 | |||
75 | /** |
||
76 | * ALNUM means Doctrine will generate Alpha-numeric string identifiers, using the INCREMENT |
||
77 | * generator to ensure identifier uniqueness |
||
78 | */ |
||
79 | public const GENERATOR_TYPE_ALNUM = 4; |
||
80 | |||
81 | /** |
||
82 | * CUSTOM means Doctrine expect a class parameter. It will then try to initiate that class |
||
83 | * and pass other options to the generator. It will throw an Exception if the class |
||
84 | * does not exist or if an option was passed for that there is not setter in the new |
||
85 | * generator class. |
||
86 | * |
||
87 | * The class will have to implement IdGenerator. |
||
88 | */ |
||
89 | public const GENERATOR_TYPE_CUSTOM = 5; |
||
90 | |||
91 | /** |
||
92 | * NONE means Doctrine will not generate any id for us and you are responsible for manually |
||
93 | * assigning an id. |
||
94 | */ |
||
95 | public const GENERATOR_TYPE_NONE = 6; |
||
96 | |||
97 | /** |
||
98 | * Default discriminator field name. |
||
99 | * |
||
100 | * This is used for associations value for associations where a that do not define a "targetDocument" or |
||
101 | * "discriminatorField" option in their mapping. |
||
102 | */ |
||
103 | public const DEFAULT_DISCRIMINATOR_FIELD = '_doctrine_class_name'; |
||
104 | |||
105 | public const REFERENCE_ONE = 1; |
||
106 | public const REFERENCE_MANY = 2; |
||
107 | public const EMBED_ONE = 3; |
||
108 | public const EMBED_MANY = 4; |
||
109 | public const MANY = 'many'; |
||
110 | public const ONE = 'one'; |
||
111 | |||
112 | /** |
||
113 | * The types of storeAs references |
||
114 | */ |
||
115 | public const REFERENCE_STORE_AS_ID = 'id'; |
||
116 | public const REFERENCE_STORE_AS_DB_REF = 'dbRef'; |
||
117 | public const REFERENCE_STORE_AS_DB_REF_WITH_DB = 'dbRefWithDb'; |
||
118 | public const REFERENCE_STORE_AS_REF = 'ref'; |
||
119 | |||
120 | /* The inheritance mapping types */ |
||
121 | /** |
||
122 | * NONE means the class does not participate in an inheritance hierarchy |
||
123 | * and therefore does not need an inheritance mapping type. |
||
124 | */ |
||
125 | public const INHERITANCE_TYPE_NONE = 1; |
||
126 | |||
127 | /** |
||
128 | * SINGLE_COLLECTION means the class will be persisted according to the rules of |
||
129 | * <tt>Single Collection Inheritance</tt>. |
||
130 | */ |
||
131 | public const INHERITANCE_TYPE_SINGLE_COLLECTION = 2; |
||
132 | |||
133 | /** |
||
134 | * COLLECTION_PER_CLASS means the class will be persisted according to the rules |
||
135 | * of <tt>Concrete Collection Inheritance</tt>. |
||
136 | */ |
||
137 | public const INHERITANCE_TYPE_COLLECTION_PER_CLASS = 3; |
||
138 | |||
139 | /** |
||
140 | * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time |
||
141 | * by doing a property-by-property comparison with the original data. This will |
||
142 | * be done for all entities that are in MANAGED state at commit-time. |
||
143 | * |
||
144 | * This is the default change tracking policy. |
||
145 | */ |
||
146 | public const CHANGETRACKING_DEFERRED_IMPLICIT = 1; |
||
147 | |||
148 | /** |
||
149 | * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time |
||
150 | * by doing a property-by-property comparison with the original data. This will |
||
151 | * be done only for entities that were explicitly saved (through persist() or a cascade). |
||
152 | */ |
||
153 | public const CHANGETRACKING_DEFERRED_EXPLICIT = 2; |
||
154 | |||
155 | /** |
||
156 | * NOTIFY means that Doctrine relies on the entities sending out notifications |
||
157 | * when their properties change. Such entity classes must implement |
||
158 | * the <tt>NotifyPropertyChanged</tt> interface. |
||
159 | */ |
||
160 | public const CHANGETRACKING_NOTIFY = 3; |
||
161 | |||
162 | /** |
||
163 | * SET means that fields will be written to the database using a $set operator |
||
164 | */ |
||
165 | public const STORAGE_STRATEGY_SET = 'set'; |
||
166 | |||
167 | /** |
||
168 | * INCREMENT means that fields will be written to the database by calculating |
||
169 | * the difference and using the $inc operator |
||
170 | */ |
||
171 | public const STORAGE_STRATEGY_INCREMENT = 'increment'; |
||
172 | |||
173 | public const STORAGE_STRATEGY_PUSH_ALL = 'pushAll'; |
||
174 | public const STORAGE_STRATEGY_ADD_TO_SET = 'addToSet'; |
||
175 | public const STORAGE_STRATEGY_ATOMIC_SET = 'atomicSet'; |
||
176 | public const STORAGE_STRATEGY_ATOMIC_SET_ARRAY = 'atomicSetArray'; |
||
177 | public const STORAGE_STRATEGY_SET_ARRAY = 'setArray'; |
||
178 | |||
179 | private const ALLOWED_GRIDFS_FIELDS = ['_id', 'chunkSize', 'filename', 'length', 'metadata', 'uploadDate']; |
||
180 | |||
181 | /** |
||
182 | * READ-ONLY: The name of the mongo database the document is mapped to. |
||
183 | * |
||
184 | * @var string|null |
||
185 | */ |
||
186 | public $db; |
||
187 | |||
188 | /** |
||
189 | * READ-ONLY: The name of the mongo collection the document is mapped to. |
||
190 | * |
||
191 | * @var string |
||
192 | */ |
||
193 | public $collection; |
||
194 | |||
195 | /** |
||
196 | * READ-ONLY: The name of the GridFS bucket the document is mapped to. |
||
197 | * |
||
198 | * @var string |
||
199 | */ |
||
200 | public $bucketName = 'fs'; |
||
201 | |||
202 | /** |
||
203 | * READ-ONLY: If the collection should be a fixed size. |
||
204 | * |
||
205 | * @var bool |
||
206 | */ |
||
207 | public $collectionCapped = false; |
||
208 | |||
209 | /** |
||
210 | * READ-ONLY: If the collection is fixed size, its size in bytes. |
||
211 | * |
||
212 | * @var int|null |
||
213 | */ |
||
214 | public $collectionSize; |
||
215 | |||
216 | /** |
||
217 | * READ-ONLY: If the collection is fixed size, the maximum number of elements to store in the collection. |
||
218 | * |
||
219 | * @var int|null |
||
220 | */ |
||
221 | public $collectionMax; |
||
222 | |||
223 | /** |
||
224 | * READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set. |
||
225 | * |
||
226 | * @var string|null |
||
227 | */ |
||
228 | public $readPreference; |
||
229 | |||
230 | /** |
||
231 | * READ-ONLY Associated with readPreference Allows to specify criteria so that your application can target read |
||
232 | * operations to specific members, based on custom parameters. |
||
233 | * |
||
234 | * @var string[][] |
||
235 | */ |
||
236 | public $readPreferenceTags = []; |
||
237 | |||
238 | /** |
||
239 | * READ-ONLY: Describes the level of acknowledgement requested from MongoDB for write operations. |
||
240 | * |
||
241 | * @var string|int|null |
||
242 | */ |
||
243 | public $writeConcern; |
||
244 | |||
245 | /** |
||
246 | * READ-ONLY: The field name of the document identifier. |
||
247 | * |
||
248 | * @var string|null |
||
249 | */ |
||
250 | public $identifier; |
||
251 | |||
252 | /** |
||
253 | * READ-ONLY: The array of indexes for the document collection. |
||
254 | * |
||
255 | * @var array |
||
256 | */ |
||
257 | public $indexes = []; |
||
258 | |||
259 | /** |
||
260 | * READ-ONLY: Keys and options describing shard key. Only for sharded collections. |
||
261 | * |
||
262 | * @var array<string, array> |
||
263 | */ |
||
264 | public $shardKey = []; |
||
265 | |||
266 | /** |
||
267 | * READ-ONLY: The name of the document class. |
||
268 | * |
||
269 | * @var string |
||
270 | */ |
||
271 | public $name; |
||
272 | |||
273 | /** |
||
274 | * READ-ONLY: The name of the document class that is at the root of the mapped document inheritance |
||
275 | * hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same |
||
276 | * as {@link $documentName}. |
||
277 | * |
||
278 | * @var string |
||
279 | */ |
||
280 | public $rootDocumentName; |
||
281 | |||
282 | /** |
||
283 | * The name of the custom repository class used for the document class. |
||
284 | * (Optional). |
||
285 | * |
||
286 | * @var string|null |
||
287 | */ |
||
288 | public $customRepositoryClassName; |
||
289 | |||
290 | /** |
||
291 | * READ-ONLY: The names of the parent classes (ancestors). |
||
292 | * |
||
293 | * @var array |
||
294 | */ |
||
295 | public $parentClasses = []; |
||
296 | |||
297 | /** |
||
298 | * READ-ONLY: The names of all subclasses (descendants). |
||
299 | * |
||
300 | * @var array |
||
301 | */ |
||
302 | public $subClasses = []; |
||
303 | |||
304 | /** |
||
305 | * The ReflectionProperty instances of the mapped class. |
||
306 | * |
||
307 | * @var ReflectionProperty[] |
||
308 | */ |
||
309 | public $reflFields = []; |
||
310 | |||
311 | /** |
||
312 | * READ-ONLY: The inheritance mapping type used by the class. |
||
313 | * |
||
314 | * @var int |
||
315 | */ |
||
316 | public $inheritanceType = self::INHERITANCE_TYPE_NONE; |
||
317 | |||
318 | /** |
||
319 | * READ-ONLY: The Id generator type used by the class. |
||
320 | * |
||
321 | * @var int |
||
322 | */ |
||
323 | public $generatorType = self::GENERATOR_TYPE_AUTO; |
||
324 | |||
325 | /** |
||
326 | * READ-ONLY: The Id generator options. |
||
327 | * |
||
328 | * @var array |
||
329 | */ |
||
330 | public $generatorOptions = []; |
||
331 | |||
332 | /** |
||
333 | * READ-ONLY: The ID generator used for generating IDs for this class. |
||
334 | * |
||
335 | * @var IdGenerator|null |
||
336 | */ |
||
337 | public $idGenerator; |
||
338 | |||
339 | /** |
||
340 | * READ-ONLY: The field mappings of the class. |
||
341 | * Keys are field names and values are mapping definitions. |
||
342 | * |
||
343 | * The mapping definition array has the following values: |
||
344 | * |
||
345 | * - <b>fieldName</b> (string) |
||
346 | * The name of the field in the Document. |
||
347 | * |
||
348 | * - <b>id</b> (boolean, optional) |
||
349 | * Marks the field as the primary key of the document. Multiple fields of an |
||
350 | * document can have the id attribute, forming a composite key. |
||
351 | * |
||
352 | * @var array |
||
353 | */ |
||
354 | public $fieldMappings = []; |
||
355 | |||
356 | /** |
||
357 | * READ-ONLY: The association mappings of the class. |
||
358 | * Keys are field names and values are mapping definitions. |
||
359 | * |
||
360 | * @var array |
||
361 | */ |
||
362 | public $associationMappings = []; |
||
363 | |||
364 | /** |
||
365 | * READ-ONLY: Array of fields to also load with a given method. |
||
366 | * |
||
367 | * @var array |
||
368 | */ |
||
369 | public $alsoLoadMethods = []; |
||
370 | |||
371 | /** |
||
372 | * READ-ONLY: The registered lifecycle callbacks for documents of this class. |
||
373 | * |
||
374 | * @var array |
||
375 | */ |
||
376 | public $lifecycleCallbacks = []; |
||
377 | |||
378 | /** |
||
379 | * READ-ONLY: The discriminator value of this class. |
||
380 | * |
||
381 | * <b>This does only apply to the JOINED and SINGLE_COLLECTION inheritance mapping strategies |
||
382 | * where a discriminator field is used.</b> |
||
383 | * |
||
384 | * @see discriminatorField |
||
385 | * |
||
386 | * @var mixed |
||
387 | */ |
||
388 | public $discriminatorValue; |
||
389 | |||
390 | /** |
||
391 | * READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
||
392 | * |
||
393 | * <b>This does only apply to the SINGLE_COLLECTION inheritance mapping strategy |
||
394 | * where a discriminator field is used.</b> |
||
395 | * |
||
396 | * @see discriminatorField |
||
397 | * |
||
398 | * @var mixed |
||
399 | */ |
||
400 | public $discriminatorMap = []; |
||
401 | |||
402 | /** |
||
403 | * READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION |
||
404 | * inheritance mapping. |
||
405 | * |
||
406 | * @var string|null |
||
407 | */ |
||
408 | public $discriminatorField; |
||
409 | |||
410 | /** |
||
411 | * READ-ONLY: The default value for discriminatorField in case it's not set in the document |
||
412 | * |
||
413 | * @see discriminatorField |
||
414 | * |
||
415 | * @var string|null |
||
416 | */ |
||
417 | public $defaultDiscriminatorValue; |
||
418 | |||
419 | /** |
||
420 | * READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
||
421 | * |
||
422 | * @var bool |
||
423 | */ |
||
424 | public $isMappedSuperclass = false; |
||
425 | |||
426 | /** |
||
427 | * READ-ONLY: Whether this class describes the mapping of a embedded document. |
||
428 | * |
||
429 | * @var bool |
||
430 | */ |
||
431 | public $isEmbeddedDocument = false; |
||
432 | |||
433 | /** |
||
434 | * READ-ONLY: Whether this class describes the mapping of an aggregation result document. |
||
435 | * |
||
436 | * @var bool |
||
437 | */ |
||
438 | public $isQueryResultDocument = false; |
||
439 | |||
440 | /** |
||
441 | * READ-ONLY: Whether this class describes the mapping of a database view. |
||
442 | * |
||
443 | * @var bool |
||
444 | */ |
||
445 | private $isView = false; |
||
446 | |||
447 | /** |
||
448 | * READ-ONLY: Whether this class describes the mapping of a gridFS file |
||
449 | * |
||
450 | * @var bool |
||
451 | */ |
||
452 | public $isFile = false; |
||
453 | |||
454 | /** |
||
455 | * READ-ONLY: The default chunk size in bytes for the file |
||
456 | * |
||
457 | * @var int|null |
||
458 | */ |
||
459 | public $chunkSizeBytes; |
||
460 | |||
461 | /** |
||
462 | * READ-ONLY: The policy used for change-tracking on entities of this class. |
||
463 | * |
||
464 | * @var int |
||
465 | */ |
||
466 | public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT; |
||
467 | |||
468 | /** |
||
469 | * READ-ONLY: A flag for whether or not instances of this class are to be versioned |
||
470 | * with optimistic locking. |
||
471 | * |
||
472 | * @var bool $isVersioned |
||
473 | */ |
||
474 | public $isVersioned = false; |
||
475 | |||
476 | /** |
||
477 | * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). |
||
478 | * |
||
479 | * @var string|null $versionField |
||
480 | */ |
||
481 | public $versionField; |
||
482 | |||
483 | /** |
||
484 | * READ-ONLY: A flag for whether or not instances of this class are to allow pessimistic |
||
485 | * locking. |
||
486 | * |
||
487 | * @var bool $isLockable |
||
488 | */ |
||
489 | public $isLockable = false; |
||
490 | |||
491 | /** |
||
492 | * READ-ONLY: The name of the field which is used for locking a document. |
||
493 | * |
||
494 | * @var mixed $lockField |
||
495 | */ |
||
496 | public $lockField; |
||
497 | |||
498 | /** |
||
499 | * The ReflectionClass instance of the mapped class. |
||
500 | * |
||
501 | * @var ReflectionClass |
||
502 | */ |
||
503 | public $reflClass; |
||
504 | |||
505 | /** |
||
506 | * READ_ONLY: A flag for whether or not this document is read-only. |
||
507 | * |
||
508 | * @var bool |
||
509 | */ |
||
510 | public $isReadOnly; |
||
511 | |||
512 | /** @var InstantiatorInterface */ |
||
513 | private $instantiator; |
||
514 | |||
515 | /** @var string|null */ |
||
516 | private $rootClass; |
||
517 | |||
518 | /** |
||
519 | * Initializes a new ClassMetadata instance that will hold the object-document mapping |
||
520 | 1681 | * metadata of the class with the given name. |
|
521 | */ |
||
522 | 1681 | public function __construct(string $documentName) |
|
530 | |||
531 | /** |
||
532 | * Helper method to get reference id of ref* type references |
||
533 | * |
||
534 | * @internal |
||
535 | * |
||
536 | * @param mixed $reference |
||
537 | * |
||
538 | 121 | * @return mixed |
|
539 | */ |
||
540 | 121 | public static function getReferenceId($reference, string $storeAs) |
|
544 | |||
545 | /** |
||
546 | 189 | * Returns the reference prefix used for a reference |
|
547 | */ |
||
548 | 189 | private static function getReferencePrefix(string $storeAs) : string |
|
556 | |||
557 | /** |
||
558 | * Returns a fully qualified field name for a given reference |
||
559 | * |
||
560 | * @internal |
||
561 | * |
||
562 | 145 | * @param string $pathPrefix The field path prefix |
|
563 | */ |
||
564 | 145 | public static function getReferenceFieldName(string $storeAs, string $pathPrefix = '') : string |
|
572 | |||
573 | /** |
||
574 | 1601 | * {@inheritDoc} |
|
575 | */ |
||
576 | 1601 | public function getReflectionClass() : ReflectionClass |
|
580 | |||
581 | /** |
||
582 | 366 | * {@inheritDoc} |
|
583 | */ |
||
584 | 366 | public function isIdentifier($fieldName) : bool |
|
588 | |||
589 | /** |
||
590 | * Sets the mapped identifier field of this class. |
||
591 | * |
||
592 | 1035 | * @internal |
|
593 | */ |
||
594 | 1035 | public function setIdentifier(?string $identifier) : void |
|
598 | |||
599 | /** |
||
600 | * {@inheritDoc} |
||
601 | * |
||
602 | * Since MongoDB only allows exactly one identifier field |
||
603 | 12 | * this will always return an array with only one value |
|
604 | */ |
||
605 | 12 | public function getIdentifier() : array |
|
609 | |||
610 | /** |
||
611 | * Since MongoDB only allows exactly one identifier field |
||
612 | * this will always return an array with only one value |
||
613 | * |
||
614 | 109 | * return (string|null)[] |
|
615 | */ |
||
616 | 109 | public function getIdentifierFieldNames() : array |
|
620 | |||
621 | /** |
||
622 | 1011 | * {@inheritDoc} |
|
623 | */ |
||
624 | 1011 | public function hasField($fieldName) : bool |
|
628 | |||
629 | /** |
||
630 | 1056 | * Sets the inheritance type used by the class and it's subclasses. |
|
631 | */ |
||
632 | 1056 | public function setInheritanceType(int $type) : void |
|
636 | |||
637 | /** |
||
638 | 1587 | * Checks whether a mapped field is inherited from an entity superclass. |
|
639 | */ |
||
640 | 1587 | public function isInheritedField(string $fieldName) : bool |
|
644 | |||
645 | /** |
||
646 | 990 | * Registers a custom repository class for the document class. |
|
647 | */ |
||
648 | 990 | public function setCustomRepositoryClass(?string $repositoryClassName) : void |
|
656 | |||
657 | /** |
||
658 | * Dispatches the lifecycle event of the given document by invoking all |
||
659 | * registered callbacks. |
||
660 | * |
||
661 | * @throws InvalidArgumentException If document class is not this class or |
||
662 | 667 | * a Proxy of this class. |
|
663 | */ |
||
664 | 667 | public function invokeLifecycleCallbacks(string $event, object $document, ?array $arguments = null) : void |
|
686 | |||
687 | /** |
||
688 | * Checks whether the class has callbacks registered for a lifecycle event. |
||
689 | */ |
||
690 | public function hasLifecycleCallbacks(string $event) : bool |
||
694 | |||
695 | /** |
||
696 | * Gets the registered lifecycle callbacks for an event. |
||
697 | */ |
||
698 | public function getLifecycleCallbacks(string $event) : array |
||
702 | |||
703 | /** |
||
704 | * Adds a lifecycle callback for documents of this class. |
||
705 | * |
||
706 | 940 | * If the callback is already registered, this is a NOOP. |
|
707 | */ |
||
708 | 940 | public function addLifecycleCallback(string $callback, string $event) : void |
|
716 | |||
717 | /** |
||
718 | * Sets the lifecycle callbacks for documents of this class. |
||
719 | * |
||
720 | 1034 | * Any previously registered callbacks are overwritten. |
|
721 | */ |
||
722 | 1034 | public function setLifecycleCallbacks(array $callbacks) : void |
|
726 | |||
727 | /** |
||
728 | * Registers a method for loading document data before field hydration. |
||
729 | * |
||
730 | * Note: A method may be registered multiple times for different fields. |
||
731 | * it will be invoked only once for the first field found. |
||
732 | * |
||
733 | 14 | * @param array|string $fields Database field name(s) |
|
734 | */ |
||
735 | 14 | public function registerAlsoLoadMethod(string $method, $fields) : void |
|
739 | |||
740 | /** |
||
741 | * Sets the AlsoLoad methods for documents of this class. |
||
742 | * |
||
743 | 1034 | * Any previously registered methods are overwritten. |
|
744 | */ |
||
745 | 1034 | public function setAlsoLoadMethods(array $methods) : void |
|
749 | |||
750 | /** |
||
751 | * Sets the discriminator field. |
||
752 | * |
||
753 | * The field name is the the unmapped database field. Discriminator values |
||
754 | * are only used to discern the hydration class and are not mapped to class |
||
755 | * properties. |
||
756 | * |
||
757 | * @param array|string|null $discriminatorField |
||
758 | * |
||
759 | * @throws MappingException If the discriminator field conflicts with the |
||
760 | 1065 | * "name" attribute of a mapped field. |
|
761 | */ |
||
762 | 1065 | public function setDiscriminatorField($discriminatorField) : void |
|
792 | |||
793 | /** |
||
794 | * Sets the discriminator values used by this class. |
||
795 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
||
796 | * |
||
797 | 1054 | * @throws MappingException |
|
798 | */ |
||
799 | 1054 | public function setDiscriminatorMap(array $map) : void |
|
823 | |||
824 | /** |
||
825 | * Sets the default discriminator value to be used for this class |
||
826 | * Used for SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value |
||
827 | * |
||
828 | 1037 | * @throws MappingException |
|
829 | */ |
||
830 | 1037 | public function setDefaultDiscriminatorValue(?string $defaultDiscriminatorValue) : void |
|
848 | |||
849 | /** |
||
850 | * Sets the discriminator value for this class. |
||
851 | * Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single |
||
852 | * collection. |
||
853 | * |
||
854 | 4 | * @throws MappingException |
|
855 | */ |
||
856 | 4 | public function setDiscriminatorValue(string $value) : void |
|
865 | |||
866 | /** |
||
867 | 283 | * Add a index for this Document. |
|
868 | */ |
||
869 | 283 | public function addIndex(array $keys, array $options = []) : void |
|
892 | |||
893 | /** |
||
894 | 50 | * Returns the array of indexes for this Document. |
|
895 | */ |
||
896 | 50 | public function getIndexes() : array |
|
900 | |||
901 | /** |
||
902 | * Checks whether this document has indexes or not. |
||
903 | */ |
||
904 | public function hasIndexes() : bool |
||
908 | |||
909 | /** |
||
910 | * Set shard key for this Document. |
||
911 | * |
||
912 | 162 | * @throws MappingException |
|
913 | */ |
||
914 | 162 | public function setShardKey(array $keys, array $options = []) : void |
|
959 | |||
960 | 27 | public function getShardKey() : array |
|
964 | |||
965 | /** |
||
966 | 1289 | * Checks whether this document has shard key or not. |
|
967 | */ |
||
968 | 1289 | public function isSharded() : bool |
|
972 | |||
973 | /** |
||
974 | 1034 | * Sets the read preference used by this class. |
|
975 | */ |
||
976 | 1034 | public function setReadPreference(?string $readPreference, array $tags) : void |
|
981 | |||
982 | /** |
||
983 | * Sets the write concern used by this class. |
||
984 | * |
||
985 | 1044 | * @param string|int|null $writeConcern |
|
986 | */ |
||
987 | 1044 | public function setWriteConcern($writeConcern) : void |
|
991 | |||
992 | /** |
||
993 | 11 | * @return int|string|null |
|
994 | */ |
||
995 | 11 | public function getWriteConcern() |
|
999 | |||
1000 | /** |
||
1001 | 615 | * Whether there is a write concern configured for this class. |
|
1002 | */ |
||
1003 | 615 | public function hasWriteConcern() : bool |
|
1007 | |||
1008 | /** |
||
1009 | 1035 | * Sets the change tracking policy used by this class. |
|
1010 | */ |
||
1011 | 1035 | public function setChangeTrackingPolicy(int $policy) : void |
|
1015 | |||
1016 | /** |
||
1017 | 70 | * Whether the change tracking policy of this class is "deferred explicit". |
|
1018 | */ |
||
1019 | 70 | public function isChangeTrackingDeferredExplicit() : bool |
|
1023 | |||
1024 | /** |
||
1025 | 626 | * Whether the change tracking policy of this class is "deferred implicit". |
|
1026 | */ |
||
1027 | 626 | public function isChangeTrackingDeferredImplicit() : bool |
|
1031 | |||
1032 | /** |
||
1033 | 346 | * Whether the change tracking policy of this class is "notify". |
|
1034 | */ |
||
1035 | 346 | public function isChangeTrackingNotify() : bool |
|
1039 | |||
1040 | /** |
||
1041 | 1 | * Gets the ReflectionProperties of the mapped class. |
|
1042 | */ |
||
1043 | 1 | public function getReflectionProperties() : array |
|
1047 | |||
1048 | /** |
||
1049 | 108 | * Gets a ReflectionProperty for a specific field of the mapped class. |
|
1050 | */ |
||
1051 | 108 | public function getReflectionProperty(string $name) : ReflectionProperty |
|
1055 | |||
1056 | /** |
||
1057 | 1609 | * {@inheritDoc} |
|
1058 | */ |
||
1059 | 1609 | public function getName() : string |
|
1063 | |||
1064 | /** |
||
1065 | 1495 | * Returns the database this Document is mapped to. |
|
1066 | */ |
||
1067 | 1495 | public function getDatabase() : ?string |
|
1071 | |||
1072 | /** |
||
1073 | 179 | * Set the database this Document is mapped to. |
|
1074 | */ |
||
1075 | 179 | public function setDatabase(?string $db) : void |
|
1079 | |||
1080 | /** |
||
1081 | 1494 | * Get the collection this Document is mapped to. |
|
1082 | */ |
||
1083 | 1494 | public function getCollection() : string |
|
1087 | |||
1088 | /** |
||
1089 | * Sets the collection this Document is mapped to. |
||
1090 | * |
||
1091 | * @param array|string $name |
||
1092 | * |
||
1093 | 1681 | * @throws InvalidArgumentException |
|
1094 | */ |
||
1095 | 1681 | public function setCollection($name) : void |
|
1109 | |||
1110 | 137 | public function getBucketName() : ?string |
|
1114 | |||
1115 | 1 | public function setBucketName(string $bucketName) : void |
|
1120 | |||
1121 | 12 | public function getChunkSizeBytes() : ?int |
|
1125 | |||
1126 | 140 | public function setChunkSizeBytes(int $chunkSizeBytes) : void |
|
1130 | |||
1131 | /** |
||
1132 | 11 | * Get whether or not the documents collection is capped. |
|
1133 | */ |
||
1134 | 11 | public function getCollectionCapped() : bool |
|
1138 | |||
1139 | /** |
||
1140 | 1 | * Set whether or not the documents collection is capped. |
|
1141 | */ |
||
1142 | 1 | public function setCollectionCapped(bool $bool) : void |
|
1146 | |||
1147 | /** |
||
1148 | 11 | * Get the collection size |
|
1149 | */ |
||
1150 | 11 | public function getCollectionSize() : ?int |
|
1154 | |||
1155 | /** |
||
1156 | 1 | * Set the collection size. |
|
1157 | */ |
||
1158 | 1 | public function setCollectionSize(int $size) : void |
|
1162 | |||
1163 | /** |
||
1164 | 11 | * Get the collection max. |
|
1165 | */ |
||
1166 | 11 | public function getCollectionMax() : ?int |
|
1170 | |||
1171 | /** |
||
1172 | 1 | * Set the collection max. |
|
1173 | */ |
||
1174 | 1 | public function setCollectionMax(int $max) : void |
|
1178 | |||
1179 | /** |
||
1180 | * Returns TRUE if this Document is mapped to a collection FALSE otherwise. |
||
1181 | */ |
||
1182 | public function isMappedToCollection() : bool |
||
1186 | |||
1187 | /** |
||
1188 | * Validates the storage strategy of a mapping for consistency |
||
1189 | * |
||
1190 | 1619 | * @throws MappingException |
|
1191 | */ |
||
1192 | 1619 | private function applyStorageStrategy(array &$mapping) : void |
|
1238 | |||
1239 | 6 | /** |
|
1240 | 6 | * Map a single embedded document. |
|
1241 | 6 | */ |
|
1242 | 5 | public function mapOneEmbedded(array $mapping) : void |
|
1248 | |||
1249 | 6 | /** |
|
1250 | 6 | * Map a collection of embedded documents. |
|
1251 | 6 | */ |
|
1252 | 6 | public function mapManyEmbedded(array $mapping) : void |
|
1258 | |||
1259 | 3 | /** |
|
1260 | 3 | * Map a single document reference. |
|
1261 | 3 | */ |
|
1262 | 3 | public function mapOneReference(array $mapping) : void |
|
1268 | |||
1269 | 1 | /** |
|
1270 | 1 | * Map a collection of document references. |
|
1271 | 1 | */ |
|
1272 | 1 | public function mapManyReference(array $mapping) : void |
|
1278 | |||
1279 | /** |
||
1280 | 205 | * Adds a field mapping without completing/validating it. |
|
1281 | * This is mainly used to add inherited field mappings to derived classes. |
||
1282 | 205 | * |
|
1283 | * @internal |
||
1284 | 205 | */ |
|
1285 | 205 | public function addInheritedFieldMapping(array $fieldMapping) : void |
|
1295 | |||
1296 | /** |
||
1297 | * Adds an association mapping without completing/validating it. |
||
1298 | * This is mainly used to add inherited association mappings to derived classes. |
||
1299 | 154 | * |
|
1300 | * @internal |
||
1301 | 154 | * |
|
1302 | 154 | * @throws MappingException |
|
1303 | */ |
||
1304 | public function addInheritedAssociationMapping(array $mapping) : void |
||
1308 | |||
1309 | 33 | /** |
|
1310 | * Checks whether the class has a mapped association with the given field name. |
||
1311 | */ |
||
1312 | public function hasReference(string $fieldName) : bool |
||
1316 | |||
1317 | 4 | /** |
|
1318 | * Checks whether the class has a mapped embed with the given field name. |
||
1319 | */ |
||
1320 | public function hasEmbed(string $fieldName) : bool |
||
1324 | |||
1325 | 6 | /** |
|
1326 | * {@inheritDoc} |
||
1327 | 6 | * |
|
1328 | * Checks whether the class has a mapped association (embed or reference) with the given field name. |
||
1329 | */ |
||
1330 | public function hasAssociation($fieldName) : bool |
||
1334 | |||
1335 | /** |
||
1336 | * {@inheritDoc} |
||
1337 | * |
||
1338 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
1339 | * is a single valued association. |
||
1340 | */ |
||
1341 | public function isSingleValuedAssociation($fieldName) : bool |
||
1345 | |||
1346 | /** |
||
1347 | * {@inheritDoc} |
||
1348 | * |
||
1349 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
1350 | * is a collection valued association. |
||
1351 | */ |
||
1352 | public function isCollectionValuedAssociation($fieldName) : bool |
||
1356 | 1 | ||
1357 | /** |
||
1358 | 1 | * Checks whether the class has a mapped association for the specified field |
|
1359 | 1 | * and if yes, checks whether it is a single-valued association (to-one). |
|
1360 | */ |
||
1361 | public function isSingleValuedReference(string $fieldName) : bool |
||
1366 | |||
1367 | /** |
||
1368 | * Checks whether the class has a mapped association for the specified field |
||
1369 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
1370 | */ |
||
1371 | public function isCollectionValuedReference(string $fieldName) : bool |
||
1376 | |||
1377 | /** |
||
1378 | * Checks whether the class has a mapped embedded document for the specified field |
||
1379 | * and if yes, checks whether it is a single-valued association (to-one). |
||
1380 | */ |
||
1381 | public function isSingleValuedEmbed(string $fieldName) : bool |
||
1386 | |||
1387 | /** |
||
1388 | * Checks whether the class has a mapped embedded document for the specified field |
||
1389 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
1390 | */ |
||
1391 | public function isCollectionValuedEmbed(string $fieldName) : bool |
||
1396 | |||
1397 | 1543 | /** |
|
1398 | 1543 | * Sets the ID generator used to generate IDs for instances of this class. |
|
1399 | */ |
||
1400 | public function setIdGenerator(IdGenerator $generator) : void |
||
1404 | |||
1405 | /** |
||
1406 | * Casts the identifier to its portable PHP type. |
||
1407 | 667 | * |
|
1408 | * @param mixed $id |
||
1409 | 667 | * |
|
1410 | * @return mixed $id |
||
1411 | 667 | */ |
|
1412 | public function getPHPIdentifierValue($id) |
||
1418 | |||
1419 | /** |
||
1420 | * Casts the identifier to its database type. |
||
1421 | 737 | * |
|
1422 | * @param mixed $id |
||
1423 | 737 | * |
|
1424 | * @return mixed $id |
||
1425 | 737 | */ |
|
1426 | public function getDatabaseIdentifierValue($id) |
||
1432 | |||
1433 | /** |
||
1434 | * Sets the document identifier of a document. |
||
1435 | 597 | * |
|
1436 | * The value will be converted to a PHP type before being set. |
||
1437 | 597 | * |
|
1438 | 597 | * @param mixed $id |
|
1439 | 597 | */ |
|
1440 | public function setIdentifierValue(object $document, $id) : void |
||
1445 | |||
1446 | 675 | /** |
|
1447 | * Gets the document identifier as a PHP type. |
||
1448 | 675 | * |
|
1449 | * @return mixed $id |
||
1450 | */ |
||
1451 | public function getIdentifierValue(object $document) |
||
1455 | |||
1456 | /** |
||
1457 | * {@inheritDoc} |
||
1458 | * |
||
1459 | * Since MongoDB only allows exactly one identifier field this is a proxy |
||
1460 | * to {@see getIdentifierValue()} and returns an array with the identifier |
||
1461 | * field as a key. |
||
1462 | */ |
||
1463 | public function getIdentifierValues($object) : array |
||
1467 | |||
1468 | 31 | /** |
|
1469 | * Get the document identifier object as a database type. |
||
1470 | 31 | * |
|
1471 | * @return mixed $id |
||
1472 | */ |
||
1473 | public function getIdentifierObject(object $document) |
||
1477 | |||
1478 | 8 | /** |
|
1479 | * Sets the specified field to the specified value on the given document. |
||
1480 | 8 | * |
|
1481 | * @param mixed $value |
||
1482 | */ |
||
1483 | 1 | public function setFieldValue(object $document, string $field, $value) : void |
|
1493 | |||
1494 | 33 | /** |
|
1495 | * Gets the specified field's value off the given document. |
||
1496 | 33 | * |
|
1497 | 1 | * @return mixed |
|
1498 | */ |
||
1499 | public function getFieldValue(object $document, string $field) |
||
1507 | |||
1508 | 201 | /** |
|
1509 | * Gets the mapping of a field. |
||
1510 | 201 | * |
|
1511 | 6 | * @throws MappingException If the $fieldName is not found in the fieldMappings array. |
|
1512 | */ |
||
1513 | public function getFieldMapping(string $fieldName) : array |
||
1521 | |||
1522 | 604 | /** |
|
1523 | 604 | * Gets mappings of fields holding embedded document(s). |
|
1524 | */ |
||
1525 | 464 | public function getEmbeddedFieldsMappings() : array |
|
1534 | |||
1535 | /** |
||
1536 | 17 | * Gets the field mapping by its DB name. |
|
1537 | * E.g. it returns identifier's mapping when called with _id. |
||
1538 | 17 | * |
|
1539 | 17 | * @throws MappingException |
|
1540 | 15 | */ |
|
1541 | public function getFieldMappingByDbFieldName(string $dbFieldName) : array |
||
1551 | |||
1552 | 1 | /** |
|
1553 | * Check if the field is not null. |
||
1554 | 1 | */ |
|
1555 | public function isNullable(string $fieldName) : bool |
||
1561 | |||
1562 | /** |
||
1563 | * Checks whether the document has a discriminator field and value configured. |
||
1564 | */ |
||
1565 | public function hasDiscriminator() : bool |
||
1569 | |||
1570 | 1034 | /** |
|
1571 | 1034 | * Sets the type of Id generator to use for the mapped class. |
|
1572 | */ |
||
1573 | public function setIdGeneratorType(int $generatorType) : void |
||
1577 | |||
1578 | /** |
||
1579 | * Sets the Id generator options. |
||
1580 | */ |
||
1581 | 631 | public function setIdGeneratorOptions(array $generatorOptions) : void |
|
1585 | |||
1586 | public function isInheritanceTypeNone() : bool |
||
1590 | |||
1591 | 1031 | /** |
|
1592 | * Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy. |
||
1593 | */ |
||
1594 | public function isInheritanceTypeSingleCollection() : bool |
||
1598 | |||
1599 | /** |
||
1600 | * Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy. |
||
1601 | */ |
||
1602 | public function isInheritanceTypeCollectionPerClass() : bool |
||
1606 | |||
1607 | 2 | /** |
|
1608 | * Sets the mapped subclasses of this class. |
||
1609 | 2 | * |
|
1610 | 2 | * @param string[] $subclasses The names of all mapped subclasses. |
|
1611 | */ |
||
1612 | 2 | public function setSubclasses(array $subclasses) : void |
|
1618 | |||
1619 | /** |
||
1620 | * Sets the parent class names. |
||
1621 | 1596 | * Assumes that the class names in the passed array are in the order: |
|
1622 | * directParent -> directParentParent -> directParentParentParent ... -> root. |
||
1623 | 1596 | * |
|
1624 | * @param string[] $classNames |
||
1625 | 1596 | */ |
|
1626 | 1595 | public function setParentClasses(array $classNames) : void |
|
1636 | |||
1637 | /** |
||
1638 | * Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us. |
||
1639 | */ |
||
1640 | public function isIdGeneratorAuto() : bool |
||
1644 | |||
1645 | /** |
||
1646 | * Checks whether the class will use a collection to generate incremented identifiers. |
||
1647 | */ |
||
1648 | public function isIdGeneratorIncrement() : bool |
||
1652 | |||
1653 | /** |
||
1654 | * Checks whether the class will generate a uuid id. |
||
1655 | */ |
||
1656 | public function isIdGeneratorUuid() : bool |
||
1660 | |||
1661 | /** |
||
1662 | * Checks whether the class uses no id generator. |
||
1663 | */ |
||
1664 | public function isIdGeneratorNone() : bool |
||
1668 | |||
1669 | /** |
||
1670 | 172 | * Sets the version field mapping used for versioning. Sets the default |
|
1671 | * value to use depending on the column type. |
||
1672 | 172 | * |
|
1673 | 1 | * @throws LockException |
|
1674 | */ |
||
1675 | public function setVersionMapping(array &$mapping) : void |
||
1684 | |||
1685 | 1034 | /** |
|
1686 | 1034 | * Sets whether this class is to be versioned for optimistic locking. |
|
1687 | */ |
||
1688 | public function setVersioned(bool $bool) : void |
||
1692 | 1034 | ||
1693 | /** |
||
1694 | 1034 | * Sets the name of the field that is to be used for versioning if this class is |
|
1695 | 1034 | * versioned for optimistic locking. |
|
1696 | */ |
||
1697 | public function setVersionField(?string $versionField) : void |
||
1701 | |||
1702 | /** |
||
1703 | 25 | * Sets the version field mapping used for versioning. Sets the default |
|
1704 | * value to use depending on the column type. |
||
1705 | 25 | * |
|
1706 | 1 | * @throws LockException |
|
1707 | */ |
||
1708 | public function setLockMapping(array &$mapping) : void |
||
1717 | |||
1718 | /** |
||
1719 | * Sets whether this class is to allow pessimistic locking. |
||
1720 | */ |
||
1721 | public function setLockable(bool $bool) : void |
||
1725 | |||
1726 | /** |
||
1727 | * Sets the name of the field that is to be used for storing whether a document |
||
1728 | * is currently locked or not. |
||
1729 | */ |
||
1730 | public function setLockField(string $lockField) : void |
||
1734 | |||
1735 | 5 | /** |
|
1736 | 5 | * Marks this class as read only, no change tracking is applied to it. |
|
1737 | */ |
||
1738 | 11 | public function markReadOnly() : void |
|
1742 | |||
1743 | 1591 | public function getRootClass() : ?string |
|
1747 | |||
1748 | 133 | public function isView() : bool |
|
1752 | 133 | ||
1753 | public function markViewOf(string $rootClass) : void |
||
1758 | |||
1759 | /** |
||
1760 | * {@inheritDoc} |
||
1761 | */ |
||
1762 | public function getFieldNames() : array |
||
1766 | |||
1767 | /** |
||
1768 | * {@inheritDoc} |
||
1769 | */ |
||
1770 | public function getAssociationNames() : array |
||
1774 | |||
1775 | /** |
||
1776 | * {@inheritDoc} |
||
1777 | */ |
||
1778 | public function getTypeOfField($fieldName) : ?string |
||
1783 | |||
1784 | 5 | /** |
|
1785 | 2 | * {@inheritDoc} |
|
1786 | */ |
||
1787 | public function getAssociationTargetClass($assocName) : ?string |
||
1795 | |||
1796 | /** |
||
1797 | * Retrieve the collectionClass associated with an association |
||
1798 | */ |
||
1799 | public function getAssociationCollectionClass(string $assocName) : string |
||
1811 | |||
1812 | /** |
||
1813 | * {@inheritDoc} |
||
1814 | */ |
||
1815 | public function isAssociationInverseSide($fieldName) : bool |
||
1819 | |||
1820 | /** |
||
1821 | * {@inheritDoc} |
||
1822 | */ |
||
1823 | public function getAssociationMappedByTargetField($fieldName) |
||
1827 | |||
1828 | 1635 | /** |
|
1829 | * Map a field. |
||
1830 | 1635 | * |
|
1831 | 9 | * @throws MappingException |
|
1832 | */ |
||
1833 | 1635 | public function mapField(array $mapping) : array |
|
1997 | |||
1998 | /** |
||
1999 | * Determines which fields get serialized. |
||
2000 | * |
||
2001 | * It is only serialized what is necessary for best unserialization performance. |
||
2002 | * That means any metadata properties that are not set or empty or simply have |
||
2003 | * their default value are NOT serialized. |
||
2004 | * |
||
2005 | 6 | * Parts that are also NOT serialized because they can not be properly unserialized: |
|
2006 | * - reflClass (ReflectionClass) |
||
2007 | * - reflFields (ReflectionProperty array) |
||
2008 | * |
||
2009 | 6 | * @return array The names of all the fields that should be serialized. |
|
2010 | */ |
||
2011 | public function __sleep() |
||
2095 | |||
2096 | 6 | /** |
|
2097 | 6 | * Restores some state that can not be serialized/unserialized. |
|
2098 | */ |
||
2099 | 6 | public function __wakeup() |
|
2115 | 374 | ||
2116 | /** |
||
2117 | * Creates a new instance of the mapped class, without invoking the constructor. |
||
2118 | 146 | */ |
|
2119 | public function newInstance() : object |
||
2123 | 1618 | ||
2124 | private function isAllowedGridFSField(string $name) : bool |
||
2128 | |||
2129 | 1618 | private function typeRequirementsAreMet(array $mapping) : void |
|
2135 | |||
2136 | 1560 | private function checkDuplicateMapping(array $mapping) : void |
|
2161 | } |
||
2162 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..