Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 |
||
| 29 | class ClassMetadata implements BaseClassMetadata |
||
| 30 | { |
||
| 31 | /* The Id generator types. */ |
||
| 32 | /** |
||
| 33 | * AUTO means Doctrine will automatically create a new \MongoDB\BSON\ObjectId instance for us. |
||
| 34 | */ |
||
| 35 | const GENERATOR_TYPE_AUTO = 1; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * INCREMENT means a separate collection is used for maintaining and incrementing id generation. |
||
| 39 | * Offers full portability. |
||
| 40 | */ |
||
| 41 | const GENERATOR_TYPE_INCREMENT = 2; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * UUID means Doctrine will generate a uuid for us. |
||
| 45 | */ |
||
| 46 | const GENERATOR_TYPE_UUID = 3; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * ALNUM means Doctrine will generate Alpha-numeric string identifiers, using the INCREMENT |
||
| 50 | * generator to ensure identifier uniqueness |
||
| 51 | */ |
||
| 52 | const GENERATOR_TYPE_ALNUM = 4; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * CUSTOM means Doctrine expect a class parameter. It will then try to initiate that class |
||
| 56 | * and pass other options to the generator. It will throw an Exception if the class |
||
| 57 | * does not exist or if an option was passed for that there is not setter in the new |
||
| 58 | * generator class. |
||
| 59 | * |
||
| 60 | * The class will have to be a subtype of AbstractIdGenerator. |
||
| 61 | */ |
||
| 62 | const GENERATOR_TYPE_CUSTOM = 5; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * NONE means Doctrine will not generate any id for us and you are responsible for manually |
||
| 66 | * assigning an id. |
||
| 67 | */ |
||
| 68 | const GENERATOR_TYPE_NONE = 6; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Default discriminator field name. |
||
| 72 | * |
||
| 73 | * This is used for associations value for associations where a that do not define a "targetDocument" or |
||
| 74 | * "discriminatorField" option in their mapping. |
||
| 75 | */ |
||
| 76 | const DEFAULT_DISCRIMINATOR_FIELD = '_doctrine_class_name'; |
||
| 77 | |||
| 78 | const REFERENCE_ONE = 1; |
||
| 79 | const REFERENCE_MANY = 2; |
||
| 80 | const EMBED_ONE = 3; |
||
| 81 | const EMBED_MANY = 4; |
||
| 82 | const MANY = 'many'; |
||
| 83 | const ONE = 'one'; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The types of storeAs references |
||
| 87 | */ |
||
| 88 | const REFERENCE_STORE_AS_ID = 'id'; |
||
| 89 | const REFERENCE_STORE_AS_DB_REF = 'dbRef'; |
||
| 90 | const REFERENCE_STORE_AS_DB_REF_WITH_DB = 'dbRefWithDb'; |
||
| 91 | const REFERENCE_STORE_AS_REF = 'ref'; |
||
| 92 | |||
| 93 | /* The inheritance mapping types */ |
||
| 94 | /** |
||
| 95 | * NONE means the class does not participate in an inheritance hierarchy |
||
| 96 | * and therefore does not need an inheritance mapping type. |
||
| 97 | */ |
||
| 98 | const INHERITANCE_TYPE_NONE = 1; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * SINGLE_COLLECTION means the class will be persisted according to the rules of |
||
| 102 | * <tt>Single Collection Inheritance</tt>. |
||
| 103 | */ |
||
| 104 | const INHERITANCE_TYPE_SINGLE_COLLECTION = 2; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * COLLECTION_PER_CLASS means the class will be persisted according to the rules |
||
| 108 | * of <tt>Concrete Collection Inheritance</tt>. |
||
| 109 | */ |
||
| 110 | const INHERITANCE_TYPE_COLLECTION_PER_CLASS = 3; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time |
||
| 114 | * by doing a property-by-property comparison with the original data. This will |
||
| 115 | * be done for all entities that are in MANAGED state at commit-time. |
||
| 116 | * |
||
| 117 | * This is the default change tracking policy. |
||
| 118 | */ |
||
| 119 | const CHANGETRACKING_DEFERRED_IMPLICIT = 1; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time |
||
| 123 | * by doing a property-by-property comparison with the original data. This will |
||
| 124 | * be done only for entities that were explicitly saved (through persist() or a cascade). |
||
| 125 | */ |
||
| 126 | const CHANGETRACKING_DEFERRED_EXPLICIT = 2; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * NOTIFY means that Doctrine relies on the entities sending out notifications |
||
| 130 | * when their properties change. Such entity classes must implement |
||
| 131 | * the <tt>NotifyPropertyChanged</tt> interface. |
||
| 132 | */ |
||
| 133 | const CHANGETRACKING_NOTIFY = 3; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * SET means that fields will be written to the database using a $set operator |
||
| 137 | */ |
||
| 138 | const STORAGE_STRATEGY_SET = 'set'; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * INCREMENT means that fields will be written to the database by calculating |
||
| 142 | * the difference and using the $inc operator |
||
| 143 | */ |
||
| 144 | const STORAGE_STRATEGY_INCREMENT = 'increment'; |
||
| 145 | |||
| 146 | const STORAGE_STRATEGY_PUSH_ALL = 'pushAll'; |
||
| 147 | const STORAGE_STRATEGY_ADD_TO_SET = 'addToSet'; |
||
| 148 | const STORAGE_STRATEGY_ATOMIC_SET = 'atomicSet'; |
||
| 149 | const STORAGE_STRATEGY_ATOMIC_SET_ARRAY = 'atomicSetArray'; |
||
| 150 | const STORAGE_STRATEGY_SET_ARRAY = 'setArray'; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * READ-ONLY: The name of the mongo database the document is mapped to. |
||
| 154 | */ |
||
| 155 | public $db; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * READ-ONLY: The name of the mongo collection the document is mapped to. |
||
| 159 | */ |
||
| 160 | public $collection; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * READ-ONLY: If the collection should be a fixed size. |
||
| 164 | */ |
||
| 165 | public $collectionCapped; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * READ-ONLY: If the collection is fixed size, its size in bytes. |
||
| 169 | */ |
||
| 170 | public $collectionSize; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * READ-ONLY: If the collection is fixed size, the maximum number of elements to store in the collection. |
||
| 174 | */ |
||
| 175 | public $collectionMax; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set. |
||
| 179 | */ |
||
| 180 | public $readPreference; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * READ-ONLY Associated with readPreference Allows to specify criteria so that your application can target read |
||
| 184 | * operations to specific members, based on custom parameters. |
||
| 185 | */ |
||
| 186 | public $readPreferenceTags; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * READ-ONLY: Describes the level of acknowledgement requested from MongoDB for write operations. |
||
| 190 | */ |
||
| 191 | public $writeConcern; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * READ-ONLY: The field name of the document identifier. |
||
| 195 | */ |
||
| 196 | public $identifier; |
||
| 197 | |||
| 198 | /** |
||
| 199 | * READ-ONLY: The array of indexes for the document collection. |
||
| 200 | */ |
||
| 201 | public $indexes = array(); |
||
| 202 | |||
| 203 | /** |
||
| 204 | * READ-ONLY: Keys and options describing shard key. Only for sharded collections. |
||
| 205 | */ |
||
| 206 | public $shardKey; |
||
| 207 | |||
| 208 | /** |
||
| 209 | * READ-ONLY: The name of the document class. |
||
| 210 | */ |
||
| 211 | public $name; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * READ-ONLY: The namespace the document class is contained in. |
||
| 215 | * |
||
| 216 | * @var string |
||
| 217 | * @todo Not really needed. Usage could be localized. |
||
| 218 | */ |
||
| 219 | public $namespace; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * READ-ONLY: The name of the document class that is at the root of the mapped document inheritance |
||
| 223 | * hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same |
||
| 224 | * as {@link $documentName}. |
||
| 225 | * |
||
| 226 | * @var string |
||
| 227 | */ |
||
| 228 | public $rootDocumentName; |
||
| 229 | |||
| 230 | /** |
||
| 231 | * The name of the custom repository class used for the document class. |
||
| 232 | * (Optional). |
||
| 233 | * |
||
| 234 | * @var string |
||
| 235 | */ |
||
| 236 | public $customRepositoryClassName; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * READ-ONLY: The names of the parent classes (ancestors). |
||
| 240 | * |
||
| 241 | * @var array |
||
| 242 | */ |
||
| 243 | public $parentClasses = array(); |
||
| 244 | |||
| 245 | /** |
||
| 246 | * READ-ONLY: The names of all subclasses (descendants). |
||
| 247 | * |
||
| 248 | * @var array |
||
| 249 | */ |
||
| 250 | public $subClasses = array(); |
||
| 251 | |||
| 252 | /** |
||
| 253 | * The ReflectionProperty instances of the mapped class. |
||
| 254 | * |
||
| 255 | * @var \ReflectionProperty[] |
||
| 256 | */ |
||
| 257 | public $reflFields = array(); |
||
| 258 | |||
| 259 | /** |
||
| 260 | * READ-ONLY: The inheritance mapping type used by the class. |
||
| 261 | * |
||
| 262 | * @var integer |
||
| 263 | */ |
||
| 264 | public $inheritanceType = self::INHERITANCE_TYPE_NONE; |
||
| 265 | |||
| 266 | /** |
||
| 267 | * READ-ONLY: The Id generator type used by the class. |
||
| 268 | * |
||
| 269 | * @var string |
||
| 270 | */ |
||
| 271 | public $generatorType = self::GENERATOR_TYPE_AUTO; |
||
| 272 | |||
| 273 | /** |
||
| 274 | * READ-ONLY: The Id generator options. |
||
| 275 | * |
||
| 276 | * @var array |
||
| 277 | */ |
||
| 278 | public $generatorOptions = array(); |
||
| 279 | |||
| 280 | /** |
||
| 281 | * READ-ONLY: The ID generator used for generating IDs for this class. |
||
| 282 | * |
||
| 283 | * @var \Doctrine\ODM\MongoDB\Id\AbstractIdGenerator |
||
| 284 | */ |
||
| 285 | public $idGenerator; |
||
| 286 | |||
| 287 | /** |
||
| 288 | * READ-ONLY: The field mappings of the class. |
||
| 289 | * Keys are field names and values are mapping definitions. |
||
| 290 | * |
||
| 291 | * The mapping definition array has the following values: |
||
| 292 | * |
||
| 293 | * - <b>fieldName</b> (string) |
||
| 294 | * The name of the field in the Document. |
||
| 295 | * |
||
| 296 | * - <b>id</b> (boolean, optional) |
||
| 297 | * Marks the field as the primary key of the document. Multiple fields of an |
||
| 298 | * document can have the id attribute, forming a composite key. |
||
| 299 | * |
||
| 300 | * @var array |
||
| 301 | */ |
||
| 302 | public $fieldMappings = array(); |
||
| 303 | |||
| 304 | /** |
||
| 305 | * READ-ONLY: The association mappings of the class. |
||
| 306 | * Keys are field names and values are mapping definitions. |
||
| 307 | * |
||
| 308 | * @var array |
||
| 309 | */ |
||
| 310 | public $associationMappings = array(); |
||
| 311 | |||
| 312 | /** |
||
| 313 | * READ-ONLY: Array of fields to also load with a given method. |
||
| 314 | * |
||
| 315 | * @var array |
||
| 316 | */ |
||
| 317 | public $alsoLoadMethods = array(); |
||
| 318 | |||
| 319 | /** |
||
| 320 | * READ-ONLY: The registered lifecycle callbacks for documents of this class. |
||
| 321 | * |
||
| 322 | * @var array |
||
| 323 | */ |
||
| 324 | public $lifecycleCallbacks = array(); |
||
| 325 | |||
| 326 | /** |
||
| 327 | * READ-ONLY: The discriminator value of this class. |
||
| 328 | * |
||
| 329 | * <b>This does only apply to the JOINED and SINGLE_COLLECTION inheritance mapping strategies |
||
| 330 | * where a discriminator field is used.</b> |
||
| 331 | * |
||
| 332 | * @var mixed |
||
| 333 | * @see discriminatorField |
||
| 334 | */ |
||
| 335 | public $discriminatorValue; |
||
| 336 | |||
| 337 | /** |
||
| 338 | * READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
||
| 339 | * |
||
| 340 | * <b>This does only apply to the SINGLE_COLLECTION inheritance mapping strategy |
||
| 341 | * where a discriminator field is used.</b> |
||
| 342 | * |
||
| 343 | * @var mixed |
||
| 344 | * @see discriminatorField |
||
| 345 | */ |
||
| 346 | public $discriminatorMap = array(); |
||
| 347 | |||
| 348 | /** |
||
| 349 | * READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION |
||
| 350 | * inheritance mapping. |
||
| 351 | * |
||
| 352 | * @var string |
||
| 353 | */ |
||
| 354 | public $discriminatorField; |
||
| 355 | |||
| 356 | /** |
||
| 357 | * READ-ONLY: The default value for discriminatorField in case it's not set in the document |
||
| 358 | * |
||
| 359 | * @var string |
||
| 360 | * @see discriminatorField |
||
| 361 | */ |
||
| 362 | public $defaultDiscriminatorValue; |
||
| 363 | |||
| 364 | /** |
||
| 365 | * READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
||
| 366 | * |
||
| 367 | * @var boolean |
||
| 368 | */ |
||
| 369 | public $isMappedSuperclass = false; |
||
| 370 | |||
| 371 | /** |
||
| 372 | * READ-ONLY: Whether this class describes the mapping of a embedded document. |
||
| 373 | * |
||
| 374 | * @var boolean |
||
| 375 | */ |
||
| 376 | public $isEmbeddedDocument = false; |
||
| 377 | |||
| 378 | /** |
||
| 379 | * READ-ONLY: Whether this class describes the mapping of an aggregation result document. |
||
| 380 | * |
||
| 381 | * @var boolean |
||
| 382 | */ |
||
| 383 | public $isQueryResultDocument = false; |
||
| 384 | |||
| 385 | /** |
||
| 386 | * READ-ONLY: The policy used for change-tracking on entities of this class. |
||
| 387 | * |
||
| 388 | * @var integer |
||
| 389 | */ |
||
| 390 | public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT; |
||
| 391 | |||
| 392 | /** |
||
| 393 | * READ-ONLY: A flag for whether or not instances of this class are to be versioned |
||
| 394 | * with optimistic locking. |
||
| 395 | * |
||
| 396 | * @var boolean $isVersioned |
||
| 397 | */ |
||
| 398 | public $isVersioned; |
||
| 399 | |||
| 400 | /** |
||
| 401 | * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). |
||
| 402 | * |
||
| 403 | * @var mixed $versionField |
||
| 404 | */ |
||
| 405 | public $versionField; |
||
| 406 | |||
| 407 | /** |
||
| 408 | * READ-ONLY: A flag for whether or not instances of this class are to allow pessimistic |
||
| 409 | * locking. |
||
| 410 | * |
||
| 411 | * @var boolean $isLockable |
||
| 412 | */ |
||
| 413 | public $isLockable; |
||
| 414 | |||
| 415 | /** |
||
| 416 | * READ-ONLY: The name of the field which is used for locking a document. |
||
| 417 | * |
||
| 418 | * @var mixed $lockField |
||
| 419 | */ |
||
| 420 | public $lockField; |
||
| 421 | |||
| 422 | /** |
||
| 423 | * The ReflectionClass instance of the mapped class. |
||
| 424 | * |
||
| 425 | * @var \ReflectionClass |
||
| 426 | */ |
||
| 427 | public $reflClass; |
||
| 428 | |||
| 429 | /** |
||
| 430 | * READ_ONLY: A flag for whether or not this document is read-only. |
||
| 431 | * |
||
| 432 | * @var bool |
||
| 433 | */ |
||
| 434 | public $isReadOnly; |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @var \Doctrine\Instantiator\InstantiatorInterface|null |
||
| 438 | */ |
||
| 439 | private $instantiator; |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Initializes a new ClassMetadata instance that will hold the object-document mapping |
||
| 443 | * metadata of the class with the given name. |
||
| 444 | * |
||
| 445 | * @param string $documentName The name of the document class the new instance is used for. |
||
| 446 | */ |
||
| 447 | 1475 | public function __construct($documentName) |
|
| 456 | |||
| 457 | /** |
||
| 458 | * Helper method to get reference id of ref* type references |
||
| 459 | * @param mixed $reference |
||
| 460 | * @param string $storeAs |
||
| 461 | * @return mixed |
||
| 462 | * @internal |
||
| 463 | */ |
||
| 464 | 120 | public static function getReferenceId($reference, $storeAs) |
|
| 468 | |||
| 469 | /** |
||
| 470 | * Returns the reference prefix used for a reference |
||
| 471 | * @param string $storeAs |
||
| 472 | * @return string |
||
| 473 | */ |
||
| 474 | 185 | private static function getReferencePrefix($storeAs) |
|
| 482 | |||
| 483 | /** |
||
| 484 | * Returns a fully qualified field name for a given reference |
||
| 485 | * @param string $storeAs |
||
| 486 | * @param string $pathPrefix The field path prefix |
||
| 487 | * @return string |
||
| 488 | * @internal |
||
| 489 | */ |
||
| 490 | 134 | public static function getReferenceFieldName($storeAs, $pathPrefix = '') |
|
| 498 | |||
| 499 | /** |
||
| 500 | * {@inheritDoc} |
||
| 501 | */ |
||
| 502 | 1366 | public function getReflectionClass() |
|
| 510 | |||
| 511 | /** |
||
| 512 | * {@inheritDoc} |
||
| 513 | */ |
||
| 514 | 321 | public function isIdentifier($fieldName) |
|
| 518 | |||
| 519 | /** |
||
| 520 | * INTERNAL: |
||
| 521 | * Sets the mapped identifier field of this class. |
||
| 522 | * |
||
| 523 | * @param string $identifier |
||
| 524 | */ |
||
| 525 | 886 | public function setIdentifier($identifier) |
|
| 529 | |||
| 530 | /** |
||
| 531 | * {@inheritDoc} |
||
| 532 | * |
||
| 533 | * Since MongoDB only allows exactly one identifier field |
||
| 534 | * this will always return an array with only one value |
||
| 535 | */ |
||
| 536 | 38 | public function getIdentifier() |
|
| 540 | |||
| 541 | /** |
||
| 542 | * {@inheritDoc} |
||
| 543 | * |
||
| 544 | * Since MongoDB only allows exactly one identifier field |
||
| 545 | * this will always return an array with only one value |
||
| 546 | */ |
||
| 547 | 97 | public function getIdentifierFieldNames() |
|
| 551 | |||
| 552 | /** |
||
| 553 | * {@inheritDoc} |
||
| 554 | */ |
||
| 555 | 886 | public function hasField($fieldName) |
|
| 559 | |||
| 560 | /** |
||
| 561 | * Sets the inheritance type used by the class and it's subclasses. |
||
| 562 | * |
||
| 563 | * @param integer $type |
||
| 564 | */ |
||
| 565 | 902 | public function setInheritanceType($type) |
|
| 569 | |||
| 570 | /** |
||
| 571 | * Checks whether a mapped field is inherited from an entity superclass. |
||
| 572 | * |
||
| 573 | * @param string $fieldName |
||
| 574 | * |
||
| 575 | * @return boolean TRUE if the field is inherited, FALSE otherwise. |
||
| 576 | */ |
||
| 577 | 1362 | public function isInheritedField($fieldName) |
|
| 581 | |||
| 582 | /** |
||
| 583 | * Registers a custom repository class for the document class. |
||
| 584 | * |
||
| 585 | * @param string $repositoryClassName The class name of the custom repository. |
||
| 586 | */ |
||
| 587 | 834 | public function setCustomRepositoryClass($repositoryClassName) |
|
| 599 | |||
| 600 | /** |
||
| 601 | * Dispatches the lifecycle event of the given document by invoking all |
||
| 602 | * registered callbacks. |
||
| 603 | * |
||
| 604 | * @param string $event Lifecycle event |
||
| 605 | * @param object $document Document on which the event occurred |
||
| 606 | * @param array $arguments Arguments to pass to all callbacks |
||
| 607 | * @throws \InvalidArgumentException if document class is not this class or |
||
| 608 | * a Proxy of this class |
||
| 609 | */ |
||
| 610 | 599 | public function invokeLifecycleCallbacks($event, $document, array $arguments = null) |
|
| 628 | |||
| 629 | /** |
||
| 630 | * Checks whether the class has callbacks registered for a lifecycle event. |
||
| 631 | * |
||
| 632 | * @param string $event Lifecycle event |
||
| 633 | * |
||
| 634 | * @return boolean |
||
| 635 | */ |
||
| 636 | public function hasLifecycleCallbacks($event) |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Gets the registered lifecycle callbacks for an event. |
||
| 643 | * |
||
| 644 | * @param string $event |
||
| 645 | * @return array |
||
| 646 | */ |
||
| 647 | public function getLifecycleCallbacks($event) |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Adds a lifecycle callback for documents of this class. |
||
| 654 | * |
||
| 655 | * If the callback is already registered, this is a NOOP. |
||
| 656 | * |
||
| 657 | * @param string $callback |
||
| 658 | * @param string $event |
||
| 659 | */ |
||
| 660 | 802 | public function addLifecycleCallback($callback, $event) |
|
| 668 | |||
| 669 | /** |
||
| 670 | * Sets the lifecycle callbacks for documents of this class. |
||
| 671 | * |
||
| 672 | * Any previously registered callbacks are overwritten. |
||
| 673 | * |
||
| 674 | * @param array $callbacks |
||
| 675 | */ |
||
| 676 | 885 | public function setLifecycleCallbacks(array $callbacks) |
|
| 680 | |||
| 681 | /** |
||
| 682 | * Registers a method for loading document data before field hydration. |
||
| 683 | * |
||
| 684 | * Note: A method may be registered multiple times for different fields. |
||
| 685 | * it will be invoked only once for the first field found. |
||
| 686 | * |
||
| 687 | * @param string $method Method name |
||
| 688 | * @param array|string $fields Database field name(s) |
||
| 689 | */ |
||
| 690 | 14 | public function registerAlsoLoadMethod($method, $fields) |
|
| 694 | |||
| 695 | /** |
||
| 696 | * Sets the AlsoLoad methods for documents of this class. |
||
| 697 | * |
||
| 698 | * Any previously registered methods are overwritten. |
||
| 699 | * |
||
| 700 | * @param array $methods |
||
| 701 | */ |
||
| 702 | 885 | public function setAlsoLoadMethods(array $methods) |
|
| 706 | |||
| 707 | /** |
||
| 708 | * Sets the discriminator field. |
||
| 709 | * |
||
| 710 | * The field name is the the unmapped database field. Discriminator values |
||
| 711 | * are only used to discern the hydration class and are not mapped to class |
||
| 712 | * properties. |
||
| 713 | * |
||
| 714 | * @param string $discriminatorField |
||
| 715 | * |
||
| 716 | * @throws MappingException If the discriminator field conflicts with the |
||
| 717 | * "name" attribute of a mapped field. |
||
| 718 | */ |
||
| 719 | 911 | public function setDiscriminatorField($discriminatorField) |
|
| 744 | |||
| 745 | /** |
||
| 746 | * Sets the discriminator values used by this class. |
||
| 747 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
||
| 748 | * |
||
| 749 | * @param array $map |
||
| 750 | * |
||
| 751 | * @throws MappingException |
||
| 752 | */ |
||
| 753 | 904 | public function setDiscriminatorMap(array $map) |
|
| 754 | { |
||
| 755 | 904 | foreach ($map as $value => $className) { |
|
| 756 | 112 | View Code Duplication | if (strpos($className, '\\') === false && strlen($this->namespace)) { |
| 757 | 82 | $className = $this->namespace . '\\' . $className; |
|
| 758 | } |
||
| 759 | 112 | $this->discriminatorMap[$value] = $className; |
|
| 760 | 112 | if ($this->name == $className) { |
|
| 761 | 104 | $this->discriminatorValue = $value; |
|
| 762 | } else { |
||
| 763 | 111 | if ( ! class_exists($className)) { |
|
| 764 | throw MappingException::invalidClassInDiscriminatorMap($className, $this->name); |
||
| 765 | } |
||
| 766 | 111 | if (is_subclass_of($className, $this->name)) { |
|
| 767 | 112 | $this->subClasses[] = $className; |
|
| 768 | } |
||
| 769 | } |
||
| 770 | } |
||
| 771 | 904 | } |
|
| 772 | |||
| 773 | /** |
||
| 774 | * Sets the default discriminator value to be used for this class |
||
| 775 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value |
||
| 776 | * |
||
| 777 | * @param string $defaultDiscriminatorValue |
||
| 778 | * |
||
| 779 | * @throws MappingException |
||
| 780 | */ |
||
| 781 | 888 | public function setDefaultDiscriminatorValue($defaultDiscriminatorValue) |
|
| 795 | |||
| 796 | /** |
||
| 797 | * Sets the discriminator value for this class. |
||
| 798 | * Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single |
||
| 799 | * collection. |
||
| 800 | * |
||
| 801 | * @param string $value |
||
| 802 | */ |
||
| 803 | 3 | public function setDiscriminatorValue($value) |
|
| 808 | |||
| 809 | /** |
||
| 810 | * Add a index for this Document. |
||
| 811 | * |
||
| 812 | * @param array $keys Array of keys for the index. |
||
| 813 | * @param array $options Array of options for the index. |
||
| 814 | */ |
||
| 815 | 183 | public function addIndex($keys, array $options = array()) |
|
| 816 | { |
||
| 817 | 183 | $this->indexes[] = array( |
|
| 818 | 183 | View Code Duplication | 'keys' => array_map(function($value) { |
| 819 | 183 | if ($value == 1 || $value == -1) { |
|
| 820 | 54 | return (int) $value; |
|
| 821 | } |
||
| 822 | 176 | if (is_string($value)) { |
|
| 823 | 176 | $lower = strtolower($value); |
|
| 824 | 176 | if ($lower === 'asc') { |
|
| 825 | 176 | return 1; |
|
| 826 | } elseif ($lower === 'desc') { |
||
| 827 | return -1; |
||
| 828 | } |
||
| 829 | } |
||
| 830 | return $value; |
||
| 831 | 183 | }, $keys), |
|
| 832 | 183 | 'options' => $options |
|
| 833 | ); |
||
| 834 | 183 | } |
|
| 835 | |||
| 836 | /** |
||
| 837 | * Returns the array of indexes for this Document. |
||
| 838 | * |
||
| 839 | * @return array $indexes The array of indexes. |
||
| 840 | */ |
||
| 841 | 23 | public function getIndexes() |
|
| 845 | |||
| 846 | /** |
||
| 847 | * Checks whether this document has indexes or not. |
||
| 848 | * |
||
| 849 | * @return boolean |
||
| 850 | */ |
||
| 851 | public function hasIndexes() |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Set shard key for this Document. |
||
| 858 | * |
||
| 859 | * @param array $keys Array of document keys. |
||
| 860 | * @param array $options Array of sharding options. |
||
| 861 | * |
||
| 862 | * @throws MappingException |
||
| 863 | */ |
||
| 864 | 71 | public function setShardKey(array $keys, array $options = array()) |
|
| 865 | { |
||
| 866 | 71 | if ($this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_COLLECTION && !is_null($this->shardKey)) { |
|
| 867 | 2 | throw MappingException::shardKeyInSingleCollInheritanceSubclass($this->getName()); |
|
| 868 | } |
||
| 869 | |||
| 870 | 71 | if ($this->isEmbeddedDocument) { |
|
| 871 | 2 | throw MappingException::embeddedDocumentCantHaveShardKey($this->getName()); |
|
| 872 | } |
||
| 873 | |||
| 874 | 69 | foreach (array_keys($keys) as $field) { |
|
| 875 | 69 | if (! isset($this->fieldMappings[$field])) { |
|
| 876 | 62 | continue; |
|
| 877 | } |
||
| 878 | |||
| 879 | 7 | if (in_array($this->fieldMappings[$field]['type'], ['many', 'collection'])) { |
|
| 880 | 3 | throw MappingException::noMultiKeyShardKeys($this->getName(), $field); |
|
| 881 | } |
||
| 882 | |||
| 883 | 4 | if ($this->fieldMappings[$field]['strategy'] !== static::STORAGE_STRATEGY_SET) { |
|
| 884 | 4 | throw MappingException::onlySetStrategyAllowedInShardKey($this->getName(), $field); |
|
| 885 | } |
||
| 886 | } |
||
| 887 | |||
| 888 | 65 | $this->shardKey = array( |
|
| 889 | 65 | View Code Duplication | 'keys' => array_map(function($value) { |
| 890 | 65 | if ($value == 1 || $value == -1) { |
|
| 891 | 6 | return (int) $value; |
|
| 892 | } |
||
| 893 | 64 | if (is_string($value)) { |
|
| 894 | 64 | $lower = strtolower($value); |
|
| 895 | 64 | if ($lower === 'asc') { |
|
| 896 | 63 | return 1; |
|
| 897 | 46 | } elseif ($lower === 'desc') { |
|
| 898 | return -1; |
||
| 899 | } |
||
| 900 | } |
||
| 901 | 46 | return $value; |
|
| 902 | 65 | }, $keys), |
|
| 903 | 65 | 'options' => $options |
|
| 904 | ); |
||
| 905 | 65 | } |
|
| 906 | |||
| 907 | /** |
||
| 908 | * @return array |
||
| 909 | */ |
||
| 910 | 17 | public function getShardKey() |
|
| 914 | |||
| 915 | /** |
||
| 916 | * Checks whether this document has shard key or not. |
||
| 917 | * |
||
| 918 | * @return bool |
||
| 919 | */ |
||
| 920 | 1096 | public function isSharded() |
|
| 924 | |||
| 925 | /** |
||
| 926 | * Sets the read preference used by this class. |
||
| 927 | * |
||
| 928 | * @param string $readPreference |
||
| 929 | * @param array|null $tags |
||
| 930 | */ |
||
| 931 | 885 | public function setReadPreference($readPreference, $tags) |
|
| 936 | |||
| 937 | /** |
||
| 938 | * Sets the write concern used by this class. |
||
| 939 | * |
||
| 940 | * @param string $writeConcern |
||
| 941 | */ |
||
| 942 | 895 | public function setWriteConcern($writeConcern) |
|
| 946 | |||
| 947 | /** |
||
| 948 | * @return string |
||
| 949 | */ |
||
| 950 | 11 | public function getWriteConcern() |
|
| 954 | |||
| 955 | /** |
||
| 956 | * Whether there is a write concern configured for this class. |
||
| 957 | * |
||
| 958 | * @return bool |
||
| 959 | */ |
||
| 960 | 548 | public function hasWriteConcern() |
|
| 964 | |||
| 965 | /** |
||
| 966 | * Sets the change tracking policy used by this class. |
||
| 967 | * |
||
| 968 | * @param integer $policy |
||
| 969 | */ |
||
| 970 | 887 | public function setChangeTrackingPolicy($policy) |
|
| 974 | |||
| 975 | /** |
||
| 976 | * Whether the change tracking policy of this class is "deferred explicit". |
||
| 977 | * |
||
| 978 | * @return boolean |
||
| 979 | */ |
||
| 980 | 61 | public function isChangeTrackingDeferredExplicit() |
|
| 984 | |||
| 985 | /** |
||
| 986 | * Whether the change tracking policy of this class is "deferred implicit". |
||
| 987 | * |
||
| 988 | * @return boolean |
||
| 989 | */ |
||
| 990 | 568 | public function isChangeTrackingDeferredImplicit() |
|
| 994 | |||
| 995 | /** |
||
| 996 | * Whether the change tracking policy of this class is "notify". |
||
| 997 | * |
||
| 998 | * @return boolean |
||
| 999 | */ |
||
| 1000 | 308 | public function isChangeTrackingNotify() |
|
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Gets the ReflectionProperties of the mapped class. |
||
| 1007 | * |
||
| 1008 | * @return array An array of ReflectionProperty instances. |
||
| 1009 | */ |
||
| 1010 | 97 | public function getReflectionProperties() |
|
| 1014 | |||
| 1015 | /** |
||
| 1016 | * Gets a ReflectionProperty for a specific field of the mapped class. |
||
| 1017 | * |
||
| 1018 | * @param string $name |
||
| 1019 | * |
||
| 1020 | * @return \ReflectionProperty |
||
| 1021 | */ |
||
| 1022 | public function getReflectionProperty($name) |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * {@inheritDoc} |
||
| 1029 | */ |
||
| 1030 | 1371 | public function getName() |
|
| 1034 | |||
| 1035 | /** |
||
| 1036 | * The namespace this Document class belongs to. |
||
| 1037 | * |
||
| 1038 | * @return string $namespace The namespace name. |
||
| 1039 | */ |
||
| 1040 | public function getNamespace() |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Returns the database this Document is mapped to. |
||
| 1047 | * |
||
| 1048 | * @return string $db The database name. |
||
| 1049 | */ |
||
| 1050 | 1295 | public function getDatabase() |
|
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Set the database this Document is mapped to. |
||
| 1057 | * |
||
| 1058 | * @param string $db The database name |
||
| 1059 | */ |
||
| 1060 | 92 | public function setDatabase($db) |
|
| 1064 | |||
| 1065 | /** |
||
| 1066 | * Get the collection this Document is mapped to. |
||
| 1067 | * |
||
| 1068 | * @return string $collection The collection name. |
||
| 1069 | */ |
||
| 1070 | 1296 | public function getCollection() |
|
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Sets the collection this Document is mapped to. |
||
| 1077 | * |
||
| 1078 | * @param array|string $name |
||
| 1079 | * |
||
| 1080 | * @throws \InvalidArgumentException |
||
| 1081 | */ |
||
| 1082 | 1475 | public function setCollection($name) |
|
| 1083 | { |
||
| 1084 | 1475 | if (is_array($name)) { |
|
| 1085 | 1 | if ( ! isset($name['name'])) { |
|
| 1086 | throw new \InvalidArgumentException('A name key is required when passing an array to setCollection()'); |
||
| 1087 | } |
||
| 1088 | 1 | $this->collectionCapped = $name['capped'] ?? false; |
|
| 1089 | 1 | $this->collectionSize = $name['size'] ?? 0; |
|
| 1090 | 1 | $this->collectionMax = $name['max'] ?? 0; |
|
| 1091 | 1 | $this->collection = $name['name']; |
|
| 1092 | } else { |
||
| 1093 | 1475 | $this->collection = $name; |
|
| 1094 | } |
||
| 1095 | 1475 | } |
|
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Get whether or not the documents collection is capped. |
||
| 1099 | * |
||
| 1100 | * @return boolean |
||
| 1101 | */ |
||
| 1102 | 5 | public function getCollectionCapped() |
|
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Set whether or not the documents collection is capped. |
||
| 1109 | * |
||
| 1110 | * @param boolean $bool |
||
| 1111 | */ |
||
| 1112 | 1 | public function setCollectionCapped($bool) |
|
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Get the collection size |
||
| 1119 | * |
||
| 1120 | * @return integer |
||
| 1121 | */ |
||
| 1122 | 5 | public function getCollectionSize() |
|
| 1126 | |||
| 1127 | /** |
||
| 1128 | * Set the collection size. |
||
| 1129 | * |
||
| 1130 | * @param integer $size |
||
| 1131 | */ |
||
| 1132 | 1 | public function setCollectionSize($size) |
|
| 1136 | |||
| 1137 | /** |
||
| 1138 | * Get the collection max. |
||
| 1139 | * |
||
| 1140 | * @return integer |
||
| 1141 | */ |
||
| 1142 | 5 | public function getCollectionMax() |
|
| 1146 | |||
| 1147 | /** |
||
| 1148 | * Set the collection max. |
||
| 1149 | * |
||
| 1150 | * @param integer $max |
||
| 1151 | */ |
||
| 1152 | 1 | public function setCollectionMax($max) |
|
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Returns TRUE if this Document is mapped to a collection FALSE otherwise. |
||
| 1159 | * |
||
| 1160 | * @return boolean |
||
| 1161 | */ |
||
| 1162 | public function isMappedToCollection() |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Validates the storage strategy of a mapping for consistency |
||
| 1169 | * @param array $mapping |
||
| 1170 | * @throws \Doctrine\ODM\MongoDB\Mapping\MappingException |
||
| 1171 | */ |
||
| 1172 | 1388 | private function applyStorageStrategy(array &$mapping) |
|
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Map a single embedded document. |
||
| 1218 | * |
||
| 1219 | * @param array $mapping The mapping information. |
||
| 1220 | */ |
||
| 1221 | 6 | public function mapOneEmbedded(array $mapping) |
|
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Map a collection of embedded documents. |
||
| 1230 | * |
||
| 1231 | * @param array $mapping The mapping information. |
||
| 1232 | */ |
||
| 1233 | 5 | public function mapManyEmbedded(array $mapping) |
|
| 1239 | |||
| 1240 | /** |
||
| 1241 | * Map a single document reference. |
||
| 1242 | * |
||
| 1243 | * @param array $mapping The mapping information. |
||
| 1244 | */ |
||
| 1245 | 2 | public function mapOneReference(array $mapping) |
|
| 1251 | |||
| 1252 | /** |
||
| 1253 | * Map a collection of document references. |
||
| 1254 | * |
||
| 1255 | * @param array $mapping The mapping information. |
||
| 1256 | */ |
||
| 1257 | 1 | public function mapManyReference(array $mapping) |
|
| 1263 | |||
| 1264 | /** |
||
| 1265 | * INTERNAL: |
||
| 1266 | * Adds a field mapping without completing/validating it. |
||
| 1267 | * This is mainly used to add inherited field mappings to derived classes. |
||
| 1268 | * |
||
| 1269 | * @param array $fieldMapping |
||
| 1270 | */ |
||
| 1271 | 116 | public function addInheritedFieldMapping(array $fieldMapping) |
|
| 1279 | |||
| 1280 | /** |
||
| 1281 | * INTERNAL: |
||
| 1282 | * Adds an association mapping without completing/validating it. |
||
| 1283 | * This is mainly used to add inherited association mappings to derived classes. |
||
| 1284 | * |
||
| 1285 | * @param array $mapping |
||
| 1286 | * |
||
| 1287 | * @return void |
||
| 1288 | * |
||
| 1289 | * @throws MappingException |
||
| 1290 | */ |
||
| 1291 | 68 | public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/) |
|
| 1295 | |||
| 1296 | /** |
||
| 1297 | * Checks whether the class has a mapped association with the given field name. |
||
| 1298 | * |
||
| 1299 | * @param string $fieldName |
||
| 1300 | * @return boolean |
||
| 1301 | */ |
||
| 1302 | 32 | public function hasReference($fieldName) |
|
| 1306 | |||
| 1307 | /** |
||
| 1308 | * Checks whether the class has a mapped embed with the given field name. |
||
| 1309 | * |
||
| 1310 | * @param string $fieldName |
||
| 1311 | * @return boolean |
||
| 1312 | */ |
||
| 1313 | 5 | public function hasEmbed($fieldName) |
|
| 1317 | |||
| 1318 | /** |
||
| 1319 | * {@inheritDoc} |
||
| 1320 | * |
||
| 1321 | * Checks whether the class has a mapped association (embed or reference) with the given field name. |
||
| 1322 | */ |
||
| 1323 | 7 | public function hasAssociation($fieldName) |
|
| 1327 | |||
| 1328 | /** |
||
| 1329 | * {@inheritDoc} |
||
| 1330 | * |
||
| 1331 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1332 | * is a single valued association. |
||
| 1333 | */ |
||
| 1334 | public function isSingleValuedAssociation($fieldName) |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * {@inheritDoc} |
||
| 1341 | * |
||
| 1342 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1343 | * is a collection valued association. |
||
| 1344 | */ |
||
| 1345 | public function isCollectionValuedAssociation($fieldName) |
||
| 1349 | |||
| 1350 | /** |
||
| 1351 | * Checks whether the class has a mapped association for the specified field |
||
| 1352 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1353 | * |
||
| 1354 | * @param string $fieldName |
||
| 1355 | * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1356 | */ |
||
| 1357 | public function isSingleValuedReference($fieldName) |
||
| 1362 | |||
| 1363 | /** |
||
| 1364 | * Checks whether the class has a mapped association for the specified field |
||
| 1365 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1366 | * |
||
| 1367 | * @param string $fieldName |
||
| 1368 | * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. |
||
| 1369 | */ |
||
| 1370 | public function isCollectionValuedReference($fieldName) |
||
| 1375 | |||
| 1376 | /** |
||
| 1377 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1378 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1379 | * |
||
| 1380 | * @param string $fieldName |
||
| 1381 | * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1382 | */ |
||
| 1383 | public function isSingleValuedEmbed($fieldName) |
||
| 1388 | |||
| 1389 | /** |
||
| 1390 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1391 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1392 | * |
||
| 1393 | * @param string $fieldName |
||
| 1394 | * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. |
||
| 1395 | */ |
||
| 1396 | public function isCollectionValuedEmbed($fieldName) |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Sets the ID generator used to generate IDs for instances of this class. |
||
| 1404 | * |
||
| 1405 | * @param \Doctrine\ODM\MongoDB\Id\AbstractIdGenerator $generator |
||
| 1406 | */ |
||
| 1407 | 1306 | public function setIdGenerator($generator) |
|
| 1411 | |||
| 1412 | /** |
||
| 1413 | * Casts the identifier to its portable PHP type. |
||
| 1414 | * |
||
| 1415 | * @param mixed $id |
||
| 1416 | * @return mixed $id |
||
| 1417 | */ |
||
| 1418 | 590 | public function getPHPIdentifierValue($id) |
|
| 1423 | |||
| 1424 | /** |
||
| 1425 | * Casts the identifier to its database type. |
||
| 1426 | * |
||
| 1427 | * @param mixed $id |
||
| 1428 | * @return mixed $id |
||
| 1429 | */ |
||
| 1430 | 655 | public function getDatabaseIdentifierValue($id) |
|
| 1435 | |||
| 1436 | /** |
||
| 1437 | * Sets the document identifier of a document. |
||
| 1438 | * |
||
| 1439 | * The value will be converted to a PHP type before being set. |
||
| 1440 | * |
||
| 1441 | * @param object $document |
||
| 1442 | * @param mixed $id |
||
| 1443 | */ |
||
| 1444 | 519 | public function setIdentifierValue($document, $id) |
|
| 1449 | |||
| 1450 | /** |
||
| 1451 | * Gets the document identifier as a PHP type. |
||
| 1452 | * |
||
| 1453 | * @param object $document |
||
| 1454 | * @return mixed $id |
||
| 1455 | */ |
||
| 1456 | 603 | public function getIdentifierValue($document) |
|
| 1460 | |||
| 1461 | /** |
||
| 1462 | * {@inheritDoc} |
||
| 1463 | * |
||
| 1464 | * Since MongoDB only allows exactly one identifier field this is a proxy |
||
| 1465 | * to {@see getIdentifierValue()} and returns an array with the identifier |
||
| 1466 | * field as a key. |
||
| 1467 | */ |
||
| 1468 | public function getIdentifierValues($object) |
||
| 1472 | |||
| 1473 | /** |
||
| 1474 | * Get the document identifier object as a database type. |
||
| 1475 | * |
||
| 1476 | * @param object $document |
||
| 1477 | * |
||
| 1478 | * @return \MongoDB\BSON\ObjectId $id The ObjectId |
||
| 1479 | */ |
||
| 1480 | 31 | public function getIdentifierObject($document) |
|
| 1484 | |||
| 1485 | /** |
||
| 1486 | * Sets the specified field to the specified value on the given document. |
||
| 1487 | * |
||
| 1488 | * @param object $document |
||
| 1489 | * @param string $field |
||
| 1490 | * @param mixed $value |
||
| 1491 | */ |
||
| 1492 | 8 | public function setFieldValue($document, $field, $value) |
|
| 1502 | |||
| 1503 | /** |
||
| 1504 | * Gets the specified field's value off the given document. |
||
| 1505 | * |
||
| 1506 | * @param object $document |
||
| 1507 | * @param string $field |
||
| 1508 | * |
||
| 1509 | * @return mixed |
||
| 1510 | */ |
||
| 1511 | 27 | public function getFieldValue($document, $field) |
|
| 1519 | |||
| 1520 | /** |
||
| 1521 | * Gets the mapping of a field. |
||
| 1522 | * |
||
| 1523 | * @param string $fieldName The field name. |
||
| 1524 | * |
||
| 1525 | * @return array The field mapping. |
||
| 1526 | * |
||
| 1527 | * @throws MappingException if the $fieldName is not found in the fieldMappings array |
||
| 1528 | */ |
||
| 1529 | 167 | public function getFieldMapping($fieldName) |
|
| 1536 | |||
| 1537 | /** |
||
| 1538 | * Gets mappings of fields holding embedded document(s). |
||
| 1539 | * |
||
| 1540 | * @return array of field mappings |
||
| 1541 | */ |
||
| 1542 | 559 | public function getEmbeddedFieldsMappings() |
|
| 1549 | |||
| 1550 | /** |
||
| 1551 | * Gets the field mapping by its DB name. |
||
| 1552 | * E.g. it returns identifier's mapping when called with _id. |
||
| 1553 | * |
||
| 1554 | * @param string $dbFieldName |
||
| 1555 | * |
||
| 1556 | * @return array |
||
| 1557 | * @throws MappingException |
||
| 1558 | */ |
||
| 1559 | 4 | public function getFieldMappingByDbFieldName($dbFieldName) |
|
| 1569 | |||
| 1570 | /** |
||
| 1571 | * Check if the field is not null. |
||
| 1572 | * |
||
| 1573 | * @param string $fieldName The field name |
||
| 1574 | * |
||
| 1575 | * @return boolean TRUE if the field is not null, FALSE otherwise. |
||
| 1576 | */ |
||
| 1577 | 1 | public function isNullable($fieldName) |
|
| 1585 | |||
| 1586 | /** |
||
| 1587 | * Checks whether the document has a discriminator field and value configured. |
||
| 1588 | * |
||
| 1589 | * @return boolean |
||
| 1590 | */ |
||
| 1591 | 492 | public function hasDiscriminator() |
|
| 1595 | |||
| 1596 | /** |
||
| 1597 | * Sets the type of Id generator to use for the mapped class. |
||
| 1598 | * |
||
| 1599 | * @param string $generatorType Generator type. |
||
| 1600 | */ |
||
| 1601 | 885 | public function setIdGeneratorType($generatorType) |
|
| 1605 | |||
| 1606 | /** |
||
| 1607 | * Sets the Id generator options. |
||
| 1608 | * |
||
| 1609 | * @param array $generatorOptions Generator options. |
||
| 1610 | */ |
||
| 1611 | public function setIdGeneratorOptions($generatorOptions) |
||
| 1615 | |||
| 1616 | /** |
||
| 1617 | * @return boolean |
||
| 1618 | */ |
||
| 1619 | 566 | public function isInheritanceTypeNone() |
|
| 1623 | |||
| 1624 | /** |
||
| 1625 | * Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy. |
||
| 1626 | * |
||
| 1627 | * @return boolean |
||
| 1628 | */ |
||
| 1629 | 884 | public function isInheritanceTypeSingleCollection() |
|
| 1633 | |||
| 1634 | /** |
||
| 1635 | * Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy. |
||
| 1636 | * |
||
| 1637 | * @return boolean |
||
| 1638 | */ |
||
| 1639 | public function isInheritanceTypeCollectionPerClass() |
||
| 1643 | |||
| 1644 | /** |
||
| 1645 | * Sets the mapped subclasses of this class. |
||
| 1646 | * |
||
| 1647 | * @param string[] $subclasses The names of all mapped subclasses. |
||
| 1648 | */ |
||
| 1649 | 2 | public function setSubclasses(array $subclasses) |
|
| 1659 | |||
| 1660 | /** |
||
| 1661 | * Sets the parent class names. |
||
| 1662 | * Assumes that the class names in the passed array are in the order: |
||
| 1663 | * directParent -> directParentParent -> directParentParentParent ... -> root. |
||
| 1664 | * |
||
| 1665 | * @param string[] $classNames |
||
| 1666 | */ |
||
| 1667 | 1362 | public function setParentClasses(array $classNames) |
|
| 1675 | |||
| 1676 | /** |
||
| 1677 | * Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us. |
||
| 1678 | * |
||
| 1679 | * @return boolean TRUE if the class uses the AUTO generator, FALSE otherwise. |
||
| 1680 | */ |
||
| 1681 | public function isIdGeneratorAuto() |
||
| 1685 | |||
| 1686 | /** |
||
| 1687 | * Checks whether the class will use a collection to generate incremented identifiers. |
||
| 1688 | * |
||
| 1689 | * @return boolean TRUE if the class uses the INCREMENT generator, FALSE otherwise. |
||
| 1690 | */ |
||
| 1691 | public function isIdGeneratorIncrement() |
||
| 1695 | |||
| 1696 | /** |
||
| 1697 | * Checks whether the class will generate a uuid id. |
||
| 1698 | * |
||
| 1699 | * @return boolean TRUE if the class uses the UUID generator, FALSE otherwise. |
||
| 1700 | */ |
||
| 1701 | public function isIdGeneratorUuid() |
||
| 1705 | |||
| 1706 | /** |
||
| 1707 | * Checks whether the class uses no id generator. |
||
| 1708 | * |
||
| 1709 | * @return boolean TRUE if the class does not use any id generator, FALSE otherwise. |
||
| 1710 | */ |
||
| 1711 | public function isIdGeneratorNone() |
||
| 1715 | |||
| 1716 | /** |
||
| 1717 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1718 | * value to use depending on the column type. |
||
| 1719 | * |
||
| 1720 | * @param array $mapping The version field mapping array |
||
| 1721 | * |
||
| 1722 | * @throws LockException |
||
| 1723 | */ |
||
| 1724 | 67 | public function setVersionMapping(array &$mapping) |
|
| 1733 | |||
| 1734 | /** |
||
| 1735 | * Sets whether this class is to be versioned for optimistic locking. |
||
| 1736 | * |
||
| 1737 | * @param boolean $bool |
||
| 1738 | */ |
||
| 1739 | 885 | public function setVersioned($bool) |
|
| 1743 | |||
| 1744 | /** |
||
| 1745 | * Sets the name of the field that is to be used for versioning if this class is |
||
| 1746 | * versioned for optimistic locking. |
||
| 1747 | * |
||
| 1748 | * @param string $versionField |
||
| 1749 | */ |
||
| 1750 | 885 | public function setVersionField($versionField) |
|
| 1754 | |||
| 1755 | /** |
||
| 1756 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1757 | * value to use depending on the column type. |
||
| 1758 | * |
||
| 1759 | * @param array $mapping The version field mapping array |
||
| 1760 | * |
||
| 1761 | * @throws \Doctrine\ODM\MongoDB\LockException |
||
| 1762 | */ |
||
| 1763 | 22 | public function setLockMapping(array &$mapping) |
|
| 1772 | |||
| 1773 | /** |
||
| 1774 | * Sets whether this class is to allow pessimistic locking. |
||
| 1775 | * |
||
| 1776 | * @param boolean $bool |
||
| 1777 | */ |
||
| 1778 | public function setLockable($bool) |
||
| 1782 | |||
| 1783 | /** |
||
| 1784 | * Sets the name of the field that is to be used for storing whether a document |
||
| 1785 | * is currently locked or not. |
||
| 1786 | * |
||
| 1787 | * @param string $lockField |
||
| 1788 | */ |
||
| 1789 | public function setLockField($lockField) |
||
| 1793 | |||
| 1794 | /** |
||
| 1795 | * Marks this class as read only, no change tracking is applied to it. |
||
| 1796 | */ |
||
| 1797 | 5 | public function markReadOnly() |
|
| 1801 | |||
| 1802 | /** |
||
| 1803 | * {@inheritDoc} |
||
| 1804 | */ |
||
| 1805 | public function getFieldNames() |
||
| 1809 | |||
| 1810 | /** |
||
| 1811 | * {@inheritDoc} |
||
| 1812 | */ |
||
| 1813 | public function getAssociationNames() |
||
| 1817 | |||
| 1818 | /** |
||
| 1819 | * {@inheritDoc} |
||
| 1820 | */ |
||
| 1821 | 23 | public function getTypeOfField($fieldName) |
|
| 1826 | |||
| 1827 | /** |
||
| 1828 | * {@inheritDoc} |
||
| 1829 | */ |
||
| 1830 | 4 | public function getAssociationTargetClass($assocName) |
|
| 1838 | |||
| 1839 | /** |
||
| 1840 | * Retrieve the collectionClass associated with an association |
||
| 1841 | * |
||
| 1842 | * @param string $assocName |
||
| 1843 | */ |
||
| 1844 | 1 | public function getAssociationCollectionClass($assocName) |
|
| 1856 | |||
| 1857 | /** |
||
| 1858 | * {@inheritDoc} |
||
| 1859 | */ |
||
| 1860 | public function isAssociationInverseSide($fieldName) |
||
| 1864 | |||
| 1865 | /** |
||
| 1866 | * {@inheritDoc} |
||
| 1867 | */ |
||
| 1868 | public function getAssociationMappedByTargetField($fieldName) |
||
| 1872 | |||
| 1873 | /** |
||
| 1874 | * Map a field. |
||
| 1875 | * |
||
| 1876 | * @param array $mapping The mapping information. |
||
| 1877 | * |
||
| 1878 | * @return array |
||
| 1879 | * |
||
| 1880 | * @throws MappingException |
||
| 1881 | */ |
||
| 1882 | 1400 | public function mapField(array $mapping) |
|
| 2057 | |||
| 2058 | /** |
||
| 2059 | * Determines which fields get serialized. |
||
| 2060 | * |
||
| 2061 | * It is only serialized what is necessary for best unserialization performance. |
||
| 2062 | * That means any metadata properties that are not set or empty or simply have |
||
| 2063 | * their default value are NOT serialized. |
||
| 2064 | * |
||
| 2065 | * Parts that are also NOT serialized because they can not be properly unserialized: |
||
| 2066 | * - reflClass (ReflectionClass) |
||
| 2067 | * - reflFields (ReflectionProperty array) |
||
| 2068 | * |
||
| 2069 | * @return array The names of all the fields that should be serialized. |
||
| 2070 | */ |
||
| 2071 | 6 | public function __sleep() |
|
| 2145 | |||
| 2146 | /** |
||
| 2147 | * Restores some state that can not be serialized/unserialized. |
||
| 2148 | * |
||
| 2149 | * @return void |
||
| 2150 | */ |
||
| 2151 | 6 | public function __wakeup() |
|
| 2167 | |||
| 2168 | /** |
||
| 2169 | * Creates a new instance of the mapped class, without invoking the constructor. |
||
| 2170 | * |
||
| 2171 | * @return object |
||
| 2172 | */ |
||
| 2173 | 354 | public function newInstance() |
|
| 2177 | } |
||
| 2178 |
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..