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 ClassMetadataInfo 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 ClassMetadataInfo, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class ClassMetadataInfo implements \Doctrine\Common\Persistence\Mapping\ClassMetadata |
||
| 28 | { |
||
| 29 | /* The Id generator types. */ |
||
| 30 | /** |
||
| 31 | * AUTO means Doctrine will automatically create a new \MongoDB\BSON\ObjectId instance for us. |
||
| 32 | */ |
||
| 33 | const GENERATOR_TYPE_AUTO = 1; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * INCREMENT means a separate collection is used for maintaining and incrementing id generation. |
||
| 37 | * Offers full portability. |
||
| 38 | */ |
||
| 39 | const GENERATOR_TYPE_INCREMENT = 2; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * UUID means Doctrine will generate a uuid for us. |
||
| 43 | */ |
||
| 44 | const GENERATOR_TYPE_UUID = 3; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * ALNUM means Doctrine will generate Alpha-numeric string identifiers, using the INCREMENT |
||
| 48 | * generator to ensure identifier uniqueness |
||
| 49 | */ |
||
| 50 | const GENERATOR_TYPE_ALNUM = 4; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * CUSTOM means Doctrine expect a class parameter. It will then try to initiate that class |
||
| 54 | * and pass other options to the generator. It will throw an Exception if the class |
||
| 55 | * does not exist or if an option was passed for that there is not setter in the new |
||
| 56 | * generator class. |
||
| 57 | * |
||
| 58 | * The class will have to be a subtype of AbstractIdGenerator. |
||
| 59 | */ |
||
| 60 | const GENERATOR_TYPE_CUSTOM = 5; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * NONE means Doctrine will not generate any id for us and you are responsible for manually |
||
| 64 | * assigning an id. |
||
| 65 | */ |
||
| 66 | const GENERATOR_TYPE_NONE = 6; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Default discriminator field name. |
||
| 70 | * |
||
| 71 | * This is used for associations value for associations where a that do not define a "targetDocument" or |
||
| 72 | * "discriminatorField" option in their mapping. |
||
| 73 | */ |
||
| 74 | const DEFAULT_DISCRIMINATOR_FIELD = '_doctrine_class_name'; |
||
| 75 | |||
| 76 | const REFERENCE_ONE = 1; |
||
| 77 | const REFERENCE_MANY = 2; |
||
| 78 | const EMBED_ONE = 3; |
||
| 79 | const EMBED_MANY = 4; |
||
| 80 | const MANY = 'many'; |
||
| 81 | const ONE = 'one'; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * The types of storeAs references |
||
| 85 | */ |
||
| 86 | const REFERENCE_STORE_AS_ID = 'id'; |
||
| 87 | const REFERENCE_STORE_AS_DB_REF = 'dbRef'; |
||
| 88 | const REFERENCE_STORE_AS_DB_REF_WITH_DB = 'dbRefWithDb'; |
||
| 89 | const REFERENCE_STORE_AS_REF = 'ref'; |
||
| 90 | |||
| 91 | /* The inheritance mapping types */ |
||
| 92 | /** |
||
| 93 | * NONE means the class does not participate in an inheritance hierarchy |
||
| 94 | * and therefore does not need an inheritance mapping type. |
||
| 95 | */ |
||
| 96 | const INHERITANCE_TYPE_NONE = 1; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * SINGLE_COLLECTION means the class will be persisted according to the rules of |
||
| 100 | * <tt>Single Collection Inheritance</tt>. |
||
| 101 | */ |
||
| 102 | const INHERITANCE_TYPE_SINGLE_COLLECTION = 2; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * COLLECTION_PER_CLASS means the class will be persisted according to the rules |
||
| 106 | * of <tt>Concrete Collection Inheritance</tt>. |
||
| 107 | */ |
||
| 108 | const INHERITANCE_TYPE_COLLECTION_PER_CLASS = 3; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time |
||
| 112 | * by doing a property-by-property comparison with the original data. This will |
||
| 113 | * be done for all entities that are in MANAGED state at commit-time. |
||
| 114 | * |
||
| 115 | * This is the default change tracking policy. |
||
| 116 | */ |
||
| 117 | const CHANGETRACKING_DEFERRED_IMPLICIT = 1; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time |
||
| 121 | * by doing a property-by-property comparison with the original data. This will |
||
| 122 | * be done only for entities that were explicitly saved (through persist() or a cascade). |
||
| 123 | */ |
||
| 124 | const CHANGETRACKING_DEFERRED_EXPLICIT = 2; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * NOTIFY means that Doctrine relies on the entities sending out notifications |
||
| 128 | * when their properties change. Such entity classes must implement |
||
| 129 | * the <tt>NotifyPropertyChanged</tt> interface. |
||
| 130 | */ |
||
| 131 | const CHANGETRACKING_NOTIFY = 3; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * SET means that fields will be written to the database using a $set operator |
||
| 135 | */ |
||
| 136 | const STORAGE_STRATEGY_SET = 'set'; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * INCREMENT means that fields will be written to the database by calculating |
||
| 140 | * the difference and using the $inc operator |
||
| 141 | */ |
||
| 142 | const STORAGE_STRATEGY_INCREMENT = 'increment'; |
||
| 143 | |||
| 144 | const STORAGE_STRATEGY_PUSH_ALL = 'pushAll'; |
||
| 145 | const STORAGE_STRATEGY_ADD_TO_SET = 'addToSet'; |
||
| 146 | const STORAGE_STRATEGY_ATOMIC_SET = 'atomicSet'; |
||
| 147 | const STORAGE_STRATEGY_ATOMIC_SET_ARRAY = 'atomicSetArray'; |
||
| 148 | const STORAGE_STRATEGY_SET_ARRAY = 'setArray'; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * READ-ONLY: The name of the mongo database the document is mapped to. |
||
| 152 | */ |
||
| 153 | public $db; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * READ-ONLY: The name of the mongo collection the document is mapped to. |
||
| 157 | */ |
||
| 158 | public $collection; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * READ-ONLY: If the collection should be a fixed size. |
||
| 162 | */ |
||
| 163 | public $collectionCapped; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * READ-ONLY: If the collection is fixed size, its size in bytes. |
||
| 167 | */ |
||
| 168 | public $collectionSize; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * READ-ONLY: If the collection is fixed size, the maximum number of elements to store in the collection. |
||
| 172 | */ |
||
| 173 | public $collectionMax; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set. |
||
| 177 | */ |
||
| 178 | public $readPreference; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * READ-ONLY Associated with readPreference Allows to specify criteria so that your application can target read |
||
| 182 | * operations to specific members, based on custom parameters. |
||
| 183 | */ |
||
| 184 | public $readPreferenceTags; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * READ-ONLY: Describes the level of acknowledgement requested from MongoDB for write operations. |
||
| 188 | */ |
||
| 189 | public $writeConcern; |
||
| 190 | |||
| 191 | /** |
||
| 192 | * READ-ONLY: The field name of the document identifier. |
||
| 193 | */ |
||
| 194 | public $identifier; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * READ-ONLY: The array of indexes for the document collection. |
||
| 198 | */ |
||
| 199 | public $indexes = array(); |
||
| 200 | |||
| 201 | /** |
||
| 202 | * READ-ONLY: Keys and options describing shard key. Only for sharded collections. |
||
| 203 | */ |
||
| 204 | public $shardKey; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * READ-ONLY: The name of the document class. |
||
| 208 | */ |
||
| 209 | public $name; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * READ-ONLY: The namespace the document class is contained in. |
||
| 213 | * |
||
| 214 | * @var string |
||
| 215 | * @todo Not really needed. Usage could be localized. |
||
| 216 | */ |
||
| 217 | public $namespace; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * READ-ONLY: The name of the document class that is at the root of the mapped document inheritance |
||
| 221 | * hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same |
||
| 222 | * as {@link $documentName}. |
||
| 223 | * |
||
| 224 | * @var string |
||
| 225 | */ |
||
| 226 | public $rootDocumentName; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * The name of the custom repository class used for the document class. |
||
| 230 | * (Optional). |
||
| 231 | * |
||
| 232 | * @var string |
||
| 233 | */ |
||
| 234 | public $customRepositoryClassName; |
||
| 235 | |||
| 236 | /** |
||
| 237 | * READ-ONLY: The names of the parent classes (ancestors). |
||
| 238 | * |
||
| 239 | * @var array |
||
| 240 | */ |
||
| 241 | public $parentClasses = array(); |
||
| 242 | |||
| 243 | /** |
||
| 244 | * READ-ONLY: The names of all subclasses (descendants). |
||
| 245 | * |
||
| 246 | * @var array |
||
| 247 | */ |
||
| 248 | public $subClasses = array(); |
||
| 249 | |||
| 250 | /** |
||
| 251 | * The ReflectionProperty instances of the mapped class. |
||
| 252 | * |
||
| 253 | * @var \ReflectionProperty[] |
||
| 254 | */ |
||
| 255 | public $reflFields = array(); |
||
| 256 | |||
| 257 | /** |
||
| 258 | * READ-ONLY: The inheritance mapping type used by the class. |
||
| 259 | * |
||
| 260 | * @var integer |
||
| 261 | */ |
||
| 262 | public $inheritanceType = self::INHERITANCE_TYPE_NONE; |
||
| 263 | |||
| 264 | /** |
||
| 265 | * READ-ONLY: The Id generator type used by the class. |
||
| 266 | * |
||
| 267 | * @var string |
||
| 268 | */ |
||
| 269 | public $generatorType = self::GENERATOR_TYPE_AUTO; |
||
| 270 | |||
| 271 | /** |
||
| 272 | * READ-ONLY: The Id generator options. |
||
| 273 | * |
||
| 274 | * @var array |
||
| 275 | */ |
||
| 276 | public $generatorOptions = array(); |
||
| 277 | |||
| 278 | /** |
||
| 279 | * READ-ONLY: The ID generator used for generating IDs for this class. |
||
| 280 | * |
||
| 281 | * @var \Doctrine\ODM\MongoDB\Id\AbstractIdGenerator |
||
| 282 | */ |
||
| 283 | public $idGenerator; |
||
| 284 | |||
| 285 | /** |
||
| 286 | * READ-ONLY: The field mappings of the class. |
||
| 287 | * Keys are field names and values are mapping definitions. |
||
| 288 | * |
||
| 289 | * The mapping definition array has the following values: |
||
| 290 | * |
||
| 291 | * - <b>fieldName</b> (string) |
||
| 292 | * The name of the field in the Document. |
||
| 293 | * |
||
| 294 | * - <b>id</b> (boolean, optional) |
||
| 295 | * Marks the field as the primary key of the document. Multiple fields of an |
||
| 296 | * document can have the id attribute, forming a composite key. |
||
| 297 | * |
||
| 298 | * @var array |
||
| 299 | */ |
||
| 300 | public $fieldMappings = array(); |
||
| 301 | |||
| 302 | /** |
||
| 303 | * READ-ONLY: The association mappings of the class. |
||
| 304 | * Keys are field names and values are mapping definitions. |
||
| 305 | * |
||
| 306 | * @var array |
||
| 307 | */ |
||
| 308 | public $associationMappings = array(); |
||
| 309 | |||
| 310 | /** |
||
| 311 | * READ-ONLY: Array of fields to also load with a given method. |
||
| 312 | * |
||
| 313 | * @var array |
||
| 314 | */ |
||
| 315 | public $alsoLoadMethods = array(); |
||
| 316 | |||
| 317 | /** |
||
| 318 | * READ-ONLY: The registered lifecycle callbacks for documents of this class. |
||
| 319 | * |
||
| 320 | * @var array |
||
| 321 | */ |
||
| 322 | public $lifecycleCallbacks = array(); |
||
| 323 | |||
| 324 | /** |
||
| 325 | * READ-ONLY: The discriminator value of this class. |
||
| 326 | * |
||
| 327 | * <b>This does only apply to the JOINED and SINGLE_COLLECTION inheritance mapping strategies |
||
| 328 | * where a discriminator field is used.</b> |
||
| 329 | * |
||
| 330 | * @var mixed |
||
| 331 | * @see discriminatorField |
||
| 332 | */ |
||
| 333 | public $discriminatorValue; |
||
| 334 | |||
| 335 | /** |
||
| 336 | * READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
||
| 337 | * |
||
| 338 | * <b>This does only apply to the SINGLE_COLLECTION inheritance mapping strategy |
||
| 339 | * where a discriminator field is used.</b> |
||
| 340 | * |
||
| 341 | * @var mixed |
||
| 342 | * @see discriminatorField |
||
| 343 | */ |
||
| 344 | public $discriminatorMap = array(); |
||
| 345 | |||
| 346 | /** |
||
| 347 | * READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION |
||
| 348 | * inheritance mapping. |
||
| 349 | * |
||
| 350 | * @var string |
||
| 351 | */ |
||
| 352 | public $discriminatorField; |
||
| 353 | |||
| 354 | /** |
||
| 355 | * READ-ONLY: The default value for discriminatorField in case it's not set in the document |
||
| 356 | * |
||
| 357 | * @var string |
||
| 358 | * @see discriminatorField |
||
| 359 | */ |
||
| 360 | public $defaultDiscriminatorValue; |
||
| 361 | |||
| 362 | /** |
||
| 363 | * READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
||
| 364 | * |
||
| 365 | * @var boolean |
||
| 366 | */ |
||
| 367 | public $isMappedSuperclass = false; |
||
| 368 | |||
| 369 | /** |
||
| 370 | * READ-ONLY: Whether this class describes the mapping of a embedded document. |
||
| 371 | * |
||
| 372 | * @var boolean |
||
| 373 | */ |
||
| 374 | public $isEmbeddedDocument = false; |
||
| 375 | |||
| 376 | /** |
||
| 377 | * READ-ONLY: Whether this class describes the mapping of an aggregation result document. |
||
| 378 | * |
||
| 379 | * @var boolean |
||
| 380 | */ |
||
| 381 | public $isQueryResultDocument = false; |
||
| 382 | |||
| 383 | /** |
||
| 384 | * READ-ONLY: The policy used for change-tracking on entities of this class. |
||
| 385 | * |
||
| 386 | * @var integer |
||
| 387 | */ |
||
| 388 | public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT; |
||
| 389 | |||
| 390 | /** |
||
| 391 | * READ-ONLY: A flag for whether or not instances of this class are to be versioned |
||
| 392 | * with optimistic locking. |
||
| 393 | * |
||
| 394 | * @var boolean $isVersioned |
||
| 395 | */ |
||
| 396 | public $isVersioned; |
||
| 397 | |||
| 398 | /** |
||
| 399 | * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). |
||
| 400 | * |
||
| 401 | * @var mixed $versionField |
||
| 402 | */ |
||
| 403 | public $versionField; |
||
| 404 | |||
| 405 | /** |
||
| 406 | * READ-ONLY: A flag for whether or not instances of this class are to allow pessimistic |
||
| 407 | * locking. |
||
| 408 | * |
||
| 409 | * @var boolean $isLockable |
||
| 410 | */ |
||
| 411 | public $isLockable; |
||
| 412 | |||
| 413 | /** |
||
| 414 | * READ-ONLY: The name of the field which is used for locking a document. |
||
| 415 | * |
||
| 416 | * @var mixed $lockField |
||
| 417 | */ |
||
| 418 | public $lockField; |
||
| 419 | |||
| 420 | /** |
||
| 421 | * The ReflectionClass instance of the mapped class. |
||
| 422 | * |
||
| 423 | * @var \ReflectionClass |
||
| 424 | */ |
||
| 425 | public $reflClass; |
||
| 426 | |||
| 427 | /** |
||
| 428 | * READ_ONLY: A flag for whether or not this document is read-only. |
||
| 429 | * |
||
| 430 | * @var bool |
||
| 431 | */ |
||
| 432 | public $isReadOnly; |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Initializes a new ClassMetadata instance that will hold the object-document mapping |
||
| 436 | * metadata of the class with the given name. |
||
| 437 | * |
||
| 438 | * @param string $documentName The name of the document class the new instance is used for. |
||
| 439 | */ |
||
| 440 | 1474 | public function __construct($documentName) |
|
| 445 | |||
| 446 | /** |
||
| 447 | * Helper method to get reference id of ref* type references |
||
| 448 | * @param mixed $reference |
||
| 449 | * @param string $storeAs |
||
| 450 | * @return mixed |
||
| 451 | * @internal |
||
| 452 | */ |
||
| 453 | 120 | public static function getReferenceId($reference, $storeAs) |
|
| 457 | |||
| 458 | /** |
||
| 459 | * Returns the reference prefix used for a reference |
||
| 460 | * @param string $storeAs |
||
| 461 | * @return string |
||
| 462 | */ |
||
| 463 | 185 | private static function getReferencePrefix($storeAs) |
|
| 471 | |||
| 472 | /** |
||
| 473 | * Returns a fully qualified field name for a given reference |
||
| 474 | * @param string $storeAs |
||
| 475 | * @param string $pathPrefix The field path prefix |
||
| 476 | * @return string |
||
| 477 | * @internal |
||
| 478 | */ |
||
| 479 | 134 | public static function getReferenceFieldName($storeAs, $pathPrefix = '') |
|
| 487 | |||
| 488 | /** |
||
| 489 | * {@inheritDoc} |
||
| 490 | */ |
||
| 491 | 1365 | public function getReflectionClass() |
|
| 499 | |||
| 500 | /** |
||
| 501 | * {@inheritDoc} |
||
| 502 | */ |
||
| 503 | 321 | public function isIdentifier($fieldName) |
|
| 507 | |||
| 508 | /** |
||
| 509 | * INTERNAL: |
||
| 510 | * Sets the mapped identifier field of this class. |
||
| 511 | * |
||
| 512 | * @param string $identifier |
||
| 513 | */ |
||
| 514 | 886 | public function setIdentifier($identifier) |
|
| 518 | |||
| 519 | /** |
||
| 520 | * {@inheritDoc} |
||
| 521 | * |
||
| 522 | * Since MongoDB only allows exactly one identifier field |
||
| 523 | * this will always return an array with only one value |
||
| 524 | */ |
||
| 525 | 38 | public function getIdentifier() |
|
| 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 | 97 | public function getIdentifierFieldNames() |
|
| 540 | |||
| 541 | /** |
||
| 542 | * {@inheritDoc} |
||
| 543 | */ |
||
| 544 | 886 | public function hasField($fieldName) |
|
| 548 | |||
| 549 | /** |
||
| 550 | * Sets the inheritance type used by the class and it's subclasses. |
||
| 551 | * |
||
| 552 | * @param integer $type |
||
| 553 | */ |
||
| 554 | 902 | public function setInheritanceType($type) |
|
| 558 | |||
| 559 | /** |
||
| 560 | * Checks whether a mapped field is inherited from an entity superclass. |
||
| 561 | * |
||
| 562 | * @param string $fieldName |
||
| 563 | * |
||
| 564 | * @return boolean TRUE if the field is inherited, FALSE otherwise. |
||
| 565 | */ |
||
| 566 | 1361 | public function isInheritedField($fieldName) |
|
| 570 | |||
| 571 | /** |
||
| 572 | * Registers a custom repository class for the document class. |
||
| 573 | * |
||
| 574 | * @param string $repositoryClassName The class name of the custom repository. |
||
| 575 | */ |
||
| 576 | 834 | public function setCustomRepositoryClass($repositoryClassName) |
|
| 588 | |||
| 589 | /** |
||
| 590 | * Dispatches the lifecycle event of the given document by invoking all |
||
| 591 | * registered callbacks. |
||
| 592 | * |
||
| 593 | * @param string $event Lifecycle event |
||
| 594 | * @param object $document Document on which the event occurred |
||
| 595 | * @param array $arguments Arguments to pass to all callbacks |
||
| 596 | * @throws \InvalidArgumentException if document class is not this class or |
||
| 597 | * a Proxy of this class |
||
| 598 | */ |
||
| 599 | 599 | public function invokeLifecycleCallbacks($event, $document, array $arguments = null) |
|
| 617 | |||
| 618 | /** |
||
| 619 | * Checks whether the class has callbacks registered for a lifecycle event. |
||
| 620 | * |
||
| 621 | * @param string $event Lifecycle event |
||
| 622 | * |
||
| 623 | * @return boolean |
||
| 624 | */ |
||
| 625 | public function hasLifecycleCallbacks($event) |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Gets the registered lifecycle callbacks for an event. |
||
| 632 | * |
||
| 633 | * @param string $event |
||
| 634 | * @return array |
||
| 635 | */ |
||
| 636 | public function getLifecycleCallbacks($event) |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Adds a lifecycle callback for documents of this class. |
||
| 643 | * |
||
| 644 | * If the callback is already registered, this is a NOOP. |
||
| 645 | * |
||
| 646 | * @param string $callback |
||
| 647 | * @param string $event |
||
| 648 | */ |
||
| 649 | 802 | public function addLifecycleCallback($callback, $event) |
|
| 657 | |||
| 658 | /** |
||
| 659 | * Sets the lifecycle callbacks for documents of this class. |
||
| 660 | * |
||
| 661 | * Any previously registered callbacks are overwritten. |
||
| 662 | * |
||
| 663 | * @param array $callbacks |
||
| 664 | */ |
||
| 665 | 885 | public function setLifecycleCallbacks(array $callbacks) |
|
| 669 | |||
| 670 | /** |
||
| 671 | * Registers a method for loading document data before field hydration. |
||
| 672 | * |
||
| 673 | * Note: A method may be registered multiple times for different fields. |
||
| 674 | * it will be invoked only once for the first field found. |
||
| 675 | * |
||
| 676 | * @param string $method Method name |
||
| 677 | * @param array|string $fields Database field name(s) |
||
| 678 | */ |
||
| 679 | 14 | public function registerAlsoLoadMethod($method, $fields) |
|
| 683 | |||
| 684 | /** |
||
| 685 | * Sets the AlsoLoad methods for documents of this class. |
||
| 686 | * |
||
| 687 | * Any previously registered methods are overwritten. |
||
| 688 | * |
||
| 689 | * @param array $methods |
||
| 690 | */ |
||
| 691 | 885 | public function setAlsoLoadMethods(array $methods) |
|
| 695 | |||
| 696 | /** |
||
| 697 | * Sets the discriminator field. |
||
| 698 | * |
||
| 699 | * The field name is the the unmapped database field. Discriminator values |
||
| 700 | * are only used to discern the hydration class and are not mapped to class |
||
| 701 | * properties. |
||
| 702 | * |
||
| 703 | * @param string $discriminatorField |
||
| 704 | * |
||
| 705 | * @throws MappingException If the discriminator field conflicts with the |
||
| 706 | * "name" attribute of a mapped field. |
||
| 707 | */ |
||
| 708 | 911 | public function setDiscriminatorField($discriminatorField) |
|
| 733 | |||
| 734 | /** |
||
| 735 | * Sets the discriminator values used by this class. |
||
| 736 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
||
| 737 | * |
||
| 738 | * @param array $map |
||
| 739 | * |
||
| 740 | * @throws MappingException |
||
| 741 | */ |
||
| 742 | 904 | public function setDiscriminatorMap(array $map) |
|
| 761 | |||
| 762 | /** |
||
| 763 | * Sets the default discriminator value to be used for this class |
||
| 764 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value |
||
| 765 | * |
||
| 766 | * @param string $defaultDiscriminatorValue |
||
| 767 | * |
||
| 768 | * @throws MappingException |
||
| 769 | */ |
||
| 770 | 888 | public function setDefaultDiscriminatorValue($defaultDiscriminatorValue) |
|
| 784 | |||
| 785 | /** |
||
| 786 | * Sets the discriminator value for this class. |
||
| 787 | * Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single |
||
| 788 | * collection. |
||
| 789 | * |
||
| 790 | * @param string $value |
||
| 791 | */ |
||
| 792 | 3 | public function setDiscriminatorValue($value) |
|
| 797 | |||
| 798 | /** |
||
| 799 | * Add a index for this Document. |
||
| 800 | * |
||
| 801 | * @param array $keys Array of keys for the index. |
||
| 802 | * @param array $options Array of options for the index. |
||
| 803 | */ |
||
| 804 | 183 | public function addIndex($keys, array $options = array()) |
|
| 805 | { |
||
| 806 | 183 | $this->indexes[] = array( |
|
| 807 | 183 | View Code Duplication | 'keys' => array_map(function($value) { |
| 808 | 183 | if ($value == 1 || $value == -1) { |
|
| 809 | 54 | return (int) $value; |
|
| 810 | } |
||
| 811 | 176 | if (is_string($value)) { |
|
| 812 | 176 | $lower = strtolower($value); |
|
| 813 | 176 | if ($lower === 'asc') { |
|
| 814 | 176 | return 1; |
|
| 815 | } elseif ($lower === 'desc') { |
||
| 816 | return -1; |
||
| 817 | } |
||
| 818 | } |
||
| 819 | return $value; |
||
| 820 | 183 | }, $keys), |
|
| 821 | 183 | 'options' => $options |
|
| 822 | ); |
||
| 823 | 183 | } |
|
| 824 | |||
| 825 | /** |
||
| 826 | * Returns the array of indexes for this Document. |
||
| 827 | * |
||
| 828 | * @return array $indexes The array of indexes. |
||
| 829 | */ |
||
| 830 | 23 | public function getIndexes() |
|
| 834 | |||
| 835 | /** |
||
| 836 | * Checks whether this document has indexes or not. |
||
| 837 | * |
||
| 838 | * @return boolean |
||
| 839 | */ |
||
| 840 | public function hasIndexes() |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Set shard key for this Document. |
||
| 847 | * |
||
| 848 | * @param array $keys Array of document keys. |
||
| 849 | * @param array $options Array of sharding options. |
||
| 850 | * |
||
| 851 | * @throws MappingException |
||
| 852 | */ |
||
| 853 | 71 | public function setShardKey(array $keys, array $options = array()) |
|
| 895 | |||
| 896 | /** |
||
| 897 | * @return array |
||
| 898 | */ |
||
| 899 | 17 | public function getShardKey() |
|
| 903 | |||
| 904 | /** |
||
| 905 | * Checks whether this document has shard key or not. |
||
| 906 | * |
||
| 907 | * @return bool |
||
| 908 | */ |
||
| 909 | 1096 | public function isSharded() |
|
| 913 | |||
| 914 | /** |
||
| 915 | * Sets the read preference used by this class. |
||
| 916 | * |
||
| 917 | * @param string $readPreference |
||
| 918 | * @param array|null $tags |
||
| 919 | */ |
||
| 920 | 885 | public function setReadPreference($readPreference, $tags) |
|
| 925 | |||
| 926 | /** |
||
| 927 | * Sets the write concern used by this class. |
||
| 928 | * |
||
| 929 | * @param string $writeConcern |
||
| 930 | */ |
||
| 931 | 895 | public function setWriteConcern($writeConcern) |
|
| 935 | |||
| 936 | /** |
||
| 937 | * @return string |
||
| 938 | */ |
||
| 939 | 11 | public function getWriteConcern() |
|
| 943 | |||
| 944 | /** |
||
| 945 | * Whether there is a write concern configured for this class. |
||
| 946 | * |
||
| 947 | * @return bool |
||
| 948 | */ |
||
| 949 | 548 | public function hasWriteConcern() |
|
| 953 | |||
| 954 | /** |
||
| 955 | * Sets the change tracking policy used by this class. |
||
| 956 | * |
||
| 957 | * @param integer $policy |
||
| 958 | */ |
||
| 959 | 887 | public function setChangeTrackingPolicy($policy) |
|
| 963 | |||
| 964 | /** |
||
| 965 | * Whether the change tracking policy of this class is "deferred explicit". |
||
| 966 | * |
||
| 967 | * @return boolean |
||
| 968 | */ |
||
| 969 | 61 | public function isChangeTrackingDeferredExplicit() |
|
| 973 | |||
| 974 | /** |
||
| 975 | * Whether the change tracking policy of this class is "deferred implicit". |
||
| 976 | * |
||
| 977 | * @return boolean |
||
| 978 | */ |
||
| 979 | 568 | public function isChangeTrackingDeferredImplicit() |
|
| 983 | |||
| 984 | /** |
||
| 985 | * Whether the change tracking policy of this class is "notify". |
||
| 986 | * |
||
| 987 | * @return boolean |
||
| 988 | */ |
||
| 989 | 308 | public function isChangeTrackingNotify() |
|
| 993 | |||
| 994 | /** |
||
| 995 | * Gets the ReflectionProperties of the mapped class. |
||
| 996 | * |
||
| 997 | * @return array An array of ReflectionProperty instances. |
||
| 998 | */ |
||
| 999 | 97 | public function getReflectionProperties() |
|
| 1003 | |||
| 1004 | /** |
||
| 1005 | * Gets a ReflectionProperty for a specific field of the mapped class. |
||
| 1006 | * |
||
| 1007 | * @param string $name |
||
| 1008 | * |
||
| 1009 | * @return \ReflectionProperty |
||
| 1010 | */ |
||
| 1011 | public function getReflectionProperty($name) |
||
| 1015 | |||
| 1016 | /** |
||
| 1017 | * {@inheritDoc} |
||
| 1018 | */ |
||
| 1019 | 1370 | public function getName() |
|
| 1023 | |||
| 1024 | /** |
||
| 1025 | * The namespace this Document class belongs to. |
||
| 1026 | * |
||
| 1027 | * @return string $namespace The namespace name. |
||
| 1028 | */ |
||
| 1029 | public function getNamespace() |
||
| 1033 | |||
| 1034 | /** |
||
| 1035 | * Returns the database this Document is mapped to. |
||
| 1036 | * |
||
| 1037 | * @return string $db The database name. |
||
| 1038 | */ |
||
| 1039 | 1294 | public function getDatabase() |
|
| 1043 | |||
| 1044 | /** |
||
| 1045 | * Set the database this Document is mapped to. |
||
| 1046 | * |
||
| 1047 | * @param string $db The database name |
||
| 1048 | */ |
||
| 1049 | 92 | public function setDatabase($db) |
|
| 1053 | |||
| 1054 | /** |
||
| 1055 | * Get the collection this Document is mapped to. |
||
| 1056 | * |
||
| 1057 | * @return string $collection The collection name. |
||
| 1058 | */ |
||
| 1059 | 1295 | public function getCollection() |
|
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Sets the collection this Document is mapped to. |
||
| 1066 | * |
||
| 1067 | * @param array|string $name |
||
| 1068 | * |
||
| 1069 | * @throws \InvalidArgumentException |
||
| 1070 | */ |
||
| 1071 | 1444 | public function setCollection($name) |
|
| 1085 | |||
| 1086 | /** |
||
| 1087 | * Get whether or not the documents collection is capped. |
||
| 1088 | * |
||
| 1089 | * @return boolean |
||
| 1090 | */ |
||
| 1091 | 4 | public function getCollectionCapped() |
|
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Set whether or not the documents collection is capped. |
||
| 1098 | * |
||
| 1099 | * @param boolean $bool |
||
| 1100 | */ |
||
| 1101 | 1 | public function setCollectionCapped($bool) |
|
| 1105 | |||
| 1106 | /** |
||
| 1107 | * Get the collection size |
||
| 1108 | * |
||
| 1109 | * @return integer |
||
| 1110 | */ |
||
| 1111 | 4 | public function getCollectionSize() |
|
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Set the collection size. |
||
| 1118 | * |
||
| 1119 | * @param integer $size |
||
| 1120 | */ |
||
| 1121 | 1 | public function setCollectionSize($size) |
|
| 1125 | |||
| 1126 | /** |
||
| 1127 | * Get the collection max. |
||
| 1128 | * |
||
| 1129 | * @return integer |
||
| 1130 | */ |
||
| 1131 | 4 | public function getCollectionMax() |
|
| 1135 | |||
| 1136 | /** |
||
| 1137 | * Set the collection max. |
||
| 1138 | * |
||
| 1139 | * @param integer $max |
||
| 1140 | */ |
||
| 1141 | 1 | public function setCollectionMax($max) |
|
| 1145 | |||
| 1146 | /** |
||
| 1147 | * Returns TRUE if this Document is mapped to a collection FALSE otherwise. |
||
| 1148 | * |
||
| 1149 | * @return boolean |
||
| 1150 | */ |
||
| 1151 | public function isMappedToCollection() |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Map a field. |
||
| 1158 | * |
||
| 1159 | * @param array $mapping The mapping information. |
||
| 1160 | * |
||
| 1161 | * @return array |
||
| 1162 | * |
||
| 1163 | * @throws MappingException |
||
| 1164 | */ |
||
| 1165 | 1399 | public function mapField(array $mapping) |
|
| 1336 | |||
| 1337 | /** |
||
| 1338 | * Validates the storage strategy of a mapping for consistency |
||
| 1339 | * @param array $mapping |
||
| 1340 | * @throws \Doctrine\ODM\MongoDB\Mapping\MappingException |
||
| 1341 | */ |
||
| 1342 | 1387 | private function applyStorageStrategy(array &$mapping) |
|
| 1385 | |||
| 1386 | /** |
||
| 1387 | * Map a single embedded document. |
||
| 1388 | * |
||
| 1389 | * @param array $mapping The mapping information. |
||
| 1390 | */ |
||
| 1391 | 6 | public function mapOneEmbedded(array $mapping) |
|
| 1397 | |||
| 1398 | /** |
||
| 1399 | * Map a collection of embedded documents. |
||
| 1400 | * |
||
| 1401 | * @param array $mapping The mapping information. |
||
| 1402 | */ |
||
| 1403 | 5 | public function mapManyEmbedded(array $mapping) |
|
| 1409 | |||
| 1410 | /** |
||
| 1411 | * Map a single document reference. |
||
| 1412 | * |
||
| 1413 | * @param array $mapping The mapping information. |
||
| 1414 | */ |
||
| 1415 | 2 | public function mapOneReference(array $mapping) |
|
| 1421 | |||
| 1422 | /** |
||
| 1423 | * Map a collection of document references. |
||
| 1424 | * |
||
| 1425 | * @param array $mapping The mapping information. |
||
| 1426 | */ |
||
| 1427 | 2 | public function mapManyReference(array $mapping) |
|
| 1433 | |||
| 1434 | /** |
||
| 1435 | * INTERNAL: |
||
| 1436 | * Adds a field mapping without completing/validating it. |
||
| 1437 | * This is mainly used to add inherited field mappings to derived classes. |
||
| 1438 | * |
||
| 1439 | * @param array $fieldMapping |
||
| 1440 | */ |
||
| 1441 | 116 | public function addInheritedFieldMapping(array $fieldMapping) |
|
| 1449 | |||
| 1450 | /** |
||
| 1451 | * INTERNAL: |
||
| 1452 | * Adds an association mapping without completing/validating it. |
||
| 1453 | * This is mainly used to add inherited association mappings to derived classes. |
||
| 1454 | * |
||
| 1455 | * @param array $mapping |
||
| 1456 | * |
||
| 1457 | * @return void |
||
| 1458 | * |
||
| 1459 | * @throws MappingException |
||
| 1460 | */ |
||
| 1461 | 68 | public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/) |
|
| 1465 | |||
| 1466 | /** |
||
| 1467 | * Checks whether the class has a mapped association with the given field name. |
||
| 1468 | * |
||
| 1469 | * @param string $fieldName |
||
| 1470 | * @return boolean |
||
| 1471 | */ |
||
| 1472 | 32 | public function hasReference($fieldName) |
|
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Checks whether the class has a mapped embed with the given field name. |
||
| 1479 | * |
||
| 1480 | * @param string $fieldName |
||
| 1481 | * @return boolean |
||
| 1482 | */ |
||
| 1483 | 5 | public function hasEmbed($fieldName) |
|
| 1487 | |||
| 1488 | /** |
||
| 1489 | * {@inheritDoc} |
||
| 1490 | * |
||
| 1491 | * Checks whether the class has a mapped association (embed or reference) with the given field name. |
||
| 1492 | */ |
||
| 1493 | 7 | public function hasAssociation($fieldName) |
|
| 1497 | |||
| 1498 | /** |
||
| 1499 | * {@inheritDoc} |
||
| 1500 | * |
||
| 1501 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1502 | * is a single valued association. |
||
| 1503 | */ |
||
| 1504 | public function isSingleValuedAssociation($fieldName) |
||
| 1508 | |||
| 1509 | /** |
||
| 1510 | * {@inheritDoc} |
||
| 1511 | * |
||
| 1512 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1513 | * is a collection valued association. |
||
| 1514 | */ |
||
| 1515 | public function isCollectionValuedAssociation($fieldName) |
||
| 1519 | |||
| 1520 | /** |
||
| 1521 | * Checks whether the class has a mapped association for the specified field |
||
| 1522 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1523 | * |
||
| 1524 | * @param string $fieldName |
||
| 1525 | * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1526 | */ |
||
| 1527 | public function isSingleValuedReference($fieldName) |
||
| 1532 | |||
| 1533 | /** |
||
| 1534 | * Checks whether the class has a mapped association for the specified field |
||
| 1535 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1536 | * |
||
| 1537 | * @param string $fieldName |
||
| 1538 | * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. |
||
| 1539 | */ |
||
| 1540 | public function isCollectionValuedReference($fieldName) |
||
| 1545 | |||
| 1546 | /** |
||
| 1547 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1548 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1549 | * |
||
| 1550 | * @param string $fieldName |
||
| 1551 | * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1552 | */ |
||
| 1553 | public function isSingleValuedEmbed($fieldName) |
||
| 1558 | |||
| 1559 | /** |
||
| 1560 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1561 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1562 | * |
||
| 1563 | * @param string $fieldName |
||
| 1564 | * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. |
||
| 1565 | */ |
||
| 1566 | public function isCollectionValuedEmbed($fieldName) |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Sets the ID generator used to generate IDs for instances of this class. |
||
| 1574 | * |
||
| 1575 | * @param \Doctrine\ODM\MongoDB\Id\AbstractIdGenerator $generator |
||
| 1576 | */ |
||
| 1577 | 1305 | public function setIdGenerator($generator) |
|
| 1581 | |||
| 1582 | /** |
||
| 1583 | * Casts the identifier to its portable PHP type. |
||
| 1584 | * |
||
| 1585 | * @param mixed $id |
||
| 1586 | * @return mixed $id |
||
| 1587 | */ |
||
| 1588 | 590 | public function getPHPIdentifierValue($id) |
|
| 1593 | |||
| 1594 | /** |
||
| 1595 | * Casts the identifier to its database type. |
||
| 1596 | * |
||
| 1597 | * @param mixed $id |
||
| 1598 | * @return mixed $id |
||
| 1599 | */ |
||
| 1600 | 655 | public function getDatabaseIdentifierValue($id) |
|
| 1605 | |||
| 1606 | /** |
||
| 1607 | * Sets the document identifier of a document. |
||
| 1608 | * |
||
| 1609 | * The value will be converted to a PHP type before being set. |
||
| 1610 | * |
||
| 1611 | * @param object $document |
||
| 1612 | * @param mixed $id |
||
| 1613 | */ |
||
| 1614 | 519 | public function setIdentifierValue($document, $id) |
|
| 1619 | |||
| 1620 | /** |
||
| 1621 | * Gets the document identifier as a PHP type. |
||
| 1622 | * |
||
| 1623 | * @param object $document |
||
| 1624 | * @return mixed $id |
||
| 1625 | */ |
||
| 1626 | 603 | public function getIdentifierValue($document) |
|
| 1630 | |||
| 1631 | /** |
||
| 1632 | * {@inheritDoc} |
||
| 1633 | * |
||
| 1634 | * Since MongoDB only allows exactly one identifier field this is a proxy |
||
| 1635 | * to {@see getIdentifierValue()} and returns an array with the identifier |
||
| 1636 | * field as a key. |
||
| 1637 | */ |
||
| 1638 | public function getIdentifierValues($object) |
||
| 1642 | |||
| 1643 | /** |
||
| 1644 | * Get the document identifier object as a database type. |
||
| 1645 | * |
||
| 1646 | * @param object $document |
||
| 1647 | * |
||
| 1648 | * @return \MongoDB\BSON\ObjectId $id The ObjectId |
||
| 1649 | */ |
||
| 1650 | 31 | public function getIdentifierObject($document) |
|
| 1654 | |||
| 1655 | /** |
||
| 1656 | * Sets the specified field to the specified value on the given document. |
||
| 1657 | * |
||
| 1658 | * @param object $document |
||
| 1659 | * @param string $field |
||
| 1660 | * @param mixed $value |
||
| 1661 | */ |
||
| 1662 | 8 | public function setFieldValue($document, $field, $value) |
|
| 1672 | |||
| 1673 | /** |
||
| 1674 | * Gets the specified field's value off the given document. |
||
| 1675 | * |
||
| 1676 | * @param object $document |
||
| 1677 | * @param string $field |
||
| 1678 | * |
||
| 1679 | * @return mixed |
||
| 1680 | */ |
||
| 1681 | 27 | public function getFieldValue($document, $field) |
|
| 1689 | |||
| 1690 | /** |
||
| 1691 | * Gets the mapping of a field. |
||
| 1692 | * |
||
| 1693 | * @param string $fieldName The field name. |
||
| 1694 | * |
||
| 1695 | * @return array The field mapping. |
||
| 1696 | * |
||
| 1697 | * @throws MappingException if the $fieldName is not found in the fieldMappings array |
||
| 1698 | */ |
||
| 1699 | 167 | public function getFieldMapping($fieldName) |
|
| 1706 | |||
| 1707 | /** |
||
| 1708 | * Gets mappings of fields holding embedded document(s). |
||
| 1709 | * |
||
| 1710 | * @return array of field mappings |
||
| 1711 | */ |
||
| 1712 | 559 | public function getEmbeddedFieldsMappings() |
|
| 1719 | |||
| 1720 | /** |
||
| 1721 | * Gets the field mapping by its DB name. |
||
| 1722 | * E.g. it returns identifier's mapping when called with _id. |
||
| 1723 | * |
||
| 1724 | * @param string $dbFieldName |
||
| 1725 | * |
||
| 1726 | * @return array |
||
| 1727 | * @throws MappingException |
||
| 1728 | */ |
||
| 1729 | 4 | public function getFieldMappingByDbFieldName($dbFieldName) |
|
| 1739 | |||
| 1740 | /** |
||
| 1741 | * Check if the field is not null. |
||
| 1742 | * |
||
| 1743 | * @param string $fieldName The field name |
||
| 1744 | * |
||
| 1745 | * @return boolean TRUE if the field is not null, FALSE otherwise. |
||
| 1746 | */ |
||
| 1747 | 1 | public function isNullable($fieldName) |
|
| 1755 | |||
| 1756 | /** |
||
| 1757 | * Checks whether the document has a discriminator field and value configured. |
||
| 1758 | * |
||
| 1759 | * @return boolean |
||
| 1760 | */ |
||
| 1761 | 492 | public function hasDiscriminator() |
|
| 1765 | |||
| 1766 | /** |
||
| 1767 | * Sets the type of Id generator to use for the mapped class. |
||
| 1768 | * |
||
| 1769 | * @param string $generatorType Generator type. |
||
| 1770 | */ |
||
| 1771 | 885 | public function setIdGeneratorType($generatorType) |
|
| 1775 | |||
| 1776 | /** |
||
| 1777 | * Sets the Id generator options. |
||
| 1778 | * |
||
| 1779 | * @param array $generatorOptions Generator options. |
||
| 1780 | */ |
||
| 1781 | public function setIdGeneratorOptions($generatorOptions) |
||
| 1785 | |||
| 1786 | /** |
||
| 1787 | * @return boolean |
||
| 1788 | */ |
||
| 1789 | 566 | public function isInheritanceTypeNone() |
|
| 1793 | |||
| 1794 | /** |
||
| 1795 | * Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy. |
||
| 1796 | * |
||
| 1797 | * @return boolean |
||
| 1798 | */ |
||
| 1799 | 884 | public function isInheritanceTypeSingleCollection() |
|
| 1803 | |||
| 1804 | /** |
||
| 1805 | * Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy. |
||
| 1806 | * |
||
| 1807 | * @return boolean |
||
| 1808 | */ |
||
| 1809 | public function isInheritanceTypeCollectionPerClass() |
||
| 1813 | |||
| 1814 | /** |
||
| 1815 | * Sets the mapped subclasses of this class. |
||
| 1816 | * |
||
| 1817 | * @param string[] $subclasses The names of all mapped subclasses. |
||
| 1818 | */ |
||
| 1819 | 2 | public function setSubclasses(array $subclasses) |
|
| 1829 | |||
| 1830 | /** |
||
| 1831 | * Sets the parent class names. |
||
| 1832 | * Assumes that the class names in the passed array are in the order: |
||
| 1833 | * directParent -> directParentParent -> directParentParentParent ... -> root. |
||
| 1834 | * |
||
| 1835 | * @param string[] $classNames |
||
| 1836 | */ |
||
| 1837 | 1361 | public function setParentClasses(array $classNames) |
|
| 1845 | |||
| 1846 | /** |
||
| 1847 | * Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us. |
||
| 1848 | * |
||
| 1849 | * @return boolean TRUE if the class uses the AUTO generator, FALSE otherwise. |
||
| 1850 | */ |
||
| 1851 | public function isIdGeneratorAuto() |
||
| 1855 | |||
| 1856 | /** |
||
| 1857 | * Checks whether the class will use a collection to generate incremented identifiers. |
||
| 1858 | * |
||
| 1859 | * @return boolean TRUE if the class uses the INCREMENT generator, FALSE otherwise. |
||
| 1860 | */ |
||
| 1861 | public function isIdGeneratorIncrement() |
||
| 1865 | |||
| 1866 | /** |
||
| 1867 | * Checks whether the class will generate a uuid id. |
||
| 1868 | * |
||
| 1869 | * @return boolean TRUE if the class uses the UUID generator, FALSE otherwise. |
||
| 1870 | */ |
||
| 1871 | public function isIdGeneratorUuid() |
||
| 1875 | |||
| 1876 | /** |
||
| 1877 | * Checks whether the class uses no id generator. |
||
| 1878 | * |
||
| 1879 | * @return boolean TRUE if the class does not use any id generator, FALSE otherwise. |
||
| 1880 | */ |
||
| 1881 | public function isIdGeneratorNone() |
||
| 1885 | |||
| 1886 | /** |
||
| 1887 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1888 | * value to use depending on the column type. |
||
| 1889 | * |
||
| 1890 | * @param array $mapping The version field mapping array |
||
| 1891 | * |
||
| 1892 | * @throws LockException |
||
| 1893 | */ |
||
| 1894 | 67 | public function setVersionMapping(array &$mapping) |
|
| 1903 | |||
| 1904 | /** |
||
| 1905 | * Sets whether this class is to be versioned for optimistic locking. |
||
| 1906 | * |
||
| 1907 | * @param boolean $bool |
||
| 1908 | */ |
||
| 1909 | 885 | public function setVersioned($bool) |
|
| 1913 | |||
| 1914 | /** |
||
| 1915 | * Sets the name of the field that is to be used for versioning if this class is |
||
| 1916 | * versioned for optimistic locking. |
||
| 1917 | * |
||
| 1918 | * @param string $versionField |
||
| 1919 | */ |
||
| 1920 | 885 | public function setVersionField($versionField) |
|
| 1924 | |||
| 1925 | /** |
||
| 1926 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1927 | * value to use depending on the column type. |
||
| 1928 | * |
||
| 1929 | * @param array $mapping The version field mapping array |
||
| 1930 | * |
||
| 1931 | * @throws \Doctrine\ODM\MongoDB\LockException |
||
| 1932 | */ |
||
| 1933 | 22 | public function setLockMapping(array &$mapping) |
|
| 1942 | |||
| 1943 | /** |
||
| 1944 | * Sets whether this class is to allow pessimistic locking. |
||
| 1945 | * |
||
| 1946 | * @param boolean $bool |
||
| 1947 | */ |
||
| 1948 | public function setLockable($bool) |
||
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Sets the name of the field that is to be used for storing whether a document |
||
| 1955 | * is currently locked or not. |
||
| 1956 | * |
||
| 1957 | * @param string $lockField |
||
| 1958 | */ |
||
| 1959 | public function setLockField($lockField) |
||
| 1963 | |||
| 1964 | /** |
||
| 1965 | * Marks this class as read only, no change tracking is applied to it. |
||
| 1966 | */ |
||
| 1967 | 5 | public function markReadOnly() |
|
| 1971 | |||
| 1972 | /** |
||
| 1973 | * {@inheritDoc} |
||
| 1974 | */ |
||
| 1975 | public function getFieldNames() |
||
| 1979 | |||
| 1980 | /** |
||
| 1981 | * {@inheritDoc} |
||
| 1982 | */ |
||
| 1983 | public function getAssociationNames() |
||
| 1987 | |||
| 1988 | /** |
||
| 1989 | * {@inheritDoc} |
||
| 1990 | */ |
||
| 1991 | 23 | public function getTypeOfField($fieldName) |
|
| 1996 | |||
| 1997 | /** |
||
| 1998 | * {@inheritDoc} |
||
| 1999 | */ |
||
| 2000 | 4 | public function getAssociationTargetClass($assocName) |
|
| 2008 | |||
| 2009 | /** |
||
| 2010 | * Retrieve the collectionClass associated with an association |
||
| 2011 | * |
||
| 2012 | * @param string $assocName |
||
| 2013 | */ |
||
| 2014 | 1 | public function getAssociationCollectionClass($assocName) |
|
| 2026 | |||
| 2027 | /** |
||
| 2028 | * {@inheritDoc} |
||
| 2029 | */ |
||
| 2030 | public function isAssociationInverseSide($fieldName) |
||
| 2034 | |||
| 2035 | /** |
||
| 2036 | * {@inheritDoc} |
||
| 2037 | */ |
||
| 2038 | public function getAssociationMappedByTargetField($fieldName) |
||
| 2042 | } |
||
| 2043 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClassto useselfinstead: