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 \MongoId 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: The field that stores a file reference and indicates the |
||
| 215 | * document is a file and should be stored on the MongoGridFS. |
||
| 216 | */ |
||
| 217 | public $file; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * READ-ONLY: The field that stores the calculated distance when performing geo spatial |
||
| 221 | * queries. |
||
| 222 | */ |
||
| 223 | public $distance; |
||
| 224 | |||
| 225 | /** |
||
| 226 | * READ-ONLY: Whether or not reads for this class are okay to read from a slave. |
||
| 227 | * |
||
| 228 | * @deprecated in version 1.2 and will be removed in 2.0. |
||
| 229 | */ |
||
| 230 | public $slaveOkay; |
||
| 231 | |||
| 232 | /** |
||
| 233 | * READ-ONLY: The array of indexes for the document collection. |
||
| 234 | */ |
||
| 235 | public $indexes = array(); |
||
| 236 | |||
| 237 | /** |
||
| 238 | * READ-ONLY: Keys and options describing shard key. Only for sharded collections. |
||
| 239 | */ |
||
| 240 | public $shardKey; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * READ-ONLY: Whether or not queries on this document should require indexes. |
||
| 244 | * |
||
| 245 | * @deprecated property was deprecated in 1.2 and will be removed in 2.0 |
||
| 246 | */ |
||
| 247 | public $requireIndexes = false; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * READ-ONLY: The name of the document class. |
||
| 251 | */ |
||
| 252 | public $name; |
||
| 253 | |||
| 254 | /** |
||
| 255 | * READ-ONLY: The namespace the document class is contained in. |
||
| 256 | * |
||
| 257 | * @var string |
||
| 258 | * @todo Not really needed. Usage could be localized. |
||
| 259 | */ |
||
| 260 | public $namespace; |
||
| 261 | |||
| 262 | /** |
||
| 263 | * READ-ONLY: The name of the document class that is at the root of the mapped document inheritance |
||
| 264 | * hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same |
||
| 265 | * as {@link $documentName}. |
||
| 266 | * |
||
| 267 | * @var string |
||
| 268 | */ |
||
| 269 | public $rootDocumentName; |
||
| 270 | |||
| 271 | /** |
||
| 272 | * The name of the custom repository class used for the document class. |
||
| 273 | * (Optional). |
||
| 274 | * |
||
| 275 | * @var string |
||
| 276 | */ |
||
| 277 | public $customRepositoryClassName; |
||
| 278 | |||
| 279 | /** |
||
| 280 | * READ-ONLY: The names of the parent classes (ancestors). |
||
| 281 | * |
||
| 282 | * @var array |
||
| 283 | */ |
||
| 284 | public $parentClasses = array(); |
||
| 285 | |||
| 286 | /** |
||
| 287 | * READ-ONLY: The names of all subclasses (descendants). |
||
| 288 | * |
||
| 289 | * @var array |
||
| 290 | */ |
||
| 291 | public $subClasses = array(); |
||
| 292 | |||
| 293 | /** |
||
| 294 | * The ReflectionProperty instances of the mapped class. |
||
| 295 | * |
||
| 296 | * @var \ReflectionProperty[] |
||
| 297 | */ |
||
| 298 | public $reflFields = array(); |
||
| 299 | |||
| 300 | /** |
||
| 301 | * READ-ONLY: The inheritance mapping type used by the class. |
||
| 302 | * |
||
| 303 | * @var integer |
||
| 304 | */ |
||
| 305 | public $inheritanceType = self::INHERITANCE_TYPE_NONE; |
||
| 306 | |||
| 307 | /** |
||
| 308 | * READ-ONLY: The Id generator type used by the class. |
||
| 309 | * |
||
| 310 | * @var string |
||
| 311 | */ |
||
| 312 | public $generatorType = self::GENERATOR_TYPE_AUTO; |
||
| 313 | |||
| 314 | /** |
||
| 315 | * READ-ONLY: The Id generator options. |
||
| 316 | * |
||
| 317 | * @var array |
||
| 318 | */ |
||
| 319 | public $generatorOptions = array(); |
||
| 320 | |||
| 321 | /** |
||
| 322 | * READ-ONLY: The ID generator used for generating IDs for this class. |
||
| 323 | * |
||
| 324 | * @var \Doctrine\ODM\MongoDB\Id\AbstractIdGenerator |
||
| 325 | */ |
||
| 326 | public $idGenerator; |
||
| 327 | |||
| 328 | /** |
||
| 329 | * READ-ONLY: The field mappings of the class. |
||
| 330 | * Keys are field names and values are mapping definitions. |
||
| 331 | * |
||
| 332 | * The mapping definition array has the following values: |
||
| 333 | * |
||
| 334 | * - <b>fieldName</b> (string) |
||
| 335 | * The name of the field in the Document. |
||
| 336 | * |
||
| 337 | * - <b>id</b> (boolean, optional) |
||
| 338 | * Marks the field as the primary key of the document. Multiple fields of an |
||
| 339 | * document can have the id attribute, forming a composite key. |
||
| 340 | * |
||
| 341 | * @var array |
||
| 342 | */ |
||
| 343 | public $fieldMappings = array(); |
||
| 344 | |||
| 345 | /** |
||
| 346 | * READ-ONLY: The association mappings of the class. |
||
| 347 | * Keys are field names and values are mapping definitions. |
||
| 348 | * |
||
| 349 | * @var array |
||
| 350 | */ |
||
| 351 | public $associationMappings = array(); |
||
| 352 | |||
| 353 | /** |
||
| 354 | * READ-ONLY: Array of fields to also load with a given method. |
||
| 355 | * |
||
| 356 | * @var array |
||
| 357 | */ |
||
| 358 | public $alsoLoadMethods = array(); |
||
| 359 | |||
| 360 | /** |
||
| 361 | * READ-ONLY: The registered lifecycle callbacks for documents of this class. |
||
| 362 | * |
||
| 363 | * @var array |
||
| 364 | */ |
||
| 365 | public $lifecycleCallbacks = array(); |
||
| 366 | |||
| 367 | /** |
||
| 368 | * READ-ONLY: The discriminator value of this class. |
||
| 369 | * |
||
| 370 | * <b>This does only apply to the JOINED and SINGLE_COLLECTION inheritance mapping strategies |
||
| 371 | * where a discriminator field is used.</b> |
||
| 372 | * |
||
| 373 | * @var mixed |
||
| 374 | * @see discriminatorField |
||
| 375 | */ |
||
| 376 | public $discriminatorValue; |
||
| 377 | |||
| 378 | /** |
||
| 379 | * READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
||
| 380 | * |
||
| 381 | * <b>This does only apply to the SINGLE_COLLECTION inheritance mapping strategy |
||
| 382 | * where a discriminator field is used.</b> |
||
| 383 | * |
||
| 384 | * @var mixed |
||
| 385 | * @see discriminatorField |
||
| 386 | */ |
||
| 387 | public $discriminatorMap = array(); |
||
| 388 | |||
| 389 | /** |
||
| 390 | * READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION |
||
| 391 | * inheritance mapping. |
||
| 392 | * |
||
| 393 | * @var string |
||
| 394 | */ |
||
| 395 | public $discriminatorField; |
||
| 396 | |||
| 397 | /** |
||
| 398 | * READ-ONLY: The default value for discriminatorField in case it's not set in the document |
||
| 399 | * |
||
| 400 | * @var string |
||
| 401 | * @see discriminatorField |
||
| 402 | */ |
||
| 403 | public $defaultDiscriminatorValue; |
||
| 404 | |||
| 405 | /** |
||
| 406 | * READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
||
| 407 | * |
||
| 408 | * @var boolean |
||
| 409 | */ |
||
| 410 | public $isMappedSuperclass = false; |
||
| 411 | |||
| 412 | /** |
||
| 413 | * READ-ONLY: Whether this class describes the mapping of a embedded document. |
||
| 414 | * |
||
| 415 | * @var boolean |
||
| 416 | */ |
||
| 417 | public $isEmbeddedDocument = false; |
||
| 418 | |||
| 419 | /** |
||
| 420 | * READ-ONLY: Whether this class describes the mapping of an aggregation result document. |
||
| 421 | * |
||
| 422 | * @var boolean |
||
| 423 | */ |
||
| 424 | public $isQueryResultDocument = false; |
||
| 425 | |||
| 426 | /** |
||
| 427 | * READ-ONLY: The policy used for change-tracking on entities of this class. |
||
| 428 | * |
||
| 429 | * @var integer |
||
| 430 | */ |
||
| 431 | public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT; |
||
| 432 | |||
| 433 | /** |
||
| 434 | * READ-ONLY: A flag for whether or not instances of this class are to be versioned |
||
| 435 | * with optimistic locking. |
||
| 436 | * |
||
| 437 | * @var boolean $isVersioned |
||
| 438 | */ |
||
| 439 | public $isVersioned; |
||
| 440 | |||
| 441 | /** |
||
| 442 | * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). |
||
| 443 | * |
||
| 444 | * @var mixed $versionField |
||
| 445 | */ |
||
| 446 | public $versionField; |
||
| 447 | |||
| 448 | /** |
||
| 449 | * READ-ONLY: A flag for whether or not instances of this class are to allow pessimistic |
||
| 450 | * locking. |
||
| 451 | * |
||
| 452 | * @var boolean $isLockable |
||
| 453 | */ |
||
| 454 | public $isLockable; |
||
| 455 | |||
| 456 | /** |
||
| 457 | * READ-ONLY: The name of the field which is used for locking a document. |
||
| 458 | * |
||
| 459 | * @var mixed $lockField |
||
| 460 | */ |
||
| 461 | public $lockField; |
||
| 462 | |||
| 463 | /** |
||
| 464 | * The ReflectionClass instance of the mapped class. |
||
| 465 | * |
||
| 466 | * @var \ReflectionClass |
||
| 467 | */ |
||
| 468 | public $reflClass; |
||
| 469 | |||
| 470 | /** |
||
| 471 | * READ_ONLY: A flag for whether or not this document is read-only. |
||
| 472 | 1001 | * |
|
| 473 | * @var bool |
||
| 474 | 1001 | */ |
|
| 475 | 1001 | public $isReadOnly; |
|
| 476 | 1001 | ||
| 477 | /** |
||
| 478 | * Initializes a new ClassMetadata instance that will hold the object-document mapping |
||
| 479 | * metadata of the class with the given name. |
||
| 480 | * |
||
| 481 | * @param string $documentName The name of the document class the new instance is used for. |
||
| 482 | */ |
||
| 483 | public function __construct($documentName) |
||
| 484 | { |
||
| 485 | 117 | $this->name = $documentName; |
|
| 486 | $this->rootDocumentName = $documentName; |
||
| 487 | 117 | } |
|
| 488 | |||
| 489 | /** |
||
| 490 | * Helper method to get reference id of ref* type references |
||
| 491 | * @param mixed $reference |
||
| 492 | * @param string $storeAs |
||
| 493 | * @return mixed |
||
| 494 | * @internal |
||
| 495 | 196 | */ |
|
| 496 | public static function getReferenceId($reference, $storeAs) |
||
| 497 | 196 | { |
|
| 498 | return $storeAs === ClassMetadataInfo::REFERENCE_STORE_AS_ID ? $reference : $reference[ClassMetadataInfo::getReferencePrefix($storeAs) . 'id']; |
||
| 499 | } |
||
| 500 | |||
| 501 | 196 | /** |
|
| 502 | * Returns the reference prefix used for a reference |
||
| 503 | * @param string $storeAs |
||
| 504 | * @return string |
||
| 505 | */ |
||
| 506 | private static function getReferencePrefix($storeAs) |
||
| 507 | { |
||
| 508 | if (!in_array($storeAs, [ClassMetadataInfo::REFERENCE_STORE_AS_REF, ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF, ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF_WITH_DB])) { |
||
| 509 | throw new \LogicException('Can only get a reference prefix for DBRef and reference arrays'); |
||
| 510 | } |
||
| 511 | 142 | ||
| 512 | return $storeAs === ClassMetadataInfo::REFERENCE_STORE_AS_REF ? '' : '$'; |
||
| 513 | 142 | } |
|
| 514 | 103 | ||
| 515 | /** |
||
| 516 | * Returns a fully qualified field name for a given reference |
||
| 517 | 133 | * @param string $storeAs |
|
| 518 | * @param string $pathPrefix The field path prefix |
||
| 519 | * @return string |
||
| 520 | * @internal |
||
| 521 | */ |
||
| 522 | public static function getReferenceFieldName($storeAs, $pathPrefix = '') |
||
| 530 | |||
| 531 | /** |
||
| 532 | * {@inheritDoc} |
||
| 533 | */ |
||
| 534 | public function getReflectionClass() |
||
| 535 | 337 | { |
|
| 536 | if ( ! $this->reflClass) { |
||
| 537 | 337 | $this->reflClass = new \ReflectionClass($this->name); |
|
| 538 | } |
||
| 539 | |||
| 540 | return $this->reflClass; |
||
| 541 | } |
||
| 542 | |||
| 543 | /** |
||
| 544 | * {@inheritDoc} |
||
| 545 | */ |
||
| 546 | 374 | public function isIdentifier($fieldName) |
|
| 547 | { |
||
| 548 | 374 | return $this->identifier === $fieldName; |
|
| 549 | 374 | } |
|
| 550 | |||
| 551 | /** |
||
| 552 | * INTERNAL: |
||
| 553 | * Sets the mapped identifier field of this class. |
||
| 554 | * |
||
| 555 | * @param string $identifier |
||
| 556 | */ |
||
| 557 | 40 | public function setIdentifier($identifier) |
|
| 558 | { |
||
| 559 | 40 | $this->identifier = $identifier; |
|
| 560 | } |
||
| 561 | |||
| 562 | /** |
||
| 563 | * {@inheritDoc} |
||
| 564 | * |
||
| 565 | * Since MongoDB only allows exactly one identifier field |
||
| 566 | * this will always return an array with only one value |
||
| 567 | */ |
||
| 568 | 98 | public function getIdentifier() |
|
| 572 | |||
| 573 | /** |
||
| 574 | * {@inheritDoc} |
||
| 575 | * |
||
| 576 | 573 | * Since MongoDB only allows exactly one identifier field |
|
| 577 | * this will always return an array with only one value |
||
| 578 | 573 | */ |
|
| 579 | public function getIdentifierFieldNames() |
||
| 580 | { |
||
| 581 | return array($this->identifier); |
||
| 582 | } |
||
| 583 | |||
| 584 | /** |
||
| 585 | * {@inheritDoc} |
||
| 586 | 390 | */ |
|
| 587 | public function hasField($fieldName) |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Sets the inheritance type used by the class and it's subclasses. |
||
| 594 | * |
||
| 595 | * @param integer $type |
||
| 596 | */ |
||
| 597 | public function setInheritanceType($type) |
||
| 598 | 929 | { |
|
| 599 | $this->inheritanceType = $type; |
||
| 600 | 929 | } |
|
| 601 | |||
| 602 | /** |
||
| 603 | * Checks whether a mapped field is inherited from an entity superclass. |
||
| 604 | * |
||
| 605 | * @param string $fieldName |
||
| 606 | * |
||
| 607 | * @return boolean TRUE if the field is inherited, FALSE otherwise. |
||
| 608 | 322 | */ |
|
| 609 | public function isInheritedField($fieldName) |
||
| 610 | 322 | { |
|
| 611 | return isset($this->fieldMappings[$fieldName]['inherited']); |
||
| 612 | } |
||
| 613 | |||
| 614 | 322 | /** |
|
| 615 | 4 | * Registers a custom repository class for the document class. |
|
| 616 | * |
||
| 617 | * @param string $repositoryClassName The class name of the custom repository. |
||
| 618 | 322 | */ |
|
| 619 | 322 | public function setCustomRepositoryClass($repositoryClassName) |
|
| 620 | { |
||
| 621 | if ($this->isEmbeddedDocument || $this->isQueryResultDocument) { |
||
| 622 | return; |
||
| 623 | } |
||
| 624 | |||
| 625 | View Code Duplication | if ($repositoryClassName && strpos($repositoryClassName, '\\') === false && strlen($this->namespace)) { |
|
| 626 | $repositoryClassName = $this->namespace . '\\' . $repositoryClassName; |
||
| 627 | } |
||
| 628 | |||
| 629 | $this->customRepositoryClassName = $repositoryClassName; |
||
| 630 | } |
||
| 631 | 678 | ||
| 632 | /** |
||
| 633 | 678 | * Dispatches the lifecycle event of the given document by invoking all |
|
| 634 | 1 | * registered callbacks. |
|
| 635 | * |
||
| 636 | * @param string $event Lifecycle event |
||
| 637 | 677 | * @param object $document Document on which the event occurred |
|
| 638 | 663 | * @param array $arguments Arguments to pass to all callbacks |
|
| 639 | * @throws \InvalidArgumentException if document class is not this class or |
||
| 640 | * a Proxy of this class |
||
| 641 | 200 | */ |
|
| 642 | 200 | public function invokeLifecycleCallbacks($event, $document, array $arguments = null) |
|
| 643 | 199 | { |
|
| 644 | if ( ! $document instanceof $this->name) { |
||
| 645 | 200 | throw new \InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, get_class($document))); |
|
| 646 | } |
||
| 647 | |||
| 648 | 200 | if (empty($this->lifecycleCallbacks[$event])) { |
|
| 649 | return; |
||
| 650 | } |
||
| 651 | |||
| 652 | foreach ($this->lifecycleCallbacks[$event] as $callback) { |
||
| 653 | if ($arguments !== null) { |
||
| 654 | call_user_func_array(array($document, $callback), $arguments); |
||
| 655 | } else { |
||
| 656 | $document->$callback(); |
||
| 657 | } |
||
| 658 | } |
||
| 659 | } |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Checks whether the class has callbacks registered for a lifecycle event. |
||
| 663 | * |
||
| 664 | * @param string $event Lifecycle event |
||
| 665 | * |
||
| 666 | * @return boolean |
||
| 667 | */ |
||
| 668 | public function hasLifecycleCallbacks($event) |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Gets the registered lifecycle callbacks for an event. |
||
| 675 | * |
||
| 676 | * @param string $event |
||
| 677 | * @return array |
||
| 678 | */ |
||
| 679 | public function getLifecycleCallbacks($event) |
||
| 680 | { |
||
| 681 | 301 | return isset($this->lifecycleCallbacks[$event]) ? $this->lifecycleCallbacks[$event] : array(); |
|
| 682 | } |
||
| 683 | 301 | ||
| 684 | 1 | /** |
|
| 685 | * Adds a lifecycle callback for documents of this class. |
||
| 686 | * |
||
| 687 | 301 | * If the callback is already registered, this is a NOOP. |
|
| 688 | 301 | * |
|
| 689 | * @param string $callback |
||
| 690 | * @param string $event |
||
| 691 | */ |
||
| 692 | public function addLifecycleCallback($callback, $event) |
||
| 700 | 373 | ||
| 701 | /** |
||
| 702 | * Sets the lifecycle callbacks for documents of this class. |
||
| 703 | * |
||
| 704 | * Any previously registered callbacks are overwritten. |
||
| 705 | * |
||
| 706 | * @param array $callbacks |
||
| 707 | */ |
||
| 708 | public function setLifecycleCallbacks(array $callbacks) |
||
| 712 | |||
| 713 | 15 | /** |
|
| 714 | 15 | * Registers a method for loading document data before field hydration. |
|
| 715 | * |
||
| 716 | * Note: A method may be registered multiple times for different fields. |
||
| 717 | * it will be invoked only once for the first field found. |
||
| 718 | * |
||
| 719 | * @param string $method Method name |
||
| 720 | * @param array|string $fields Database field name(s) |
||
| 721 | */ |
||
| 722 | public function registerAlsoLoadMethod($method, $fields) |
||
| 726 | 373 | ||
| 727 | /** |
||
| 728 | * Sets the AlsoLoad methods for documents of this class. |
||
| 729 | * |
||
| 730 | * Any previously registered methods are overwritten. |
||
| 731 | * |
||
| 732 | * @param array $methods |
||
| 733 | */ |
||
| 734 | public function setAlsoLoadMethods(array $methods) |
||
| 738 | |||
| 739 | /** |
||
| 740 | 403 | * Sets the discriminator field. |
|
| 741 | * |
||
| 742 | 403 | * The field name is the the unmapped database field. Discriminator values |
|
| 743 | 330 | * are only used to discern the hydration class and are not mapped to class |
|
| 744 | * properties. |
||
| 745 | 330 | * |
|
| 746 | * @param string $discriminatorField |
||
| 747 | * |
||
| 748 | * @throws MappingException If the discriminator field conflicts with the |
||
| 749 | 130 | * "name" attribute of a mapped field. |
|
| 750 | */ |
||
| 751 | public function setDiscriminatorField($discriminatorField) |
||
| 776 | 396 | ||
| 777 | 125 | /** |
|
| 778 | 91 | * Sets the discriminator values used by this class. |
|
| 779 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
||
| 780 | 125 | * |
|
| 781 | 125 | * @param array $map |
|
| 782 | 117 | * |
|
| 783 | * @throws MappingException |
||
| 784 | 120 | */ |
|
| 785 | public function setDiscriminatorMap(array $map) |
||
| 804 | 380 | ||
| 805 | 373 | /** |
|
| 806 | * Sets the default discriminator value to be used for this class |
||
| 807 | 373 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value |
|
| 808 | * |
||
| 809 | * @param string $defaultDiscriminatorValue |
||
| 810 | 60 | * |
|
| 811 | * @throws MappingException |
||
| 812 | */ |
||
| 813 | public function setDefaultDiscriminatorValue($defaultDiscriminatorValue) |
||
| 827 | 3 | ||
| 828 | 3 | /** |
|
| 829 | * Sets the discriminator value for this class. |
||
| 830 | * Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single |
||
| 831 | * collection. |
||
| 832 | * |
||
| 833 | * @param string $value |
||
| 834 | */ |
||
| 835 | public function setDiscriminatorValue($value) |
||
| 840 | 3 | ||
| 841 | 3 | /** |
|
| 842 | * Sets the slaveOkay option applied to collections for this class. |
||
| 843 | 3 | * |
|
| 844 | 3 | * @param boolean|null $slaveOkay |
|
| 845 | * |
||
| 846 | * @deprecated in version 1.2 and will be removed in 2.0. |
||
| 847 | * |
||
| 848 | * @throws MappingException |
||
| 849 | */ |
||
| 850 | public function setSlaveOkay($slaveOkay) |
||
| 864 | 4 | ||
| 865 | /** |
||
| 866 | * Add a index for this Document. |
||
| 867 | 7 | * |
|
| 868 | 235 | * @param array $keys Array of keys for the index. |
|
| 869 | 235 | * @param array $options Array of options for the index. |
|
| 870 | */ |
||
| 871 | 235 | public function addIndex($keys, array $options = array()) |
|
| 891 | |||
| 892 | /** |
||
| 893 | * Set whether or not queries on this document should require indexes. |
||
| 894 | 54 | * |
|
| 895 | * @param bool $requireIndexes |
||
| 896 | 54 | * |
|
| 897 | * @deprecated method was deprecated in 1.2 and will be removed in 2.0 |
||
| 898 | */ |
||
| 899 | public function setRequireIndexes($requireIndexes) |
||
| 910 | |||
| 911 | /** |
||
| 912 | * Returns the array of indexes for this Document. |
||
| 913 | * |
||
| 914 | * @return array $indexes The array of indexes. |
||
| 915 | */ |
||
| 916 | public function getIndexes() |
||
| 920 | 2 | ||
| 921 | /** |
||
| 922 | * Checks whether this document has indexes or not. |
||
| 923 | 87 | * |
|
| 924 | 2 | * @return boolean |
|
| 925 | */ |
||
| 926 | public function hasIndexes() |
||
| 930 | |||
| 931 | /** |
||
| 932 | 7 | * Set shard key for this Document. |
|
| 933 | 3 | * |
|
| 934 | * @param array $keys Array of document keys. |
||
| 935 | * @param array $options Array of sharding options. |
||
| 936 | 4 | * |
|
| 937 | 4 | * @throws MappingException |
|
| 938 | */ |
||
| 939 | public function setShardKey(array $keys, array $options = array()) |
||
| 981 | |||
| 982 | /** |
||
| 983 | 387 | * @return array |
|
| 984 | */ |
||
| 985 | 387 | public function getShardKey() |
|
| 989 | |||
| 990 | /** |
||
| 991 | 12 | * Checks whether this document has shard key or not. |
|
| 992 | * |
||
| 993 | 12 | * @return bool |
|
| 994 | */ |
||
| 995 | public function isSharded() |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | 622 | * Sets the read preference used by this class. |
|
| 1002 | * |
||
| 1003 | 622 | * @param string $readPreference |
|
| 1004 | * @param array|null $tags |
||
| 1005 | * |
||
| 1006 | * @throws MappingException |
||
| 1007 | */ |
||
| 1008 | public function setReadPreference($readPreference, $tags) |
||
| 1016 | |||
| 1017 | /** |
||
| 1018 | * Sets the write concern used by this class. |
||
| 1019 | * |
||
| 1020 | * @param string $writeConcern |
||
| 1021 | 75 | */ |
|
| 1022 | public function setWriteConcern($writeConcern) |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * @return string |
||
| 1029 | */ |
||
| 1030 | public function getWriteConcern() |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * Whether there is a write concern configured for this class. |
||
| 1037 | * |
||
| 1038 | * @return bool |
||
| 1039 | */ |
||
| 1040 | public function hasWriteConcern() |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Sets the change tracking policy used by this class. |
||
| 1047 | * |
||
| 1048 | * @param integer $policy |
||
| 1049 | */ |
||
| 1050 | public function setChangeTrackingPolicy($policy) |
||
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Whether the change tracking policy of this class is "deferred explicit". |
||
| 1057 | * |
||
| 1058 | * @return boolean |
||
| 1059 | */ |
||
| 1060 | public function isChangeTrackingDeferredExplicit() |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * Whether the change tracking policy of this class is "deferred implicit". |
||
| 1067 | * |
||
| 1068 | * @return boolean |
||
| 1069 | */ |
||
| 1070 | public function isChangeTrackingDeferredImplicit() |
||
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Whether the change tracking policy of this class is "notify". |
||
| 1077 | * |
||
| 1078 | * @return boolean |
||
| 1079 | */ |
||
| 1080 | public function isChangeTrackingNotify() |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Gets the ReflectionProperties of the mapped class. |
||
| 1087 | * |
||
| 1088 | * @return array An array of ReflectionProperty instances. |
||
| 1089 | */ |
||
| 1090 | public function getReflectionProperties() |
||
| 1094 | |||
| 1095 | /** |
||
| 1096 | * Gets a ReflectionProperty for a specific field of the mapped class. |
||
| 1097 | * |
||
| 1098 | * @param string $name |
||
| 1099 | * |
||
| 1100 | * @return \ReflectionProperty |
||
| 1101 | 104 | */ |
|
| 1102 | public function getReflectionProperty($name) |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * {@inheritDoc} |
||
| 1109 | */ |
||
| 1110 | public function getName() |
||
| 1114 | |||
| 1115 | /** |
||
| 1116 | * The namespace this Document class belongs to. |
||
| 1117 | * |
||
| 1118 | * @return string $namespace The namespace name. |
||
| 1119 | */ |
||
| 1120 | public function getNamespace() |
||
| 1124 | |||
| 1125 | 965 | /** |
|
| 1126 | * Returns the database this Document is mapped to. |
||
| 1127 | * |
||
| 1128 | * @return string $db The database name. |
||
| 1129 | */ |
||
| 1130 | public function getDatabase() |
||
| 1134 | 965 | ||
| 1135 | /** |
||
| 1136 | 965 | * Set the database this Document is mapped to. |
|
| 1137 | * |
||
| 1138 | * @param string $db The database name |
||
| 1139 | */ |
||
| 1140 | public function setDatabase($db) |
||
| 1144 | |||
| 1145 | 4 | /** |
|
| 1146 | * Get the collection this Document is mapped to. |
||
| 1147 | * |
||
| 1148 | * @return string $collection The collection name. |
||
| 1149 | */ |
||
| 1150 | public function getCollection() |
||
| 1154 | |||
| 1155 | 1 | /** |
|
| 1156 | 1 | * Sets the collection this Document is mapped to. |
|
| 1157 | * |
||
| 1158 | * @param array|string $name |
||
| 1159 | * |
||
| 1160 | * @throws \InvalidArgumentException |
||
| 1161 | */ |
||
| 1162 | public function setCollection($name) |
||
| 1176 | 1 | ||
| 1177 | /** |
||
| 1178 | * Get whether or not the documents collection is capped. |
||
| 1179 | * |
||
| 1180 | * @return boolean |
||
| 1181 | */ |
||
| 1182 | public function getCollectionCapped() |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Set whether or not the documents collection is capped. |
||
| 1189 | * |
||
| 1190 | * @param boolean $bool |
||
| 1191 | */ |
||
| 1192 | public function setCollectionCapped($bool) |
||
| 1196 | 1 | ||
| 1197 | /** |
||
| 1198 | * Get the collection size |
||
| 1199 | * |
||
| 1200 | * @return integer |
||
| 1201 | */ |
||
| 1202 | public function getCollectionSize() |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Set the collection size. |
||
| 1209 | * |
||
| 1210 | * @param integer $size |
||
| 1211 | */ |
||
| 1212 | public function setCollectionSize($size) |
||
| 1216 | |||
| 1217 | /** |
||
| 1218 | * Get the collection max. |
||
| 1219 | * |
||
| 1220 | * @return integer |
||
| 1221 | */ |
||
| 1222 | public function getCollectionMax() |
||
| 1226 | |||
| 1227 | /** |
||
| 1228 | * Set the collection max. |
||
| 1229 | * |
||
| 1230 | * @param integer $max |
||
| 1231 | */ |
||
| 1232 | public function setCollectionMax($max) |
||
| 1236 | 374 | ||
| 1237 | /** |
||
| 1238 | * Returns TRUE if this Document is mapped to a collection FALSE otherwise. |
||
| 1239 | * |
||
| 1240 | * @return boolean |
||
| 1241 | */ |
||
| 1242 | public function isMappedToCollection() |
||
| 1246 | |||
| 1247 | /** |
||
| 1248 | * Returns TRUE if this Document is a file to be stored on the MongoGridFS FALSE otherwise. |
||
| 1249 | * |
||
| 1250 | * @return boolean |
||
| 1251 | */ |
||
| 1252 | public function isFile() |
||
| 1256 | 1 | ||
| 1257 | /** |
||
| 1258 | * Returns the file field name. |
||
| 1259 | * |
||
| 1260 | * @return string $file The file field name. |
||
| 1261 | */ |
||
| 1262 | public function getFile() |
||
| 1266 | |||
| 1267 | 979 | /** |
|
| 1268 | * Set the field name that stores the grid file. |
||
| 1269 | 979 | * |
|
| 1270 | 10 | * @param string $file |
|
| 1271 | */ |
||
| 1272 | 979 | public function setFile($file) |
|
| 1276 | 969 | ||
| 1277 | /** |
||
| 1278 | 979 | * Returns the distance field name. |
|
| 1279 | 1 | * |
|
| 1280 | * @return string $distance The distance field name. |
||
| 1281 | 978 | */ |
|
| 1282 | public function getDistance() |
||
| 1286 | |||
| 1287 | 977 | /** |
|
| 1288 | 627 | * Set the field name that stores the distance. |
|
| 1289 | * |
||
| 1290 | 977 | * @param string $distance |
|
| 1291 | 65 | */ |
|
| 1292 | 63 | public function setDistance($distance) |
|
| 1296 | 977 | ||
| 1297 | 65 | /** |
|
| 1298 | 65 | * Map a field. |
|
| 1299 | 1 | * |
|
| 1300 | * @param array $mapping The mapping information. |
||
| 1301 | * |
||
| 1302 | * @return array |
||
| 1303 | 976 | * |
|
| 1304 | 129 | * @throws MappingException |
|
| 1305 | 129 | */ |
|
| 1306 | 129 | public function mapField(array $mapping) |
|
| 1500 | |||
| 1501 | /** |
||
| 1502 | 929 | * Validates the storage strategy of a mapping for consistency |
|
| 1503 | * @param array $mapping |
||
| 1504 | * @throws \Doctrine\ODM\MongoDB\Mapping\MappingException |
||
| 1505 | */ |
||
| 1506 | 929 | private function applyStorageStrategy(array &$mapping) |
|
| 1550 | |||
| 1551 | /** |
||
| 1552 | * Map a MongoGridFSFile. |
||
| 1553 | 8 | * |
|
| 1554 | * @param array $mapping The mapping information. |
||
| 1555 | 8 | */ |
|
| 1556 | 8 | public function mapFile(array $mapping) |
|
| 1562 | |||
| 1563 | /** |
||
| 1564 | * Map a single embedded document. |
||
| 1565 | 8 | * |
|
| 1566 | * @param array $mapping The mapping information. |
||
| 1567 | 8 | */ |
|
| 1568 | 8 | public function mapOneEmbedded(array $mapping) |
|
| 1574 | |||
| 1575 | /** |
||
| 1576 | * Map a collection of embedded documents. |
||
| 1577 | * |
||
| 1578 | * @param array $mapping The mapping information. |
||
| 1579 | 129 | */ |
|
| 1580 | public function mapManyEmbedded(array $mapping) |
||
| 1586 | 129 | ||
| 1587 | /** |
||
| 1588 | * Map a single document reference. |
||
| 1589 | * |
||
| 1590 | * @param array $mapping The mapping information. |
||
| 1591 | */ |
||
| 1592 | public function mapOneReference(array $mapping) |
||
| 1598 | |||
| 1599 | 78 | /** |
|
| 1600 | * Map a collection of document references. |
||
| 1601 | 78 | * |
|
| 1602 | 78 | * @param array $mapping The mapping information. |
|
| 1603 | */ |
||
| 1604 | public function mapManyReference(array $mapping) |
||
| 1610 | 17 | ||
| 1611 | /** |
||
| 1612 | 17 | * INTERNAL: |
|
| 1613 | * Adds a field mapping without completing/validating it. |
||
| 1614 | * This is mainly used to add inherited field mappings to derived classes. |
||
| 1615 | * |
||
| 1616 | * @param array $fieldMapping |
||
| 1617 | */ |
||
| 1618 | public function addInheritedFieldMapping(array $fieldMapping) |
||
| 1626 | |||
| 1627 | /** |
||
| 1628 | * INTERNAL: |
||
| 1629 | * Adds an association mapping without completing/validating it. |
||
| 1630 | * This is mainly used to add inherited association mappings to derived classes. |
||
| 1631 | 7 | * |
|
| 1632 | * @param array $mapping |
||
| 1633 | 7 | * |
|
| 1634 | * @return void |
||
| 1635 | * |
||
| 1636 | * @throws MappingException |
||
| 1637 | */ |
||
| 1638 | public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/) |
||
| 1642 | |||
| 1643 | /** |
||
| 1644 | * Checks whether the class has a mapped association with the given field name. |
||
| 1645 | * |
||
| 1646 | * @param string $fieldName |
||
| 1647 | * @return boolean |
||
| 1648 | */ |
||
| 1649 | public function hasReference($fieldName) |
||
| 1653 | |||
| 1654 | /** |
||
| 1655 | * Checks whether the class has a mapped embed with the given field name. |
||
| 1656 | * |
||
| 1657 | * @param string $fieldName |
||
| 1658 | * @return boolean |
||
| 1659 | */ |
||
| 1660 | public function hasEmbed($fieldName) |
||
| 1664 | |||
| 1665 | /** |
||
| 1666 | * {@inheritDoc} |
||
| 1667 | * |
||
| 1668 | * Checks whether the class has a mapped association (embed or reference) with the given field name. |
||
| 1669 | */ |
||
| 1670 | public function hasAssociation($fieldName) |
||
| 1674 | |||
| 1675 | /** |
||
| 1676 | * {@inheritDoc} |
||
| 1677 | * |
||
| 1678 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1679 | * is a single valued association. |
||
| 1680 | */ |
||
| 1681 | public function isSingleValuedAssociation($fieldName) |
||
| 1685 | |||
| 1686 | /** |
||
| 1687 | * {@inheritDoc} |
||
| 1688 | * |
||
| 1689 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1690 | * is a collection valued association. |
||
| 1691 | */ |
||
| 1692 | public function isCollectionValuedAssociation($fieldName) |
||
| 1696 | |||
| 1697 | /** |
||
| 1698 | * Checks whether the class has a mapped association for the specified field |
||
| 1699 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1700 | * |
||
| 1701 | * @param string $fieldName |
||
| 1702 | * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1703 | */ |
||
| 1704 | public function isSingleValuedReference($fieldName) |
||
| 1709 | |||
| 1710 | /** |
||
| 1711 | * Checks whether the class has a mapped association for the specified field |
||
| 1712 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1713 | * |
||
| 1714 | * @param string $fieldName |
||
| 1715 | 868 | * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. |
|
| 1716 | */ |
||
| 1717 | 868 | public function isCollectionValuedReference($fieldName) |
|
| 1722 | |||
| 1723 | /** |
||
| 1724 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1725 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1726 | 665 | * |
|
| 1727 | * @param string $fieldName |
||
| 1728 | 665 | * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. |
|
| 1729 | 665 | */ |
|
| 1730 | public function isSingleValuedEmbed($fieldName) |
||
| 1735 | |||
| 1736 | /** |
||
| 1737 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1738 | 737 | * and if yes, checks whether it is a collection-valued association (to-many). |
|
| 1739 | * |
||
| 1740 | 737 | * @param string $fieldName |
|
| 1741 | 737 | * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. |
|
| 1742 | */ |
||
| 1743 | public function isCollectionValuedEmbed($fieldName) |
||
| 1748 | |||
| 1749 | /** |
||
| 1750 | * Sets the ID generator used to generate IDs for instances of this class. |
||
| 1751 | * |
||
| 1752 | 591 | * @param \Doctrine\ODM\MongoDB\Id\AbstractIdGenerator $generator |
|
| 1753 | */ |
||
| 1754 | 591 | public function setIdGenerator($generator) |
|
| 1758 | |||
| 1759 | /** |
||
| 1760 | * Casts the identifier to its portable PHP type. |
||
| 1761 | * |
||
| 1762 | * @param mixed $id |
||
| 1763 | * @return mixed $id |
||
| 1764 | 682 | */ |
|
| 1765 | public function getPHPIdentifierValue($id) |
||
| 1770 | |||
| 1771 | /** |
||
| 1772 | * Casts the identifier to its database type. |
||
| 1773 | * |
||
| 1774 | * @param mixed $id |
||
| 1775 | * @return mixed $id |
||
| 1776 | */ |
||
| 1777 | public function getDatabaseIdentifierValue($id) |
||
| 1782 | |||
| 1783 | /** |
||
| 1784 | * Sets the document identifier of a document. |
||
| 1785 | * |
||
| 1786 | * The value will be converted to a PHP type before being set. |
||
| 1787 | * |
||
| 1788 | 36 | * @param object $document |
|
| 1789 | * @param mixed $id |
||
| 1790 | 36 | */ |
|
| 1791 | public function setIdentifierValue($document, $id) |
||
| 1796 | |||
| 1797 | /** |
||
| 1798 | * Gets the document identifier as a PHP type. |
||
| 1799 | * |
||
| 1800 | 11 | * @param object $document |
|
| 1801 | * @return mixed $id |
||
| 1802 | 11 | */ |
|
| 1803 | public function getIdentifierValue($document) |
||
| 1807 | |||
| 1808 | 11 | /** |
|
| 1809 | 11 | * {@inheritDoc} |
|
| 1810 | * |
||
| 1811 | * Since MongoDB only allows exactly one identifier field this is a proxy |
||
| 1812 | * to {@see getIdentifierValue()} and returns an array with the identifier |
||
| 1813 | * field as a key. |
||
| 1814 | */ |
||
| 1815 | public function getIdentifierValues($object) |
||
| 1819 | 31 | ||
| 1820 | /** |
||
| 1821 | 31 | * Get the document identifier object as a database type. |
|
| 1822 | 1 | * |
|
| 1823 | * @param object $document |
||
| 1824 | * |
||
| 1825 | 31 | * @return \MongoId $id The MongoID object. |
|
| 1826 | */ |
||
| 1827 | public function getIdentifierObject($document) |
||
| 1831 | |||
| 1832 | /** |
||
| 1833 | * Sets the specified field to the specified value on the given document. |
||
| 1834 | * |
||
| 1835 | * @param object $document |
||
| 1836 | * @param string $field |
||
| 1837 | 201 | * @param mixed $value |
|
| 1838 | */ |
||
| 1839 | 201 | public function setFieldValue($document, $field, $value) |
|
| 1849 | |||
| 1850 | 634 | /** |
|
| 1851 | * Gets the specified field's value off the given document. |
||
| 1852 | 634 | * |
|
| 1853 | 634 | * @param object $document |
|
| 1854 | * @param string $field |
||
| 1855 | * |
||
| 1856 | * @return mixed |
||
| 1857 | */ |
||
| 1858 | public function getFieldValue($document, $field) |
||
| 1866 | |||
| 1867 | 9 | /** |
|
| 1868 | * Gets the mapping of a field. |
||
| 1869 | 9 | * |
|
| 1870 | 9 | * @param string $fieldName The field name. |
|
| 1871 | 9 | * |
|
| 1872 | * @return array The field mapping. |
||
| 1873 | * |
||
| 1874 | * @throws MappingException if the $fieldName is not found in the fieldMappings array |
||
| 1875 | */ |
||
| 1876 | public function getFieldMapping($fieldName) |
||
| 1883 | |||
| 1884 | /** |
||
| 1885 | 1 | * Gets mappings of fields holding embedded document(s). |
|
| 1886 | * |
||
| 1887 | 1 | * @return array of field mappings |
|
| 1888 | 1 | */ |
|
| 1889 | 1 | public function getEmbeddedFieldsMappings() |
|
| 1896 | |||
| 1897 | /** |
||
| 1898 | * Gets the field mapping by its DB name. |
||
| 1899 | 539 | * E.g. it returns identifier's mapping when called with _id. |
|
| 1900 | * |
||
| 1901 | 539 | * @param string $dbFieldName |
|
| 1902 | * |
||
| 1903 | * @return array |
||
| 1904 | * @throws MappingException |
||
| 1905 | */ |
||
| 1906 | public function getFieldMappingByDbFieldName($dbFieldName) |
||
| 1916 | |||
| 1917 | /** |
||
| 1918 | * Check if the field is not null. |
||
| 1919 | * |
||
| 1920 | * @param string $fieldName The field name |
||
| 1921 | * |
||
| 1922 | * @return boolean TRUE if the field is not null, FALSE otherwise. |
||
| 1923 | */ |
||
| 1924 | public function isNullable($fieldName) |
||
| 1932 | |||
| 1933 | /** |
||
| 1934 | * Checks whether the document has a discriminator field and value configured. |
||
| 1935 | * |
||
| 1936 | * @return boolean |
||
| 1937 | 372 | */ |
|
| 1938 | public function hasDiscriminator() |
||
| 1942 | |||
| 1943 | /** |
||
| 1944 | * Sets the type of Id generator to use for the mapped class. |
||
| 1945 | * |
||
| 1946 | * @param string $generatorType Generator type. |
||
| 1947 | */ |
||
| 1948 | public function setIdGeneratorType($generatorType) |
||
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Sets the Id generator options. |
||
| 1955 | * |
||
| 1956 | * @param array $generatorOptions Generator options. |
||
| 1957 | 2 | */ |
|
| 1958 | public function setIdGeneratorOptions($generatorOptions) |
||
| 1962 | |||
| 1963 | 2 | /** |
|
| 1964 | * @return boolean |
||
| 1965 | */ |
||
| 1966 | 2 | public function isInheritanceTypeNone() |
|
| 1970 | |||
| 1971 | /** |
||
| 1972 | * Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy. |
||
| 1973 | * |
||
| 1974 | * @return boolean |
||
| 1975 | 926 | */ |
|
| 1976 | public function isInheritanceTypeSingleCollection() |
||
| 1980 | 113 | ||
| 1981 | /** |
||
| 1982 | 926 | * Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy. |
|
| 1983 | * |
||
| 1984 | * @return boolean |
||
| 1985 | */ |
||
| 1986 | public function isInheritanceTypeCollectionPerClass() |
||
| 1990 | |||
| 1991 | /** |
||
| 1992 | * Sets the mapped subclasses of this class. |
||
| 1993 | * |
||
| 1994 | * @param string[] $subclasses The names of all mapped subclasses. |
||
| 1995 | */ |
||
| 1996 | public function setSubclasses(array $subclasses) |
||
| 2006 | |||
| 2007 | /** |
||
| 2008 | * Sets the parent class names. |
||
| 2009 | * Assumes that the class names in the passed array are in the order: |
||
| 2010 | * directParent -> directParentParent -> directParentParentParent ... -> root. |
||
| 2011 | * |
||
| 2012 | * @param string[] $classNames |
||
| 2013 | */ |
||
| 2014 | public function setParentClasses(array $classNames) |
||
| 2022 | |||
| 2023 | /** |
||
| 2024 | * Checks whether the class will generate a new \MongoId instance for us. |
||
| 2025 | * |
||
| 2026 | * @return boolean TRUE if the class uses the AUTO generator, FALSE otherwise. |
||
| 2027 | */ |
||
| 2028 | public function isIdGeneratorAuto() |
||
| 2032 | 102 | ||
| 2033 | /** |
||
| 2034 | 102 | * Checks whether the class will use a collection to generate incremented identifiers. |
|
| 2035 | 1 | * |
|
| 2036 | * @return boolean TRUE if the class uses the INCREMENT generator, FALSE otherwise. |
||
| 2037 | */ |
||
| 2038 | 101 | public function isIdGeneratorIncrement() |
|
| 2042 | |||
| 2043 | /** |
||
| 2044 | * Checks whether the class will generate a uuid id. |
||
| 2045 | * |
||
| 2046 | * @return boolean TRUE if the class uses the UUID generator, FALSE otherwise. |
||
| 2047 | 373 | */ |
|
| 2048 | public function isIdGeneratorUuid() |
||
| 2052 | |||
| 2053 | /** |
||
| 2054 | * Checks whether the class uses no id generator. |
||
| 2055 | * |
||
| 2056 | * @return boolean TRUE if the class does not use any id generator, FALSE otherwise. |
||
| 2057 | */ |
||
| 2058 | 373 | public function isIdGeneratorNone() |
|
| 2062 | |||
| 2063 | /** |
||
| 2064 | * Sets the version field mapping used for versioning. Sets the default |
||
| 2065 | * value to use depending on the column type. |
||
| 2066 | * |
||
| 2067 | * @param array $mapping The version field mapping array |
||
| 2068 | * |
||
| 2069 | * @throws LockException |
||
| 2070 | */ |
||
| 2071 | 27 | public function setVersionMapping(array &$mapping) |
|
| 2080 | |||
| 2081 | /** |
||
| 2082 | * Sets whether this class is to be versioned for optimistic locking. |
||
| 2083 | * |
||
| 2084 | * @param boolean $bool |
||
| 2085 | */ |
||
| 2086 | public function setVersioned($bool) |
||
| 2090 | |||
| 2091 | /** |
||
| 2092 | * Sets the name of the field that is to be used for versioning if this class is |
||
| 2093 | * versioned for optimistic locking. |
||
| 2094 | * |
||
| 2095 | * @param string $versionField |
||
| 2096 | */ |
||
| 2097 | public function setVersionField($versionField) |
||
| 2101 | |||
| 2102 | /** |
||
| 2103 | * Sets the version field mapping used for versioning. Sets the default |
||
| 2104 | * value to use depending on the column type. |
||
| 2105 | 9 | * |
|
| 2106 | * @param array $mapping The version field mapping array |
||
| 2107 | 9 | * |
|
| 2108 | 9 | * @throws \Doctrine\ODM\MongoDB\LockException |
|
| 2109 | */ |
||
| 2110 | public function setLockMapping(array &$mapping) |
||
| 2119 | |||
| 2120 | /** |
||
| 2121 | * Sets whether this class is to allow pessimistic locking. |
||
| 2122 | * |
||
| 2123 | * @param boolean $bool |
||
| 2124 | */ |
||
| 2125 | public function setLockable($bool) |
||
| 2129 | 22 | ||
| 2130 | /** |
||
| 2131 | 22 | * Sets the name of the field that is to be used for storing whether a document |
|
| 2132 | 22 | * is currently locked or not. |
|
| 2133 | * |
||
| 2134 | * @param string $lockField |
||
| 2135 | */ |
||
| 2136 | public function setLockField($lockField) |
||
| 2140 | 6 | ||
| 2141 | 3 | /** |
|
| 2142 | * Marks this class as read only, no change tracking is applied to it. |
||
| 2143 | */ |
||
| 2144 | 3 | public function markReadOnly() |
|
| 2148 | |||
| 2149 | /** |
||
| 2150 | * {@inheritDoc} |
||
| 2151 | */ |
||
| 2152 | 2 | public function getFieldNames() |
|
| 2156 | |||
| 2157 | /** |
||
| 2158 | 2 | * {@inheritDoc} |
|
| 2159 | */ |
||
| 2160 | public function getAssociationNames() |
||
| 2164 | |||
| 2165 | /** |
||
| 2166 | * {@inheritDoc} |
||
| 2167 | */ |
||
| 2168 | public function getTypeOfField($fieldName) |
||
| 2173 | |||
| 2174 | /** |
||
| 2175 | * {@inheritDoc} |
||
| 2176 | */ |
||
| 2177 | public function getAssociationTargetClass($assocName) |
||
| 2185 | |||
| 2186 | /** |
||
| 2187 | * Retrieve the collectionClass associated with an association |
||
| 2188 | * |
||
| 2189 | * @param string $assocName |
||
| 2190 | */ |
||
| 2191 | public function getAssociationCollectionClass($assocName) |
||
| 2203 | |||
| 2204 | /** |
||
| 2205 | * {@inheritDoc} |
||
| 2206 | */ |
||
| 2207 | public function isAssociationInverseSide($fieldName) |
||
| 2211 | |||
| 2212 | /** |
||
| 2213 | * {@inheritDoc} |
||
| 2214 | */ |
||
| 2215 | public function getAssociationMappedByTargetField($fieldName) |
||
| 2219 | } |
||
| 2220 |
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: