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 |
||
| 44 | class ClassMetadataInfo implements \Doctrine\Common\Persistence\Mapping\ClassMetadata |
||
| 45 | { |
||
| 46 | /* The Id generator types. */ |
||
| 47 | /** |
||
| 48 | * AUTO means Doctrine will automatically create a new \MongoDB\BSON\ObjectId instance for us. |
||
| 49 | */ |
||
| 50 | const GENERATOR_TYPE_AUTO = 1; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * INCREMENT means a separate collection is used for maintaining and incrementing id generation. |
||
| 54 | * Offers full portability. |
||
| 55 | */ |
||
| 56 | const GENERATOR_TYPE_INCREMENT = 2; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * UUID means Doctrine will generate a uuid for us. |
||
| 60 | */ |
||
| 61 | const GENERATOR_TYPE_UUID = 3; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * ALNUM means Doctrine will generate Alpha-numeric string identifiers, using the INCREMENT |
||
| 65 | * generator to ensure identifier uniqueness |
||
| 66 | */ |
||
| 67 | const GENERATOR_TYPE_ALNUM = 4; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * CUSTOM means Doctrine expect a class parameter. It will then try to initiate that class |
||
| 71 | * and pass other options to the generator. It will throw an Exception if the class |
||
| 72 | * does not exist or if an option was passed for that there is not setter in the new |
||
| 73 | * generator class. |
||
| 74 | * |
||
| 75 | * The class will have to be a subtype of AbstractIdGenerator. |
||
| 76 | */ |
||
| 77 | const GENERATOR_TYPE_CUSTOM = 5; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * NONE means Doctrine will not generate any id for us and you are responsible for manually |
||
| 81 | * assigning an id. |
||
| 82 | */ |
||
| 83 | const GENERATOR_TYPE_NONE = 6; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Default discriminator field name. |
||
| 87 | * |
||
| 88 | * This is used for associations value for associations where a that do not define a "targetDocument" or |
||
| 89 | * "discriminatorField" option in their mapping. |
||
| 90 | */ |
||
| 91 | const DEFAULT_DISCRIMINATOR_FIELD = '_doctrine_class_name'; |
||
| 92 | |||
| 93 | const REFERENCE_ONE = 1; |
||
| 94 | const REFERENCE_MANY = 2; |
||
| 95 | const EMBED_ONE = 3; |
||
| 96 | const EMBED_MANY = 4; |
||
| 97 | const MANY = 'many'; |
||
| 98 | const ONE = 'one'; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * The types of storeAs references |
||
| 102 | */ |
||
| 103 | const REFERENCE_STORE_AS_ID = 'id'; |
||
| 104 | const REFERENCE_STORE_AS_DB_REF = 'dbRef'; |
||
| 105 | const REFERENCE_STORE_AS_DB_REF_WITH_DB = 'dbRefWithDb'; |
||
| 106 | const REFERENCE_STORE_AS_REF = 'ref'; |
||
| 107 | |||
| 108 | /* The inheritance mapping types */ |
||
| 109 | /** |
||
| 110 | * NONE means the class does not participate in an inheritance hierarchy |
||
| 111 | * and therefore does not need an inheritance mapping type. |
||
| 112 | */ |
||
| 113 | const INHERITANCE_TYPE_NONE = 1; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * SINGLE_COLLECTION means the class will be persisted according to the rules of |
||
| 117 | * <tt>Single Collection Inheritance</tt>. |
||
| 118 | */ |
||
| 119 | const INHERITANCE_TYPE_SINGLE_COLLECTION = 2; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * COLLECTION_PER_CLASS means the class will be persisted according to the rules |
||
| 123 | * of <tt>Concrete Collection Inheritance</tt>. |
||
| 124 | */ |
||
| 125 | const INHERITANCE_TYPE_COLLECTION_PER_CLASS = 3; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time |
||
| 129 | * by doing a property-by-property comparison with the original data. This will |
||
| 130 | * be done for all entities that are in MANAGED state at commit-time. |
||
| 131 | * |
||
| 132 | * This is the default change tracking policy. |
||
| 133 | */ |
||
| 134 | const CHANGETRACKING_DEFERRED_IMPLICIT = 1; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time |
||
| 138 | * by doing a property-by-property comparison with the original data. This will |
||
| 139 | * be done only for entities that were explicitly saved (through persist() or a cascade). |
||
| 140 | */ |
||
| 141 | const CHANGETRACKING_DEFERRED_EXPLICIT = 2; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * NOTIFY means that Doctrine relies on the entities sending out notifications |
||
| 145 | * when their properties change. Such entity classes must implement |
||
| 146 | * the <tt>NotifyPropertyChanged</tt> interface. |
||
| 147 | */ |
||
| 148 | const CHANGETRACKING_NOTIFY = 3; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * SET means that fields will be written to the database using a $set operator |
||
| 152 | */ |
||
| 153 | const STORAGE_STRATEGY_SET = 'set'; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * INCREMENT means that fields will be written to the database by calculating |
||
| 157 | * the difference and using the $inc operator |
||
| 158 | */ |
||
| 159 | const STORAGE_STRATEGY_INCREMENT = 'increment'; |
||
| 160 | |||
| 161 | const STORAGE_STRATEGY_PUSH_ALL = 'pushAll'; |
||
| 162 | const STORAGE_STRATEGY_ADD_TO_SET = 'addToSet'; |
||
| 163 | const STORAGE_STRATEGY_ATOMIC_SET = 'atomicSet'; |
||
| 164 | const STORAGE_STRATEGY_ATOMIC_SET_ARRAY = 'atomicSetArray'; |
||
| 165 | const STORAGE_STRATEGY_SET_ARRAY = 'setArray'; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * READ-ONLY: The name of the mongo database the document is mapped to. |
||
| 169 | */ |
||
| 170 | public $db; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * READ-ONLY: The name of the mongo collection the document is mapped to. |
||
| 174 | */ |
||
| 175 | public $collection; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * READ-ONLY: If the collection should be a fixed size. |
||
| 179 | */ |
||
| 180 | public $collectionCapped; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * READ-ONLY: If the collection is fixed size, its size in bytes. |
||
| 184 | */ |
||
| 185 | public $collectionSize; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * READ-ONLY: If the collection is fixed size, the maximum number of elements to store in the collection. |
||
| 189 | */ |
||
| 190 | public $collectionMax; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set. |
||
| 194 | */ |
||
| 195 | public $readPreference; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * READ-ONLY Associated with readPreference Allows to specify criteria so that your application can target read |
||
| 199 | * operations to specific members, based on custom parameters. |
||
| 200 | */ |
||
| 201 | public $readPreferenceTags; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * READ-ONLY: Describes the level of acknowledgement requested from MongoDB for write operations. |
||
| 205 | */ |
||
| 206 | public $writeConcern; |
||
| 207 | |||
| 208 | /** |
||
| 209 | * READ-ONLY: The field name of the document identifier. |
||
| 210 | */ |
||
| 211 | public $identifier; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * READ-ONLY: Whether or not reads for this class are okay to read from a slave. |
||
| 215 | * |
||
| 216 | * @deprecated in version 1.2 and will be removed in 2.0. |
||
| 217 | */ |
||
| 218 | public $slaveOkay; |
||
| 219 | |||
| 220 | /** |
||
| 221 | * READ-ONLY: The array of indexes for the document collection. |
||
| 222 | */ |
||
| 223 | public $indexes = array(); |
||
| 224 | |||
| 225 | /** |
||
| 226 | * READ-ONLY: Keys and options describing shard key. Only for sharded collections. |
||
| 227 | */ |
||
| 228 | public $shardKey; |
||
| 229 | |||
| 230 | /** |
||
| 231 | * READ-ONLY: The name of the document class. |
||
| 232 | */ |
||
| 233 | public $name; |
||
| 234 | |||
| 235 | /** |
||
| 236 | * READ-ONLY: The namespace the document class is contained in. |
||
| 237 | * |
||
| 238 | * @var string |
||
| 239 | * @todo Not really needed. Usage could be localized. |
||
| 240 | */ |
||
| 241 | public $namespace; |
||
| 242 | |||
| 243 | /** |
||
| 244 | * READ-ONLY: The name of the document class that is at the root of the mapped document inheritance |
||
| 245 | * hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same |
||
| 246 | * as {@link $documentName}. |
||
| 247 | * |
||
| 248 | * @var string |
||
| 249 | */ |
||
| 250 | public $rootDocumentName; |
||
| 251 | |||
| 252 | /** |
||
| 253 | * The name of the custom repository class used for the document class. |
||
| 254 | * (Optional). |
||
| 255 | * |
||
| 256 | * @var string |
||
| 257 | */ |
||
| 258 | public $customRepositoryClassName; |
||
| 259 | |||
| 260 | /** |
||
| 261 | * READ-ONLY: The names of the parent classes (ancestors). |
||
| 262 | * |
||
| 263 | * @var array |
||
| 264 | */ |
||
| 265 | public $parentClasses = array(); |
||
| 266 | |||
| 267 | /** |
||
| 268 | * READ-ONLY: The names of all subclasses (descendants). |
||
| 269 | * |
||
| 270 | * @var array |
||
| 271 | */ |
||
| 272 | public $subClasses = array(); |
||
| 273 | |||
| 274 | /** |
||
| 275 | * The ReflectionProperty instances of the mapped class. |
||
| 276 | * |
||
| 277 | * @var \ReflectionProperty[] |
||
| 278 | */ |
||
| 279 | public $reflFields = array(); |
||
| 280 | |||
| 281 | /** |
||
| 282 | * READ-ONLY: The inheritance mapping type used by the class. |
||
| 283 | * |
||
| 284 | * @var integer |
||
| 285 | */ |
||
| 286 | public $inheritanceType = self::INHERITANCE_TYPE_NONE; |
||
| 287 | |||
| 288 | /** |
||
| 289 | * READ-ONLY: The Id generator type used by the class. |
||
| 290 | * |
||
| 291 | * @var string |
||
| 292 | */ |
||
| 293 | public $generatorType = self::GENERATOR_TYPE_AUTO; |
||
| 294 | |||
| 295 | /** |
||
| 296 | * READ-ONLY: The Id generator options. |
||
| 297 | * |
||
| 298 | * @var array |
||
| 299 | */ |
||
| 300 | public $generatorOptions = array(); |
||
| 301 | |||
| 302 | /** |
||
| 303 | * READ-ONLY: The ID generator used for generating IDs for this class. |
||
| 304 | * |
||
| 305 | * @var \Doctrine\ODM\MongoDB\Id\AbstractIdGenerator |
||
| 306 | */ |
||
| 307 | public $idGenerator; |
||
| 308 | |||
| 309 | /** |
||
| 310 | * READ-ONLY: The field mappings of the class. |
||
| 311 | * Keys are field names and values are mapping definitions. |
||
| 312 | * |
||
| 313 | * The mapping definition array has the following values: |
||
| 314 | * |
||
| 315 | * - <b>fieldName</b> (string) |
||
| 316 | * The name of the field in the Document. |
||
| 317 | * |
||
| 318 | * - <b>id</b> (boolean, optional) |
||
| 319 | * Marks the field as the primary key of the document. Multiple fields of an |
||
| 320 | * document can have the id attribute, forming a composite key. |
||
| 321 | * |
||
| 322 | * @var array |
||
| 323 | */ |
||
| 324 | public $fieldMappings = array(); |
||
| 325 | |||
| 326 | /** |
||
| 327 | * READ-ONLY: The association mappings of the class. |
||
| 328 | * Keys are field names and values are mapping definitions. |
||
| 329 | * |
||
| 330 | * @var array |
||
| 331 | */ |
||
| 332 | public $associationMappings = array(); |
||
| 333 | |||
| 334 | /** |
||
| 335 | * READ-ONLY: Array of fields to also load with a given method. |
||
| 336 | * |
||
| 337 | * @var array |
||
| 338 | */ |
||
| 339 | public $alsoLoadMethods = array(); |
||
| 340 | |||
| 341 | /** |
||
| 342 | * READ-ONLY: The registered lifecycle callbacks for documents of this class. |
||
| 343 | * |
||
| 344 | * @var array |
||
| 345 | */ |
||
| 346 | public $lifecycleCallbacks = array(); |
||
| 347 | |||
| 348 | /** |
||
| 349 | * READ-ONLY: The discriminator value of this class. |
||
| 350 | * |
||
| 351 | * <b>This does only apply to the JOINED and SINGLE_COLLECTION inheritance mapping strategies |
||
| 352 | * where a discriminator field is used.</b> |
||
| 353 | * |
||
| 354 | * @var mixed |
||
| 355 | * @see discriminatorField |
||
| 356 | */ |
||
| 357 | public $discriminatorValue; |
||
| 358 | |||
| 359 | /** |
||
| 360 | * READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
||
| 361 | * |
||
| 362 | * <b>This does only apply to the SINGLE_COLLECTION inheritance mapping strategy |
||
| 363 | * where a discriminator field is used.</b> |
||
| 364 | * |
||
| 365 | * @var mixed |
||
| 366 | * @see discriminatorField |
||
| 367 | */ |
||
| 368 | public $discriminatorMap = array(); |
||
| 369 | |||
| 370 | /** |
||
| 371 | * READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION |
||
| 372 | * inheritance mapping. |
||
| 373 | * |
||
| 374 | * @var string |
||
| 375 | */ |
||
| 376 | public $discriminatorField; |
||
| 377 | |||
| 378 | /** |
||
| 379 | * READ-ONLY: The default value for discriminatorField in case it's not set in the document |
||
| 380 | * |
||
| 381 | * @var string |
||
| 382 | * @see discriminatorField |
||
| 383 | */ |
||
| 384 | public $defaultDiscriminatorValue; |
||
| 385 | |||
| 386 | /** |
||
| 387 | * READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
||
| 388 | * |
||
| 389 | * @var boolean |
||
| 390 | */ |
||
| 391 | public $isMappedSuperclass = false; |
||
| 392 | |||
| 393 | /** |
||
| 394 | * READ-ONLY: Whether this class describes the mapping of a embedded document. |
||
| 395 | * |
||
| 396 | * @var boolean |
||
| 397 | */ |
||
| 398 | public $isEmbeddedDocument = false; |
||
| 399 | |||
| 400 | /** |
||
| 401 | * READ-ONLY: Whether this class describes the mapping of an aggregation result document. |
||
| 402 | * |
||
| 403 | * @var boolean |
||
| 404 | */ |
||
| 405 | public $isQueryResultDocument = false; |
||
| 406 | |||
| 407 | /** |
||
| 408 | * READ-ONLY: The policy used for change-tracking on entities of this class. |
||
| 409 | * |
||
| 410 | * @var integer |
||
| 411 | */ |
||
| 412 | public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT; |
||
| 413 | |||
| 414 | /** |
||
| 415 | * READ-ONLY: A flag for whether or not instances of this class are to be versioned |
||
| 416 | * with optimistic locking. |
||
| 417 | * |
||
| 418 | * @var boolean $isVersioned |
||
| 419 | */ |
||
| 420 | public $isVersioned; |
||
| 421 | |||
| 422 | /** |
||
| 423 | * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). |
||
| 424 | * |
||
| 425 | * @var mixed $versionField |
||
| 426 | */ |
||
| 427 | public $versionField; |
||
| 428 | |||
| 429 | /** |
||
| 430 | * READ-ONLY: A flag for whether or not instances of this class are to allow pessimistic |
||
| 431 | * locking. |
||
| 432 | * |
||
| 433 | * @var boolean $isLockable |
||
| 434 | */ |
||
| 435 | public $isLockable; |
||
| 436 | |||
| 437 | /** |
||
| 438 | * READ-ONLY: The name of the field which is used for locking a document. |
||
| 439 | * |
||
| 440 | * @var mixed $lockField |
||
| 441 | */ |
||
| 442 | public $lockField; |
||
| 443 | |||
| 444 | /** |
||
| 445 | * The ReflectionClass instance of the mapped class. |
||
| 446 | * |
||
| 447 | * @var \ReflectionClass |
||
| 448 | */ |
||
| 449 | public $reflClass; |
||
| 450 | |||
| 451 | /** |
||
| 452 | * READ_ONLY: A flag for whether or not this document is read-only. |
||
| 453 | * |
||
| 454 | * @var bool |
||
| 455 | */ |
||
| 456 | public $isReadOnly; |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Initializes a new ClassMetadata instance that will hold the object-document mapping |
||
| 460 | * metadata of the class with the given name. |
||
| 461 | * |
||
| 462 | * @param string $documentName The name of the document class the new instance is used for. |
||
| 463 | */ |
||
| 464 | 1516 | public function __construct($documentName) |
|
| 469 | |||
| 470 | /** |
||
| 471 | * Helper method to get reference id of ref* type references |
||
| 472 | * @param mixed $reference |
||
| 473 | * @param string $storeAs |
||
| 474 | * @return mixed |
||
| 475 | * @internal |
||
| 476 | */ |
||
| 477 | 121 | public static function getReferenceId($reference, $storeAs) |
|
| 481 | |||
| 482 | /** |
||
| 483 | * Returns the reference prefix used for a reference |
||
| 484 | * @param string $storeAs |
||
| 485 | * @return string |
||
| 486 | */ |
||
| 487 | 186 | private static function getReferencePrefix($storeAs) |
|
| 495 | |||
| 496 | /** |
||
| 497 | * Returns a fully qualified field name for a given reference |
||
| 498 | * @param string $storeAs |
||
| 499 | * @param string $pathPrefix The field path prefix |
||
| 500 | * @return string |
||
| 501 | * @internal |
||
| 502 | */ |
||
| 503 | 134 | public static function getReferenceFieldName($storeAs, $pathPrefix = '') |
|
| 511 | |||
| 512 | /** |
||
| 513 | * {@inheritDoc} |
||
| 514 | */ |
||
| 515 | 1383 | public function getReflectionClass() |
|
| 523 | |||
| 524 | /** |
||
| 525 | * {@inheritDoc} |
||
| 526 | */ |
||
| 527 | 323 | public function isIdentifier($fieldName) |
|
| 531 | |||
| 532 | /** |
||
| 533 | * INTERNAL: |
||
| 534 | * Sets the mapped identifier field of this class. |
||
| 535 | * |
||
| 536 | * @param string $identifier |
||
| 537 | */ |
||
| 538 | 896 | public function setIdentifier($identifier) |
|
| 542 | |||
| 543 | /** |
||
| 544 | * {@inheritDoc} |
||
| 545 | * |
||
| 546 | * Since MongoDB only allows exactly one identifier field |
||
| 547 | * this will always return an array with only one value |
||
| 548 | */ |
||
| 549 | 38 | public function getIdentifier() |
|
| 553 | |||
| 554 | /** |
||
| 555 | * {@inheritDoc} |
||
| 556 | * |
||
| 557 | * Since MongoDB only allows exactly one identifier field |
||
| 558 | * this will always return an array with only one value |
||
| 559 | */ |
||
| 560 | 99 | public function getIdentifierFieldNames() |
|
| 564 | |||
| 565 | /** |
||
| 566 | * {@inheritDoc} |
||
| 567 | */ |
||
| 568 | 892 | public function hasField($fieldName) |
|
| 572 | |||
| 573 | /** |
||
| 574 | * Sets the inheritance type used by the class and it's subclasses. |
||
| 575 | * |
||
| 576 | * @param integer $type |
||
| 577 | */ |
||
| 578 | 912 | public function setInheritanceType($type) |
|
| 582 | |||
| 583 | /** |
||
| 584 | * Checks whether a mapped field is inherited from an entity superclass. |
||
| 585 | * |
||
| 586 | * @param string $fieldName |
||
| 587 | * |
||
| 588 | * @return boolean TRUE if the field is inherited, FALSE otherwise. |
||
| 589 | */ |
||
| 590 | 1383 | public function isInheritedField($fieldName) |
|
| 594 | |||
| 595 | /** |
||
| 596 | * Registers a custom repository class for the document class. |
||
| 597 | * |
||
| 598 | * @param string $repositoryClassName The class name of the custom repository. |
||
| 599 | */ |
||
| 600 | 844 | public function setCustomRepositoryClass($repositoryClassName) |
|
| 612 | |||
| 613 | /** |
||
| 614 | * Dispatches the lifecycle event of the given document by invoking all |
||
| 615 | * registered callbacks. |
||
| 616 | * |
||
| 617 | * @param string $event Lifecycle event |
||
| 618 | * @param object $document Document on which the event occurred |
||
| 619 | * @param array $arguments Arguments to pass to all callbacks |
||
| 620 | * @throws \InvalidArgumentException if document class is not this class or |
||
| 621 | * a Proxy of this class |
||
| 622 | */ |
||
| 623 | 609 | public function invokeLifecycleCallbacks($event, $document, array $arguments = null) |
|
| 641 | |||
| 642 | /** |
||
| 643 | * Checks whether the class has callbacks registered for a lifecycle event. |
||
| 644 | * |
||
| 645 | * @param string $event Lifecycle event |
||
| 646 | * |
||
| 647 | * @return boolean |
||
| 648 | */ |
||
| 649 | public function hasLifecycleCallbacks($event) |
||
| 653 | |||
| 654 | /** |
||
| 655 | * Gets the registered lifecycle callbacks for an event. |
||
| 656 | * |
||
| 657 | * @param string $event |
||
| 658 | * @return array |
||
| 659 | */ |
||
| 660 | public function getLifecycleCallbacks($event) |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Adds a lifecycle callback for documents of this class. |
||
| 667 | * |
||
| 668 | * If the callback is already registered, this is a NOOP. |
||
| 669 | * |
||
| 670 | * @param string $callback |
||
| 671 | * @param string $event |
||
| 672 | */ |
||
| 673 | 817 | public function addLifecycleCallback($callback, $event) |
|
| 681 | |||
| 682 | /** |
||
| 683 | * Sets the lifecycle callbacks for documents of this class. |
||
| 684 | * |
||
| 685 | * Any previously registered callbacks are overwritten. |
||
| 686 | * |
||
| 687 | * @param array $callbacks |
||
| 688 | */ |
||
| 689 | 895 | public function setLifecycleCallbacks(array $callbacks) |
|
| 693 | |||
| 694 | /** |
||
| 695 | * Registers a method for loading document data before field hydration. |
||
| 696 | * |
||
| 697 | * Note: A method may be registered multiple times for different fields. |
||
| 698 | * it will be invoked only once for the first field found. |
||
| 699 | * |
||
| 700 | * @param string $method Method name |
||
| 701 | * @param array|string $fields Database field name(s) |
||
| 702 | */ |
||
| 703 | 15 | public function registerAlsoLoadMethod($method, $fields) |
|
| 707 | |||
| 708 | /** |
||
| 709 | * Sets the AlsoLoad methods for documents of this class. |
||
| 710 | * |
||
| 711 | * Any previously registered methods are overwritten. |
||
| 712 | * |
||
| 713 | * @param array $methods |
||
| 714 | */ |
||
| 715 | 895 | public function setAlsoLoadMethods(array $methods) |
|
| 719 | |||
| 720 | /** |
||
| 721 | * Sets the discriminator field. |
||
| 722 | * |
||
| 723 | * The field name is the the unmapped database field. Discriminator values |
||
| 724 | * are only used to discern the hydration class and are not mapped to class |
||
| 725 | * properties. |
||
| 726 | * |
||
| 727 | * @param string $discriminatorField |
||
| 728 | * |
||
| 729 | * @throws MappingException If the discriminator field conflicts with the |
||
| 730 | * "name" attribute of a mapped field. |
||
| 731 | */ |
||
| 732 | 922 | public function setDiscriminatorField($discriminatorField) |
|
| 757 | |||
| 758 | /** |
||
| 759 | * Sets the discriminator values used by this class. |
||
| 760 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
||
| 761 | * |
||
| 762 | * @param array $map |
||
| 763 | * |
||
| 764 | * @throws MappingException |
||
| 765 | */ |
||
| 766 | 915 | public function setDiscriminatorMap(array $map) |
|
| 785 | |||
| 786 | /** |
||
| 787 | * Sets the default discriminator value to be used for this class |
||
| 788 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value |
||
| 789 | * |
||
| 790 | * @param string $defaultDiscriminatorValue |
||
| 791 | * |
||
| 792 | * @throws MappingException |
||
| 793 | */ |
||
| 794 | 899 | public function setDefaultDiscriminatorValue($defaultDiscriminatorValue) |
|
| 808 | |||
| 809 | /** |
||
| 810 | * Sets the discriminator value for this class. |
||
| 811 | * Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single |
||
| 812 | * collection. |
||
| 813 | * |
||
| 814 | * @param string $value |
||
| 815 | */ |
||
| 816 | 3 | public function setDiscriminatorValue($value) |
|
| 821 | |||
| 822 | /** |
||
| 823 | * Sets the slaveOkay option applied to collections for this class. |
||
| 824 | * |
||
| 825 | * @param boolean|null $slaveOkay |
||
| 826 | * |
||
| 827 | * @deprecated in version 1.2 and will be removed in 2.0. |
||
| 828 | * |
||
| 829 | * @throws MappingException |
||
| 830 | */ |
||
| 831 | 2 | public function setSlaveOkay($slaveOkay) |
|
| 845 | |||
| 846 | /** |
||
| 847 | * Add a index for this Document. |
||
| 848 | * |
||
| 849 | * @param array $keys Array of keys for the index. |
||
| 850 | * @param array $options Array of options for the index. |
||
| 851 | */ |
||
| 852 | 189 | public function addIndex($keys, array $options = array()) |
|
| 872 | |||
| 873 | /** |
||
| 874 | * Returns the array of indexes for this Document. |
||
| 875 | * |
||
| 876 | * @return array $indexes The array of indexes. |
||
| 877 | */ |
||
| 878 | 25 | public function getIndexes() |
|
| 882 | |||
| 883 | /** |
||
| 884 | * Checks whether this document has indexes or not. |
||
| 885 | * |
||
| 886 | * @return boolean |
||
| 887 | */ |
||
| 888 | public function hasIndexes() |
||
| 892 | |||
| 893 | /** |
||
| 894 | * Set shard key for this Document. |
||
| 895 | * |
||
| 896 | * @param array $keys Array of document keys. |
||
| 897 | * @param array $options Array of sharding options. |
||
| 898 | * |
||
| 899 | * @throws MappingException |
||
| 900 | */ |
||
| 901 | 72 | public function setShardKey(array $keys, array $options = array()) |
|
| 943 | |||
| 944 | /** |
||
| 945 | * @return array |
||
| 946 | */ |
||
| 947 | 18 | public function getShardKey() |
|
| 951 | |||
| 952 | /** |
||
| 953 | * Checks whether this document has shard key or not. |
||
| 954 | * |
||
| 955 | * @return bool |
||
| 956 | */ |
||
| 957 | 1111 | public function isSharded() |
|
| 961 | |||
| 962 | /** |
||
| 963 | * Sets the read preference used by this class. |
||
| 964 | * |
||
| 965 | * @param string $readPreference |
||
| 966 | * @param array|null $tags |
||
| 967 | * |
||
| 968 | * @throws MappingException |
||
| 969 | */ |
||
| 970 | 896 | public function setReadPreference($readPreference, $tags) |
|
| 978 | |||
| 979 | /** |
||
| 980 | * Sets the write concern used by this class. |
||
| 981 | * |
||
| 982 | * @param string $writeConcern |
||
| 983 | */ |
||
| 984 | 906 | public function setWriteConcern($writeConcern) |
|
| 988 | |||
| 989 | /** |
||
| 990 | * @return string |
||
| 991 | */ |
||
| 992 | 12 | public function getWriteConcern() |
|
| 996 | |||
| 997 | /** |
||
| 998 | * Whether there is a write concern configured for this class. |
||
| 999 | * |
||
| 1000 | * @return bool |
||
| 1001 | */ |
||
| 1002 | 558 | public function hasWriteConcern() |
|
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Sets the change tracking policy used by this class. |
||
| 1009 | * |
||
| 1010 | * @param integer $policy |
||
| 1011 | */ |
||
| 1012 | 899 | public function setChangeTrackingPolicy($policy) |
|
| 1016 | |||
| 1017 | /** |
||
| 1018 | * Whether the change tracking policy of this class is "deferred explicit". |
||
| 1019 | * |
||
| 1020 | * @return boolean |
||
| 1021 | */ |
||
| 1022 | 69 | public function isChangeTrackingDeferredExplicit() |
|
| 1026 | |||
| 1027 | /** |
||
| 1028 | * Whether the change tracking policy of this class is "deferred implicit". |
||
| 1029 | * |
||
| 1030 | * @return boolean |
||
| 1031 | */ |
||
| 1032 | 578 | public function isChangeTrackingDeferredImplicit() |
|
| 1036 | |||
| 1037 | /** |
||
| 1038 | * Whether the change tracking policy of this class is "notify". |
||
| 1039 | * |
||
| 1040 | * @return boolean |
||
| 1041 | */ |
||
| 1042 | 314 | public function isChangeTrackingNotify() |
|
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Gets the ReflectionProperties of the mapped class. |
||
| 1049 | * |
||
| 1050 | * @return array An array of ReflectionProperty instances. |
||
| 1051 | */ |
||
| 1052 | 99 | public function getReflectionProperties() |
|
| 1056 | |||
| 1057 | /** |
||
| 1058 | * Gets a ReflectionProperty for a specific field of the mapped class. |
||
| 1059 | * |
||
| 1060 | * @param string $name |
||
| 1061 | * |
||
| 1062 | * @return \ReflectionProperty |
||
| 1063 | */ |
||
| 1064 | public function getReflectionProperty($name) |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * {@inheritDoc} |
||
| 1071 | */ |
||
| 1072 | 1390 | public function getName() |
|
| 1076 | |||
| 1077 | /** |
||
| 1078 | * The namespace this Document class belongs to. |
||
| 1079 | * |
||
| 1080 | * @return string $namespace The namespace name. |
||
| 1081 | */ |
||
| 1082 | public function getNamespace() |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Returns the database this Document is mapped to. |
||
| 1089 | * |
||
| 1090 | * @return string $db The database name. |
||
| 1091 | */ |
||
| 1092 | 1310 | public function getDatabase() |
|
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Set the database this Document is mapped to. |
||
| 1099 | * |
||
| 1100 | * @param string $db The database name |
||
| 1101 | */ |
||
| 1102 | 95 | public function setDatabase($db) |
|
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Get the collection this Document is mapped to. |
||
| 1109 | * |
||
| 1110 | * @return string $collection The collection name. |
||
| 1111 | */ |
||
| 1112 | 1314 | public function getCollection() |
|
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Sets the collection this Document is mapped to. |
||
| 1119 | * |
||
| 1120 | * @param array|string $name |
||
| 1121 | * |
||
| 1122 | * @throws \InvalidArgumentException |
||
| 1123 | */ |
||
| 1124 | 1481 | public function setCollection($name) |
|
| 1138 | |||
| 1139 | /** |
||
| 1140 | * Get whether or not the documents collection is capped. |
||
| 1141 | * |
||
| 1142 | * @return boolean |
||
| 1143 | */ |
||
| 1144 | 4 | public function getCollectionCapped() |
|
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Set whether or not the documents collection is capped. |
||
| 1151 | * |
||
| 1152 | * @param boolean $bool |
||
| 1153 | */ |
||
| 1154 | 1 | public function setCollectionCapped($bool) |
|
| 1158 | |||
| 1159 | /** |
||
| 1160 | * Get the collection size |
||
| 1161 | * |
||
| 1162 | * @return integer |
||
| 1163 | */ |
||
| 1164 | 4 | public function getCollectionSize() |
|
| 1168 | |||
| 1169 | /** |
||
| 1170 | * Set the collection size. |
||
| 1171 | * |
||
| 1172 | * @param integer $size |
||
| 1173 | */ |
||
| 1174 | 1 | public function setCollectionSize($size) |
|
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Get the collection max. |
||
| 1181 | * |
||
| 1182 | * @return integer |
||
| 1183 | */ |
||
| 1184 | 4 | public function getCollectionMax() |
|
| 1188 | |||
| 1189 | /** |
||
| 1190 | * Set the collection max. |
||
| 1191 | * |
||
| 1192 | * @param integer $max |
||
| 1193 | */ |
||
| 1194 | 1 | public function setCollectionMax($max) |
|
| 1198 | |||
| 1199 | /** |
||
| 1200 | * Returns TRUE if this Document is mapped to a collection FALSE otherwise. |
||
| 1201 | * |
||
| 1202 | * @return boolean |
||
| 1203 | */ |
||
| 1204 | public function isMappedToCollection() |
||
| 1208 | |||
| 1209 | /** |
||
| 1210 | * Map a field. |
||
| 1211 | * |
||
| 1212 | * @param array $mapping The mapping information. |
||
| 1213 | * |
||
| 1214 | * @return array |
||
| 1215 | * |
||
| 1216 | * @throws MappingException |
||
| 1217 | */ |
||
| 1218 | 1431 | public function mapField(array $mapping) |
|
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Validates the storage strategy of a mapping for consistency |
||
| 1392 | * @param array $mapping |
||
| 1393 | * @throws \Doctrine\ODM\MongoDB\Mapping\MappingException |
||
| 1394 | */ |
||
| 1395 | 1419 | private function applyStorageStrategy(array &$mapping) |
|
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Map a single embedded document. |
||
| 1441 | * |
||
| 1442 | * @param array $mapping The mapping information. |
||
| 1443 | */ |
||
| 1444 | 6 | public function mapOneEmbedded(array $mapping) |
|
| 1450 | |||
| 1451 | /** |
||
| 1452 | * Map a collection of embedded documents. |
||
| 1453 | * |
||
| 1454 | * @param array $mapping The mapping information. |
||
| 1455 | */ |
||
| 1456 | 5 | public function mapManyEmbedded(array $mapping) |
|
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Map a single document reference. |
||
| 1465 | * |
||
| 1466 | * @param array $mapping The mapping information. |
||
| 1467 | */ |
||
| 1468 | 8 | public function mapOneReference(array $mapping) |
|
| 1474 | |||
| 1475 | /** |
||
| 1476 | * Map a collection of document references. |
||
| 1477 | * |
||
| 1478 | * @param array $mapping The mapping information. |
||
| 1479 | */ |
||
| 1480 | 8 | public function mapManyReference(array $mapping) |
|
| 1486 | |||
| 1487 | /** |
||
| 1488 | * INTERNAL: |
||
| 1489 | * Adds a field mapping without completing/validating it. |
||
| 1490 | * This is mainly used to add inherited field mappings to derived classes. |
||
| 1491 | * |
||
| 1492 | * @param array $fieldMapping |
||
| 1493 | */ |
||
| 1494 | 119 | public function addInheritedFieldMapping(array $fieldMapping) |
|
| 1502 | |||
| 1503 | /** |
||
| 1504 | * INTERNAL: |
||
| 1505 | * Adds an association mapping without completing/validating it. |
||
| 1506 | * This is mainly used to add inherited association mappings to derived classes. |
||
| 1507 | * |
||
| 1508 | * @param array $mapping |
||
| 1509 | * |
||
| 1510 | * @return void |
||
| 1511 | * |
||
| 1512 | * @throws MappingException |
||
| 1513 | */ |
||
| 1514 | 69 | public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/) |
|
| 1518 | |||
| 1519 | /** |
||
| 1520 | * Checks whether the class has a mapped association with the given field name. |
||
| 1521 | * |
||
| 1522 | * @param string $fieldName |
||
| 1523 | * @return boolean |
||
| 1524 | */ |
||
| 1525 | 32 | public function hasReference($fieldName) |
|
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Checks whether the class has a mapped embed with the given field name. |
||
| 1532 | * |
||
| 1533 | * @param string $fieldName |
||
| 1534 | * @return boolean |
||
| 1535 | */ |
||
| 1536 | 5 | public function hasEmbed($fieldName) |
|
| 1540 | |||
| 1541 | /** |
||
| 1542 | * {@inheritDoc} |
||
| 1543 | * |
||
| 1544 | * Checks whether the class has a mapped association (embed or reference) with the given field name. |
||
| 1545 | */ |
||
| 1546 | 7 | public function hasAssociation($fieldName) |
|
| 1550 | |||
| 1551 | /** |
||
| 1552 | * {@inheritDoc} |
||
| 1553 | * |
||
| 1554 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1555 | * is a single valued association. |
||
| 1556 | */ |
||
| 1557 | public function isSingleValuedAssociation($fieldName) |
||
| 1561 | |||
| 1562 | /** |
||
| 1563 | * {@inheritDoc} |
||
| 1564 | * |
||
| 1565 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1566 | * is a collection valued association. |
||
| 1567 | */ |
||
| 1568 | public function isCollectionValuedAssociation($fieldName) |
||
| 1572 | |||
| 1573 | /** |
||
| 1574 | * Checks whether the class has a mapped association for the specified field |
||
| 1575 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1576 | * |
||
| 1577 | * @param string $fieldName |
||
| 1578 | * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1579 | */ |
||
| 1580 | public function isSingleValuedReference($fieldName) |
||
| 1585 | |||
| 1586 | /** |
||
| 1587 | * Checks whether the class has a mapped association for the specified field |
||
| 1588 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1589 | * |
||
| 1590 | * @param string $fieldName |
||
| 1591 | * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. |
||
| 1592 | */ |
||
| 1593 | public function isCollectionValuedReference($fieldName) |
||
| 1598 | |||
| 1599 | /** |
||
| 1600 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1601 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1602 | * |
||
| 1603 | * @param string $fieldName |
||
| 1604 | * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1605 | */ |
||
| 1606 | public function isSingleValuedEmbed($fieldName) |
||
| 1611 | |||
| 1612 | /** |
||
| 1613 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1614 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1615 | * |
||
| 1616 | * @param string $fieldName |
||
| 1617 | * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. |
||
| 1618 | */ |
||
| 1619 | public function isCollectionValuedEmbed($fieldName) |
||
| 1624 | |||
| 1625 | /** |
||
| 1626 | * Sets the ID generator used to generate IDs for instances of this class. |
||
| 1627 | * |
||
| 1628 | * @param \Doctrine\ODM\MongoDB\Id\AbstractIdGenerator $generator |
||
| 1629 | */ |
||
| 1630 | 1324 | public function setIdGenerator($generator) |
|
| 1634 | |||
| 1635 | /** |
||
| 1636 | * Casts the identifier to its portable PHP type. |
||
| 1637 | * |
||
| 1638 | * @param mixed $id |
||
| 1639 | * @return mixed $id |
||
| 1640 | */ |
||
| 1641 | 600 | public function getPHPIdentifierValue($id) |
|
| 1646 | |||
| 1647 | /** |
||
| 1648 | * Casts the identifier to its database type. |
||
| 1649 | * |
||
| 1650 | * @param mixed $id |
||
| 1651 | * @return mixed $id |
||
| 1652 | */ |
||
| 1653 | 666 | public function getDatabaseIdentifierValue($id) |
|
| 1658 | |||
| 1659 | /** |
||
| 1660 | * Sets the document identifier of a document. |
||
| 1661 | * |
||
| 1662 | * The value will be converted to a PHP type before being set. |
||
| 1663 | * |
||
| 1664 | * @param object $document |
||
| 1665 | * @param mixed $id |
||
| 1666 | */ |
||
| 1667 | 528 | public function setIdentifierValue($document, $id) |
|
| 1672 | |||
| 1673 | /** |
||
| 1674 | * Gets the document identifier as a PHP type. |
||
| 1675 | * |
||
| 1676 | * @param object $document |
||
| 1677 | * @return mixed $id |
||
| 1678 | */ |
||
| 1679 | 614 | public function getIdentifierValue($document) |
|
| 1683 | |||
| 1684 | /** |
||
| 1685 | * {@inheritDoc} |
||
| 1686 | * |
||
| 1687 | * Since MongoDB only allows exactly one identifier field this is a proxy |
||
| 1688 | * to {@see getIdentifierValue()} and returns an array with the identifier |
||
| 1689 | * field as a key. |
||
| 1690 | */ |
||
| 1691 | public function getIdentifierValues($object) |
||
| 1695 | |||
| 1696 | /** |
||
| 1697 | * Get the document identifier object as a database type. |
||
| 1698 | * |
||
| 1699 | * @param object $document |
||
| 1700 | * |
||
| 1701 | * @return \MongoDB\BSON\ObjectId $id The ObjectId |
||
| 1702 | */ |
||
| 1703 | 32 | public function getIdentifierObject($document) |
|
| 1707 | |||
| 1708 | /** |
||
| 1709 | * Sets the specified field to the specified value on the given document. |
||
| 1710 | * |
||
| 1711 | * @param object $document |
||
| 1712 | * @param string $field |
||
| 1713 | * @param mixed $value |
||
| 1714 | */ |
||
| 1715 | 8 | public function setFieldValue($document, $field, $value) |
|
| 1725 | |||
| 1726 | /** |
||
| 1727 | * Gets the specified field's value off the given document. |
||
| 1728 | * |
||
| 1729 | * @param object $document |
||
| 1730 | * @param string $field |
||
| 1731 | * |
||
| 1732 | * @return mixed |
||
| 1733 | */ |
||
| 1734 | 27 | public function getFieldValue($document, $field) |
|
| 1742 | |||
| 1743 | /** |
||
| 1744 | * Gets the mapping of a field. |
||
| 1745 | * |
||
| 1746 | * @param string $fieldName The field name. |
||
| 1747 | * |
||
| 1748 | * @return array The field mapping. |
||
| 1749 | * |
||
| 1750 | * @throws MappingException if the $fieldName is not found in the fieldMappings array |
||
| 1751 | */ |
||
| 1752 | 167 | public function getFieldMapping($fieldName) |
|
| 1759 | |||
| 1760 | /** |
||
| 1761 | * Gets mappings of fields holding embedded document(s). |
||
| 1762 | * |
||
| 1763 | * @return array of field mappings |
||
| 1764 | */ |
||
| 1765 | 569 | public function getEmbeddedFieldsMappings() |
|
| 1772 | |||
| 1773 | /** |
||
| 1774 | * Gets the field mapping by its DB name. |
||
| 1775 | * E.g. it returns identifier's mapping when called with _id. |
||
| 1776 | * |
||
| 1777 | * @param string $dbFieldName |
||
| 1778 | * |
||
| 1779 | * @return array |
||
| 1780 | * @throws MappingException |
||
| 1781 | */ |
||
| 1782 | 4 | public function getFieldMappingByDbFieldName($dbFieldName) |
|
| 1792 | |||
| 1793 | /** |
||
| 1794 | * Check if the field is not null. |
||
| 1795 | * |
||
| 1796 | * @param string $fieldName The field name |
||
| 1797 | * |
||
| 1798 | * @return boolean TRUE if the field is not null, FALSE otherwise. |
||
| 1799 | */ |
||
| 1800 | 1 | public function isNullable($fieldName) |
|
| 1808 | |||
| 1809 | /** |
||
| 1810 | * Checks whether the document has a discriminator field and value configured. |
||
| 1811 | * |
||
| 1812 | * @return boolean |
||
| 1813 | */ |
||
| 1814 | 498 | public function hasDiscriminator() |
|
| 1818 | |||
| 1819 | /** |
||
| 1820 | * Sets the type of Id generator to use for the mapped class. |
||
| 1821 | * |
||
| 1822 | * @param string $generatorType Generator type. |
||
| 1823 | */ |
||
| 1824 | 901 | public function setIdGeneratorType($generatorType) |
|
| 1828 | |||
| 1829 | /** |
||
| 1830 | * Sets the Id generator options. |
||
| 1831 | * |
||
| 1832 | * @param array $generatorOptions Generator options. |
||
| 1833 | */ |
||
| 1834 | public function setIdGeneratorOptions($generatorOptions) |
||
| 1838 | |||
| 1839 | /** |
||
| 1840 | * @return boolean |
||
| 1841 | */ |
||
| 1842 | 576 | public function isInheritanceTypeNone() |
|
| 1846 | |||
| 1847 | /** |
||
| 1848 | * Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy. |
||
| 1849 | * |
||
| 1850 | * @return boolean |
||
| 1851 | */ |
||
| 1852 | 894 | public function isInheritanceTypeSingleCollection() |
|
| 1856 | |||
| 1857 | /** |
||
| 1858 | * Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy. |
||
| 1859 | * |
||
| 1860 | * @return boolean |
||
| 1861 | */ |
||
| 1862 | public function isInheritanceTypeCollectionPerClass() |
||
| 1866 | |||
| 1867 | /** |
||
| 1868 | * Sets the mapped subclasses of this class. |
||
| 1869 | * |
||
| 1870 | * @param string[] $subclasses The names of all mapped subclasses. |
||
| 1871 | */ |
||
| 1872 | 2 | public function setSubclasses(array $subclasses) |
|
| 1882 | |||
| 1883 | /** |
||
| 1884 | * Sets the parent class names. |
||
| 1885 | * Assumes that the class names in the passed array are in the order: |
||
| 1886 | * directParent -> directParentParent -> directParentParentParent ... -> root. |
||
| 1887 | * |
||
| 1888 | * @param string[] $classNames |
||
| 1889 | */ |
||
| 1890 | 1381 | public function setParentClasses(array $classNames) |
|
| 1898 | |||
| 1899 | /** |
||
| 1900 | * Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us. |
||
| 1901 | * |
||
| 1902 | * @return boolean TRUE if the class uses the AUTO generator, FALSE otherwise. |
||
| 1903 | */ |
||
| 1904 | public function isIdGeneratorAuto() |
||
| 1908 | |||
| 1909 | /** |
||
| 1910 | * Checks whether the class will use a collection to generate incremented identifiers. |
||
| 1911 | * |
||
| 1912 | * @return boolean TRUE if the class uses the INCREMENT generator, FALSE otherwise. |
||
| 1913 | */ |
||
| 1914 | public function isIdGeneratorIncrement() |
||
| 1918 | |||
| 1919 | /** |
||
| 1920 | * Checks whether the class will generate a uuid id. |
||
| 1921 | * |
||
| 1922 | * @return boolean TRUE if the class uses the UUID generator, FALSE otherwise. |
||
| 1923 | */ |
||
| 1924 | public function isIdGeneratorUuid() |
||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * Checks whether the class uses no id generator. |
||
| 1931 | * |
||
| 1932 | * @return boolean TRUE if the class does not use any id generator, FALSE otherwise. |
||
| 1933 | */ |
||
| 1934 | public function isIdGeneratorNone() |
||
| 1938 | |||
| 1939 | /** |
||
| 1940 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1941 | * value to use depending on the column type. |
||
| 1942 | * |
||
| 1943 | * @param array $mapping The version field mapping array |
||
| 1944 | * |
||
| 1945 | * @throws LockException |
||
| 1946 | */ |
||
| 1947 | 68 | public function setVersionMapping(array &$mapping) |
|
| 1956 | |||
| 1957 | /** |
||
| 1958 | * Sets whether this class is to be versioned for optimistic locking. |
||
| 1959 | * |
||
| 1960 | * @param boolean $bool |
||
| 1961 | */ |
||
| 1962 | 895 | public function setVersioned($bool) |
|
| 1966 | |||
| 1967 | /** |
||
| 1968 | * Sets the name of the field that is to be used for versioning if this class is |
||
| 1969 | * versioned for optimistic locking. |
||
| 1970 | * |
||
| 1971 | * @param string $versionField |
||
| 1972 | */ |
||
| 1973 | 895 | public function setVersionField($versionField) |
|
| 1977 | |||
| 1978 | /** |
||
| 1979 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1980 | * value to use depending on the column type. |
||
| 1981 | * |
||
| 1982 | * @param array $mapping The version field mapping array |
||
| 1983 | * |
||
| 1984 | * @throws \Doctrine\ODM\MongoDB\LockException |
||
| 1985 | */ |
||
| 1986 | 23 | public function setLockMapping(array &$mapping) |
|
| 1995 | |||
| 1996 | /** |
||
| 1997 | * Sets whether this class is to allow pessimistic locking. |
||
| 1998 | * |
||
| 1999 | * @param boolean $bool |
||
| 2000 | */ |
||
| 2001 | public function setLockable($bool) |
||
| 2005 | |||
| 2006 | /** |
||
| 2007 | * Sets the name of the field that is to be used for storing whether a document |
||
| 2008 | * is currently locked or not. |
||
| 2009 | * |
||
| 2010 | * @param string $lockField |
||
| 2011 | */ |
||
| 2012 | public function setLockField($lockField) |
||
| 2016 | |||
| 2017 | /** |
||
| 2018 | * Marks this class as read only, no change tracking is applied to it. |
||
| 2019 | */ |
||
| 2020 | 6 | public function markReadOnly() |
|
| 2024 | |||
| 2025 | /** |
||
| 2026 | * {@inheritDoc} |
||
| 2027 | */ |
||
| 2028 | public function getFieldNames() |
||
| 2032 | |||
| 2033 | /** |
||
| 2034 | * {@inheritDoc} |
||
| 2035 | */ |
||
| 2036 | public function getAssociationNames() |
||
| 2040 | |||
| 2041 | /** |
||
| 2042 | * {@inheritDoc} |
||
| 2043 | */ |
||
| 2044 | 23 | public function getTypeOfField($fieldName) |
|
| 2049 | |||
| 2050 | /** |
||
| 2051 | * {@inheritDoc} |
||
| 2052 | */ |
||
| 2053 | 6 | public function getAssociationTargetClass($assocName) |
|
| 2061 | |||
| 2062 | /** |
||
| 2063 | * Retrieve the collectionClass associated with an association |
||
| 2064 | * |
||
| 2065 | * @param string $assocName |
||
| 2066 | */ |
||
| 2067 | 2 | public function getAssociationCollectionClass($assocName) |
|
| 2079 | |||
| 2080 | /** |
||
| 2081 | * {@inheritDoc} |
||
| 2082 | */ |
||
| 2083 | public function isAssociationInverseSide($fieldName) |
||
| 2087 | |||
| 2088 | /** |
||
| 2089 | * {@inheritDoc} |
||
| 2090 | */ |
||
| 2091 | public function getAssociationMappedByTargetField($fieldName) |
||
| 2095 | } |
||
| 2096 |
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: