Complex classes like ClassMetadata often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ClassMetadata, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 53 | class ClassMetadata implements BaseClassMetadata |
||
| 54 | { |
||
| 55 | /* The Id generator types. */ |
||
| 56 | /** |
||
| 57 | * AUTO means Doctrine will automatically create a new \MongoDB\BSON\ObjectId instance for us. |
||
| 58 | */ |
||
| 59 | public const GENERATOR_TYPE_AUTO = 1; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * INCREMENT means a separate collection is used for maintaining and incrementing id generation. |
||
| 63 | * Offers full portability. |
||
| 64 | */ |
||
| 65 | public const GENERATOR_TYPE_INCREMENT = 2; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * UUID means Doctrine will generate a uuid for us. |
||
| 69 | */ |
||
| 70 | public const GENERATOR_TYPE_UUID = 3; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * ALNUM means Doctrine will generate Alpha-numeric string identifiers, using the INCREMENT |
||
| 74 | * generator to ensure identifier uniqueness |
||
| 75 | */ |
||
| 76 | public const GENERATOR_TYPE_ALNUM = 4; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * CUSTOM means Doctrine expect a class parameter. It will then try to initiate that class |
||
| 80 | * and pass other options to the generator. It will throw an Exception if the class |
||
| 81 | * does not exist or if an option was passed for that there is not setter in the new |
||
| 82 | * generator class. |
||
| 83 | * |
||
| 84 | * The class will have to be a subtype of AbstractIdGenerator. |
||
| 85 | */ |
||
| 86 | public const GENERATOR_TYPE_CUSTOM = 5; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * NONE means Doctrine will not generate any id for us and you are responsible for manually |
||
| 90 | * assigning an id. |
||
| 91 | */ |
||
| 92 | public const GENERATOR_TYPE_NONE = 6; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Default discriminator field name. |
||
| 96 | * |
||
| 97 | * This is used for associations value for associations where a that do not define a "targetDocument" or |
||
| 98 | * "discriminatorField" option in their mapping. |
||
| 99 | */ |
||
| 100 | public const DEFAULT_DISCRIMINATOR_FIELD = '_doctrine_class_name'; |
||
| 101 | |||
| 102 | public const REFERENCE_ONE = 1; |
||
| 103 | public const REFERENCE_MANY = 2; |
||
| 104 | public const EMBED_ONE = 3; |
||
| 105 | public const EMBED_MANY = 4; |
||
| 106 | public const MANY = 'many'; |
||
| 107 | public const ONE = 'one'; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * The types of storeAs references |
||
| 111 | */ |
||
| 112 | public const REFERENCE_STORE_AS_ID = 'id'; |
||
| 113 | public const REFERENCE_STORE_AS_DB_REF = 'dbRef'; |
||
| 114 | public const REFERENCE_STORE_AS_DB_REF_WITH_DB = 'dbRefWithDb'; |
||
| 115 | public const REFERENCE_STORE_AS_REF = 'ref'; |
||
| 116 | |||
| 117 | /* The inheritance mapping types */ |
||
| 118 | /** |
||
| 119 | * NONE means the class does not participate in an inheritance hierarchy |
||
| 120 | * and therefore does not need an inheritance mapping type. |
||
| 121 | */ |
||
| 122 | public const INHERITANCE_TYPE_NONE = 1; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * SINGLE_COLLECTION means the class will be persisted according to the rules of |
||
| 126 | * <tt>Single Collection Inheritance</tt>. |
||
| 127 | */ |
||
| 128 | public const INHERITANCE_TYPE_SINGLE_COLLECTION = 2; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * COLLECTION_PER_CLASS means the class will be persisted according to the rules |
||
| 132 | * of <tt>Concrete Collection Inheritance</tt>. |
||
| 133 | */ |
||
| 134 | public const INHERITANCE_TYPE_COLLECTION_PER_CLASS = 3; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * DEFERRED_IMPLICIT 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 for all entities that are in MANAGED state at commit-time. |
||
| 140 | * |
||
| 141 | * This is the default change tracking policy. |
||
| 142 | */ |
||
| 143 | public const CHANGETRACKING_DEFERRED_IMPLICIT = 1; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time |
||
| 147 | * by doing a property-by-property comparison with the original data. This will |
||
| 148 | * be done only for entities that were explicitly saved (through persist() or a cascade). |
||
| 149 | */ |
||
| 150 | public const CHANGETRACKING_DEFERRED_EXPLICIT = 2; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * NOTIFY means that Doctrine relies on the entities sending out notifications |
||
| 154 | * when their properties change. Such entity classes must implement |
||
| 155 | * the <tt>NotifyPropertyChanged</tt> interface. |
||
| 156 | */ |
||
| 157 | public const CHANGETRACKING_NOTIFY = 3; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * SET means that fields will be written to the database using a $set operator |
||
| 161 | */ |
||
| 162 | public const STORAGE_STRATEGY_SET = 'set'; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * INCREMENT means that fields will be written to the database by calculating |
||
| 166 | * the difference and using the $inc operator |
||
| 167 | */ |
||
| 168 | public const STORAGE_STRATEGY_INCREMENT = 'increment'; |
||
| 169 | |||
| 170 | public const STORAGE_STRATEGY_PUSH_ALL = 'pushAll'; |
||
| 171 | public const STORAGE_STRATEGY_ADD_TO_SET = 'addToSet'; |
||
| 172 | public const STORAGE_STRATEGY_ATOMIC_SET = 'atomicSet'; |
||
| 173 | public const STORAGE_STRATEGY_ATOMIC_SET_ARRAY = 'atomicSetArray'; |
||
| 174 | public const STORAGE_STRATEGY_SET_ARRAY = 'setArray'; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * READ-ONLY: The name of the mongo database the document is mapped to. |
||
| 178 | */ |
||
| 179 | public $db; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * READ-ONLY: The name of the mongo collection the document is mapped to. |
||
| 183 | */ |
||
| 184 | public $collection; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * READ-ONLY: If the collection should be a fixed size. |
||
| 188 | */ |
||
| 189 | public $collectionCapped; |
||
| 190 | |||
| 191 | /** |
||
| 192 | * READ-ONLY: If the collection is fixed size, its size in bytes. |
||
| 193 | */ |
||
| 194 | public $collectionSize; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * READ-ONLY: If the collection is fixed size, the maximum number of elements to store in the collection. |
||
| 198 | */ |
||
| 199 | public $collectionMax; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set. |
||
| 203 | */ |
||
| 204 | public $readPreference; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * READ-ONLY Associated with readPreference Allows to specify criteria so that your application can target read |
||
| 208 | * operations to specific members, based on custom parameters. |
||
| 209 | */ |
||
| 210 | public $readPreferenceTags; |
||
| 211 | |||
| 212 | /** |
||
| 213 | * READ-ONLY: Describes the level of acknowledgement requested from MongoDB for write operations. |
||
| 214 | */ |
||
| 215 | public $writeConcern; |
||
| 216 | |||
| 217 | /** |
||
| 218 | * READ-ONLY: The field name of the document identifier. |
||
| 219 | */ |
||
| 220 | public $identifier; |
||
| 221 | |||
| 222 | /** |
||
| 223 | * READ-ONLY: The array of indexes for the document collection. |
||
| 224 | */ |
||
| 225 | public $indexes = []; |
||
| 226 | |||
| 227 | /** |
||
| 228 | * READ-ONLY: Keys and options describing shard key. Only for sharded collections. |
||
| 229 | */ |
||
| 230 | public $shardKey; |
||
| 231 | |||
| 232 | /** |
||
| 233 | * READ-ONLY: The name of the document class. |
||
| 234 | */ |
||
| 235 | public $name; |
||
| 236 | |||
| 237 | /** |
||
| 238 | * READ-ONLY: The namespace the document class is contained in. |
||
| 239 | * |
||
| 240 | * @var string |
||
| 241 | * @todo Not really needed. Usage could be localized. |
||
| 242 | */ |
||
| 243 | public $namespace; |
||
| 244 | |||
| 245 | /** |
||
| 246 | * READ-ONLY: The name of the document class that is at the root of the mapped document inheritance |
||
| 247 | * hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same |
||
| 248 | * as {@link $documentName}. |
||
| 249 | * |
||
| 250 | * @var string |
||
| 251 | */ |
||
| 252 | public $rootDocumentName; |
||
| 253 | |||
| 254 | /** |
||
| 255 | * The name of the custom repository class used for the document class. |
||
| 256 | * (Optional). |
||
| 257 | * |
||
| 258 | * @var string |
||
| 259 | */ |
||
| 260 | public $customRepositoryClassName; |
||
| 261 | |||
| 262 | /** |
||
| 263 | * READ-ONLY: The names of the parent classes (ancestors). |
||
| 264 | * |
||
| 265 | * @var array |
||
| 266 | */ |
||
| 267 | public $parentClasses = []; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * READ-ONLY: The names of all subclasses (descendants). |
||
| 271 | * |
||
| 272 | * @var array |
||
| 273 | */ |
||
| 274 | public $subClasses = []; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * The ReflectionProperty instances of the mapped class. |
||
| 278 | * |
||
| 279 | * @var \ReflectionProperty[] |
||
| 280 | */ |
||
| 281 | public $reflFields = []; |
||
| 282 | |||
| 283 | /** |
||
| 284 | * READ-ONLY: The inheritance mapping type used by the class. |
||
| 285 | * |
||
| 286 | * @var int |
||
| 287 | */ |
||
| 288 | public $inheritanceType = self::INHERITANCE_TYPE_NONE; |
||
| 289 | |||
| 290 | /** |
||
| 291 | * READ-ONLY: The Id generator type used by the class. |
||
| 292 | * |
||
| 293 | * @var string |
||
| 294 | */ |
||
| 295 | public $generatorType = self::GENERATOR_TYPE_AUTO; |
||
| 296 | |||
| 297 | /** |
||
| 298 | * READ-ONLY: The Id generator options. |
||
| 299 | * |
||
| 300 | * @var array |
||
| 301 | */ |
||
| 302 | public $generatorOptions = []; |
||
| 303 | |||
| 304 | /** |
||
| 305 | * READ-ONLY: The ID generator used for generating IDs for this class. |
||
| 306 | * |
||
| 307 | * @var AbstractIdGenerator |
||
| 308 | */ |
||
| 309 | public $idGenerator; |
||
| 310 | |||
| 311 | /** |
||
| 312 | * READ-ONLY: The field mappings of the class. |
||
| 313 | * Keys are field names and values are mapping definitions. |
||
| 314 | * |
||
| 315 | * The mapping definition array has the following values: |
||
| 316 | * |
||
| 317 | * - <b>fieldName</b> (string) |
||
| 318 | * The name of the field in the Document. |
||
| 319 | * |
||
| 320 | * - <b>id</b> (boolean, optional) |
||
| 321 | * Marks the field as the primary key of the document. Multiple fields of an |
||
| 322 | * document can have the id attribute, forming a composite key. |
||
| 323 | * |
||
| 324 | * @var array |
||
| 325 | */ |
||
| 326 | public $fieldMappings = []; |
||
| 327 | |||
| 328 | /** |
||
| 329 | * READ-ONLY: The association mappings of the class. |
||
| 330 | * Keys are field names and values are mapping definitions. |
||
| 331 | * |
||
| 332 | * @var array |
||
| 333 | */ |
||
| 334 | public $associationMappings = []; |
||
| 335 | |||
| 336 | /** |
||
| 337 | * READ-ONLY: Array of fields to also load with a given method. |
||
| 338 | * |
||
| 339 | * @var array |
||
| 340 | */ |
||
| 341 | public $alsoLoadMethods = []; |
||
| 342 | |||
| 343 | /** |
||
| 344 | * READ-ONLY: The registered lifecycle callbacks for documents of this class. |
||
| 345 | * |
||
| 346 | * @var array |
||
| 347 | */ |
||
| 348 | public $lifecycleCallbacks = []; |
||
| 349 | |||
| 350 | /** |
||
| 351 | * READ-ONLY: The discriminator value of this class. |
||
| 352 | * |
||
| 353 | * <b>This does only apply to the JOINED and SINGLE_COLLECTION inheritance mapping strategies |
||
| 354 | * where a discriminator field is used.</b> |
||
| 355 | * |
||
| 356 | * @var mixed |
||
| 357 | * @see discriminatorField |
||
| 358 | */ |
||
| 359 | public $discriminatorValue; |
||
| 360 | |||
| 361 | /** |
||
| 362 | * READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
||
| 363 | * |
||
| 364 | * <b>This does only apply to the SINGLE_COLLECTION inheritance mapping strategy |
||
| 365 | * where a discriminator field is used.</b> |
||
| 366 | * |
||
| 367 | * @var mixed |
||
| 368 | * @see discriminatorField |
||
| 369 | */ |
||
| 370 | public $discriminatorMap = []; |
||
| 371 | |||
| 372 | /** |
||
| 373 | * READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION |
||
| 374 | * inheritance mapping. |
||
| 375 | * |
||
| 376 | * @var string |
||
| 377 | */ |
||
| 378 | public $discriminatorField; |
||
| 379 | |||
| 380 | /** |
||
| 381 | * READ-ONLY: The default value for discriminatorField in case it's not set in the document |
||
| 382 | * |
||
| 383 | * @var string |
||
| 384 | * @see discriminatorField |
||
| 385 | */ |
||
| 386 | public $defaultDiscriminatorValue; |
||
| 387 | |||
| 388 | /** |
||
| 389 | * READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
||
| 390 | * |
||
| 391 | * @var bool |
||
| 392 | */ |
||
| 393 | public $isMappedSuperclass = false; |
||
| 394 | |||
| 395 | /** |
||
| 396 | * READ-ONLY: Whether this class describes the mapping of a embedded document. |
||
| 397 | * |
||
| 398 | * @var bool |
||
| 399 | */ |
||
| 400 | public $isEmbeddedDocument = false; |
||
| 401 | |||
| 402 | /** |
||
| 403 | * READ-ONLY: Whether this class describes the mapping of an aggregation result document. |
||
| 404 | * |
||
| 405 | * @var bool |
||
| 406 | */ |
||
| 407 | public $isQueryResultDocument = false; |
||
| 408 | |||
| 409 | /** |
||
| 410 | * READ-ONLY: The policy used for change-tracking on entities of this class. |
||
| 411 | * |
||
| 412 | * @var int |
||
| 413 | */ |
||
| 414 | public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT; |
||
| 415 | |||
| 416 | /** |
||
| 417 | * READ-ONLY: A flag for whether or not instances of this class are to be versioned |
||
| 418 | * with optimistic locking. |
||
| 419 | * |
||
| 420 | * @var bool $isVersioned |
||
| 421 | */ |
||
| 422 | public $isVersioned; |
||
| 423 | |||
| 424 | /** |
||
| 425 | * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). |
||
| 426 | * |
||
| 427 | * @var mixed $versionField |
||
| 428 | */ |
||
| 429 | public $versionField; |
||
| 430 | |||
| 431 | /** |
||
| 432 | * READ-ONLY: A flag for whether or not instances of this class are to allow pessimistic |
||
| 433 | * locking. |
||
| 434 | * |
||
| 435 | * @var bool $isLockable |
||
| 436 | */ |
||
| 437 | public $isLockable; |
||
| 438 | |||
| 439 | /** |
||
| 440 | * READ-ONLY: The name of the field which is used for locking a document. |
||
| 441 | * |
||
| 442 | * @var mixed $lockField |
||
| 443 | */ |
||
| 444 | public $lockField; |
||
| 445 | |||
| 446 | /** |
||
| 447 | * The ReflectionClass instance of the mapped class. |
||
| 448 | * |
||
| 449 | * @var \ReflectionClass |
||
| 450 | */ |
||
| 451 | public $reflClass; |
||
| 452 | |||
| 453 | /** |
||
| 454 | * READ_ONLY: A flag for whether or not this document is read-only. |
||
| 455 | * |
||
| 456 | * @var bool |
||
| 457 | */ |
||
| 458 | public $isReadOnly; |
||
| 459 | |||
| 460 | /** @var InstantiatorInterface|null */ |
||
| 461 | private $instantiator; |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Initializes a new ClassMetadata instance that will hold the object-document mapping |
||
| 465 | * metadata of the class with the given name. |
||
| 466 | * |
||
| 467 | * @param string $documentName The name of the document class the new instance is used for. |
||
| 468 | */ |
||
| 469 | 1474 | public function __construct($documentName) |
|
| 470 | { |
||
| 471 | 1474 | $this->name = $documentName; |
|
| 472 | 1474 | $this->rootDocumentName = $documentName; |
|
| 473 | 1474 | $this->reflClass = new \ReflectionClass($documentName); |
|
| 474 | 1474 | $this->namespace = $this->reflClass->getNamespaceName(); |
|
| 475 | 1474 | $this->setCollection($this->reflClass->getShortName()); |
|
| 476 | 1474 | $this->instantiator = new Instantiator(); |
|
|
|
|||
| 477 | 1474 | } |
|
| 478 | |||
| 479 | /** |
||
| 480 | * Helper method to get reference id of ref* type references |
||
| 481 | * @param mixed $reference |
||
| 482 | * @param string $storeAs |
||
| 483 | * @return mixed |
||
| 484 | * @internal |
||
| 485 | */ |
||
| 486 | 120 | public static function getReferenceId($reference, $storeAs) |
|
| 487 | { |
||
| 488 | 120 | return $storeAs === self::REFERENCE_STORE_AS_ID ? $reference : $reference[self::getReferencePrefix($storeAs) . 'id']; |
|
| 489 | } |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Returns the reference prefix used for a reference |
||
| 493 | * @param string $storeAs |
||
| 494 | * @return string |
||
| 495 | */ |
||
| 496 | 185 | private static function getReferencePrefix($storeAs) |
|
| 497 | { |
||
| 498 | 185 | if (! in_array($storeAs, [self::REFERENCE_STORE_AS_REF, self::REFERENCE_STORE_AS_DB_REF, self::REFERENCE_STORE_AS_DB_REF_WITH_DB])) { |
|
| 499 | throw new \LogicException('Can only get a reference prefix for DBRef and reference arrays'); |
||
| 500 | } |
||
| 501 | |||
| 502 | 185 | return $storeAs === self::REFERENCE_STORE_AS_REF ? '' : '$'; |
|
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Returns a fully qualified field name for a given reference |
||
| 507 | * @param string $storeAs |
||
| 508 | * @param string $pathPrefix The field path prefix |
||
| 509 | * @return string |
||
| 510 | * @internal |
||
| 511 | */ |
||
| 512 | 134 | public static function getReferenceFieldName($storeAs, $pathPrefix = '') |
|
| 513 | { |
||
| 514 | 134 | if ($storeAs === self::REFERENCE_STORE_AS_ID) { |
|
| 515 | 94 | return $pathPrefix; |
|
| 516 | } |
||
| 517 | |||
| 518 | 122 | return ($pathPrefix ? $pathPrefix . '.' : '') . static::getReferencePrefix($storeAs) . 'id'; |
|
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * {@inheritDoc} |
||
| 523 | */ |
||
| 524 | 1365 | public function getReflectionClass() |
|
| 525 | { |
||
| 526 | 1365 | if (! $this->reflClass) { |
|
| 527 | $this->reflClass = new \ReflectionClass($this->name); |
||
| 528 | } |
||
| 529 | |||
| 530 | 1365 | return $this->reflClass; |
|
| 531 | } |
||
| 532 | |||
| 533 | /** |
||
| 534 | * {@inheritDoc} |
||
| 535 | */ |
||
| 536 | 321 | public function isIdentifier($fieldName) |
|
| 537 | { |
||
| 538 | 321 | return $this->identifier === $fieldName; |
|
| 539 | } |
||
| 540 | |||
| 541 | /** |
||
| 542 | * INTERNAL: |
||
| 543 | * Sets the mapped identifier field of this class. |
||
| 544 | * |
||
| 545 | * @param string $identifier |
||
| 546 | */ |
||
| 547 | 886 | public function setIdentifier($identifier) |
|
| 548 | { |
||
| 549 | 886 | $this->identifier = $identifier; |
|
| 550 | 886 | } |
|
| 551 | |||
| 552 | /** |
||
| 553 | * {@inheritDoc} |
||
| 554 | * |
||
| 555 | * Since MongoDB only allows exactly one identifier field |
||
| 556 | * this will always return an array with only one value |
||
| 557 | */ |
||
| 558 | 38 | public function getIdentifier() |
|
| 559 | { |
||
| 560 | 38 | return [$this->identifier]; |
|
| 561 | } |
||
| 562 | |||
| 563 | /** |
||
| 564 | * {@inheritDoc} |
||
| 565 | * |
||
| 566 | * Since MongoDB only allows exactly one identifier field |
||
| 567 | * this will always return an array with only one value |
||
| 568 | */ |
||
| 569 | 97 | public function getIdentifierFieldNames() |
|
| 570 | { |
||
| 571 | 97 | return [$this->identifier]; |
|
| 572 | } |
||
| 573 | |||
| 574 | /** |
||
| 575 | * {@inheritDoc} |
||
| 576 | */ |
||
| 577 | 886 | public function hasField($fieldName) |
|
| 578 | { |
||
| 579 | 886 | return isset($this->fieldMappings[$fieldName]); |
|
| 580 | } |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Sets the inheritance type used by the class and it's subclasses. |
||
| 584 | * |
||
| 585 | * @param int $type |
||
| 586 | */ |
||
| 587 | 902 | public function setInheritanceType($type) |
|
| 588 | { |
||
| 589 | 902 | $this->inheritanceType = $type; |
|
| 590 | 902 | } |
|
| 591 | |||
| 592 | /** |
||
| 593 | * Checks whether a mapped field is inherited from an entity superclass. |
||
| 594 | * |
||
| 595 | * @param string $fieldName |
||
| 596 | * |
||
| 597 | * @return bool TRUE if the field is inherited, FALSE otherwise. |
||
| 598 | */ |
||
| 599 | 1361 | public function isInheritedField($fieldName) |
|
| 600 | { |
||
| 601 | 1361 | return isset($this->fieldMappings[$fieldName]['inherited']); |
|
| 602 | } |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Registers a custom repository class for the document class. |
||
| 606 | * |
||
| 607 | * @param string $repositoryClassName The class name of the custom repository. |
||
| 608 | */ |
||
| 609 | 834 | public function setCustomRepositoryClass($repositoryClassName) |
|
| 610 | { |
||
| 611 | 834 | if ($this->isEmbeddedDocument || $this->isQueryResultDocument) { |
|
| 612 | return; |
||
| 613 | } |
||
| 614 | |||
| 615 | 834 | if ($repositoryClassName && strpos($repositoryClassName, '\\') === false && strlen($this->namespace)) { |
|
| 616 | 3 | $repositoryClassName = $this->namespace . '\\' . $repositoryClassName; |
|
| 617 | } |
||
| 618 | |||
| 619 | 834 | $this->customRepositoryClassName = $repositoryClassName; |
|
| 620 | 834 | } |
|
| 621 | |||
| 622 | /** |
||
| 623 | * Dispatches the lifecycle event of the given document by invoking all |
||
| 624 | * registered callbacks. |
||
| 625 | * |
||
| 626 | * @param string $event Lifecycle event |
||
| 627 | * @param object $document Document on which the event occurred |
||
| 628 | * @param array $arguments Arguments to pass to all callbacks |
||
| 629 | * @throws \InvalidArgumentException If document class is not this class or |
||
| 630 | * a Proxy of this class. |
||
| 631 | */ |
||
| 632 | 598 | public function invokeLifecycleCallbacks($event, $document, ?array $arguments = null) |
|
| 633 | { |
||
| 634 | 598 | if (! $document instanceof $this->name) { |
|
| 635 | 1 | throw new \InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, get_class($document))); |
|
| 636 | } |
||
| 637 | |||
| 638 | 597 | if (empty($this->lifecycleCallbacks[$event])) { |
|
| 639 | 582 | return; |
|
| 640 | } |
||
| 641 | |||
| 642 | 176 | foreach ($this->lifecycleCallbacks[$event] as $callback) { |
|
| 643 | 176 | if ($arguments !== null) { |
|
| 644 | 175 | call_user_func_array([$document, $callback], $arguments); |
|
| 645 | } else { |
||
| 646 | 176 | $document->$callback(); |
|
| 647 | } |
||
| 648 | } |
||
| 649 | 176 | } |
|
| 650 | |||
| 651 | /** |
||
| 652 | * Checks whether the class has callbacks registered for a lifecycle event. |
||
| 653 | * |
||
| 654 | * @param string $event Lifecycle event |
||
| 655 | * |
||
| 656 | * @return bool |
||
| 657 | */ |
||
| 658 | public function hasLifecycleCallbacks($event) |
||
| 659 | { |
||
| 660 | return ! empty($this->lifecycleCallbacks[$event]); |
||
| 661 | } |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Gets the registered lifecycle callbacks for an event. |
||
| 665 | * |
||
| 666 | * @param string $event |
||
| 667 | * @return array |
||
| 668 | */ |
||
| 669 | public function getLifecycleCallbacks($event) |
||
| 670 | { |
||
| 671 | return $this->lifecycleCallbacks[$event] ?? []; |
||
| 672 | } |
||
| 673 | |||
| 674 | /** |
||
| 675 | * Adds a lifecycle callback for documents of this class. |
||
| 676 | * |
||
| 677 | * If the callback is already registered, this is a NOOP. |
||
| 678 | * |
||
| 679 | * @param string $callback |
||
| 680 | * @param string $event |
||
| 681 | */ |
||
| 682 | 802 | public function addLifecycleCallback($callback, $event) |
|
| 683 | { |
||
| 684 | 802 | if (isset($this->lifecycleCallbacks[$event]) && in_array($callback, $this->lifecycleCallbacks[$event])) { |
|
| 685 | 1 | return; |
|
| 686 | } |
||
| 687 | |||
| 688 | 802 | $this->lifecycleCallbacks[$event][] = $callback; |
|
| 689 | 802 | } |
|
| 690 | |||
| 691 | /** |
||
| 692 | * Sets the lifecycle callbacks for documents of this class. |
||
| 693 | * |
||
| 694 | * Any previously registered callbacks are overwritten. |
||
| 695 | * |
||
| 696 | * @param array $callbacks |
||
| 697 | */ |
||
| 698 | 885 | public function setLifecycleCallbacks(array $callbacks) |
|
| 699 | { |
||
| 700 | 885 | $this->lifecycleCallbacks = $callbacks; |
|
| 701 | 885 | } |
|
| 702 | |||
| 703 | /** |
||
| 704 | * Registers a method for loading document data before field hydration. |
||
| 705 | * |
||
| 706 | * Note: A method may be registered multiple times for different fields. |
||
| 707 | * it will be invoked only once for the first field found. |
||
| 708 | * |
||
| 709 | * @param string $method Method name |
||
| 710 | * @param array|string $fields Database field name(s) |
||
| 711 | */ |
||
| 712 | 14 | public function registerAlsoLoadMethod($method, $fields) |
|
| 713 | { |
||
| 714 | 14 | $this->alsoLoadMethods[$method] = is_array($fields) ? $fields : [$fields]; |
|
| 715 | 14 | } |
|
| 716 | |||
| 717 | /** |
||
| 718 | * Sets the AlsoLoad methods for documents of this class. |
||
| 719 | * |
||
| 720 | * Any previously registered methods are overwritten. |
||
| 721 | * |
||
| 722 | * @param array $methods |
||
| 723 | */ |
||
| 724 | 885 | public function setAlsoLoadMethods(array $methods) |
|
| 725 | { |
||
| 726 | 885 | $this->alsoLoadMethods = $methods; |
|
| 727 | 885 | } |
|
| 728 | |||
| 729 | /** |
||
| 730 | * Sets the discriminator field. |
||
| 731 | * |
||
| 732 | * The field name is the the unmapped database field. Discriminator values |
||
| 733 | * are only used to discern the hydration class and are not mapped to class |
||
| 734 | * properties. |
||
| 735 | * |
||
| 736 | * @param string $discriminatorField |
||
| 737 | * |
||
| 738 | * @throws MappingException If the discriminator field conflicts with the |
||
| 739 | * "name" attribute of a mapped field. |
||
| 740 | */ |
||
| 741 | 911 | public function setDiscriminatorField($discriminatorField) |
|
| 742 | { |
||
| 743 | 911 | if ($discriminatorField === null) { |
|
| 744 | 843 | $this->discriminatorField = null; |
|
| 745 | |||
| 746 | 843 | return; |
|
| 747 | } |
||
| 748 | |||
| 749 | // Handle array argument with name/fieldName keys for BC |
||
| 750 | 117 | if (is_array($discriminatorField)) { |
|
| 751 | if (isset($discriminatorField['name'])) { |
||
| 752 | $discriminatorField = $discriminatorField['name']; |
||
| 753 | } elseif (isset($discriminatorField['fieldName'])) { |
||
| 754 | $discriminatorField = $discriminatorField['fieldName']; |
||
| 755 | } |
||
| 756 | } |
||
| 757 | |||
| 758 | 117 | foreach ($this->fieldMappings as $fieldMapping) { |
|
| 759 | 4 | if ($discriminatorField === $fieldMapping['name']) { |
|
| 760 | 4 | throw MappingException::discriminatorFieldConflict($this->name, $discriminatorField); |
|
| 761 | } |
||
| 762 | } |
||
| 763 | |||
| 764 | 116 | $this->discriminatorField = $discriminatorField; |
|
| 765 | 116 | } |
|
| 766 | |||
| 767 | /** |
||
| 768 | * Sets the discriminator values used by this class. |
||
| 769 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
||
| 770 | * |
||
| 771 | * @param array $map |
||
| 772 | * |
||
| 773 | * @throws MappingException |
||
| 774 | */ |
||
| 775 | 904 | public function setDiscriminatorMap(array $map) |
|
| 776 | { |
||
| 777 | 904 | foreach ($map as $value => $className) { |
|
| 778 | 112 | if (strpos($className, '\\') === false && strlen($this->namespace)) { |
|
| 779 | 82 | $className = $this->namespace . '\\' . $className; |
|
| 780 | } |
||
| 781 | 112 | $this->discriminatorMap[$value] = $className; |
|
| 782 | 112 | if ($this->name === $className) { |
|
| 783 | 104 | $this->discriminatorValue = $value; |
|
| 784 | } else { |
||
| 785 | 111 | if (! class_exists($className)) { |
|
| 786 | throw MappingException::invalidClassInDiscriminatorMap($className, $this->name); |
||
| 787 | } |
||
| 788 | 111 | if (is_subclass_of($className, $this->name)) { |
|
| 789 | 112 | $this->subClasses[] = $className; |
|
| 790 | } |
||
| 791 | } |
||
| 792 | } |
||
| 793 | 904 | } |
|
| 794 | |||
| 795 | /** |
||
| 796 | * Sets the default discriminator value to be used for this class |
||
| 797 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value |
||
| 798 | * |
||
| 799 | * @param string $defaultDiscriminatorValue |
||
| 800 | * |
||
| 801 | * @throws MappingException |
||
| 802 | */ |
||
| 803 | 888 | public function setDefaultDiscriminatorValue($defaultDiscriminatorValue) |
|
| 804 | { |
||
| 805 | 888 | if ($defaultDiscriminatorValue === null) { |
|
| 806 | 885 | $this->defaultDiscriminatorValue = null; |
|
| 807 | |||
| 808 | 885 | return; |
|
| 809 | } |
||
| 810 | |||
| 811 | 48 | if (! array_key_exists($defaultDiscriminatorValue, $this->discriminatorMap)) { |
|
| 812 | throw MappingException::invalidDiscriminatorValue($defaultDiscriminatorValue, $this->name); |
||
| 813 | } |
||
| 814 | |||
| 815 | 48 | $this->defaultDiscriminatorValue = $defaultDiscriminatorValue; |
|
| 816 | 48 | } |
|
| 817 | |||
| 818 | /** |
||
| 819 | * Sets the discriminator value for this class. |
||
| 820 | * Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single |
||
| 821 | * collection. |
||
| 822 | * |
||
| 823 | * @param string $value |
||
| 824 | */ |
||
| 825 | 3 | public function setDiscriminatorValue($value) |
|
| 826 | { |
||
| 827 | 3 | $this->discriminatorMap[$value] = $this->name; |
|
| 828 | 3 | $this->discriminatorValue = $value; |
|
| 829 | 3 | } |
|
| 830 | |||
| 831 | /** |
||
| 832 | * Add a index for this Document. |
||
| 833 | * |
||
| 834 | * @param array $keys Array of keys for the index. |
||
| 835 | * @param array $options Array of options for the index. |
||
| 836 | */ |
||
| 837 | 183 | public function addIndex($keys, array $options = []) |
|
| 838 | { |
||
| 839 | 183 | $this->indexes[] = [ |
|
| 840 | 183 | 'keys' => array_map(function ($value) { |
|
| 841 | 183 | if ($value === 1 || $value === -1) { |
|
| 842 | 45 | return (int) $value; |
|
| 843 | } |
||
| 844 | 183 | if (is_string($value)) { |
|
| 845 | 183 | $lower = strtolower($value); |
|
| 846 | 183 | if ($lower === 'asc') { |
|
| 847 | 176 | return 1; |
|
| 848 | } |
||
| 849 | |||
| 850 | 52 | if ($lower === 'desc') { |
|
| 851 | return -1; |
||
| 852 | } |
||
| 853 | } |
||
| 854 | 52 | return $value; |
|
| 855 | 183 | }, $keys), |
|
| 856 | 183 | 'options' => $options, |
|
| 857 | ]; |
||
| 858 | 183 | } |
|
| 859 | |||
| 860 | /** |
||
| 861 | * Returns the array of indexes for this Document. |
||
| 862 | * |
||
| 863 | * @return array $indexes The array of indexes. |
||
| 864 | */ |
||
| 865 | 23 | public function getIndexes() |
|
| 869 | |||
| 870 | /** |
||
| 871 | * Checks whether this document has indexes or not. |
||
| 872 | * |
||
| 873 | * @return bool |
||
| 874 | */ |
||
| 875 | public function hasIndexes() |
||
| 879 | |||
| 880 | /** |
||
| 881 | * Set shard key for this Document. |
||
| 882 | * |
||
| 883 | * @param array $keys Array of document keys. |
||
| 884 | * @param array $options Array of sharding options. |
||
| 885 | * |
||
| 886 | * @throws MappingException |
||
| 887 | */ |
||
| 888 | 71 | public function setShardKey(array $keys, array $options = []) |
|
| 889 | { |
||
| 890 | 71 | if ($this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_COLLECTION && $this->shardKey !== null) { |
|
| 891 | 2 | throw MappingException::shardKeyInSingleCollInheritanceSubclass($this->getName()); |
|
| 892 | } |
||
| 893 | |||
| 894 | 71 | if ($this->isEmbeddedDocument) { |
|
| 895 | 2 | throw MappingException::embeddedDocumentCantHaveShardKey($this->getName()); |
|
| 896 | } |
||
| 897 | |||
| 898 | 69 | foreach (array_keys($keys) as $field) { |
|
| 899 | 69 | if (! isset($this->fieldMappings[$field])) { |
|
| 900 | 62 | continue; |
|
| 901 | } |
||
| 902 | |||
| 903 | 7 | if (in_array($this->fieldMappings[$field]['type'], ['many', 'collection'])) { |
|
| 904 | 3 | throw MappingException::noMultiKeyShardKeys($this->getName(), $field); |
|
| 932 | |||
| 933 | /** |
||
| 934 | * @return array |
||
| 935 | */ |
||
| 936 | 17 | public function getShardKey() |
|
| 940 | |||
| 941 | /** |
||
| 942 | * Checks whether this document has shard key or not. |
||
| 943 | * |
||
| 944 | * @return bool |
||
| 945 | */ |
||
| 946 | 1095 | public function isSharded() |
|
| 950 | |||
| 951 | /** |
||
| 952 | * Sets the read preference used by this class. |
||
| 953 | * |
||
| 954 | * @param string $readPreference |
||
| 955 | * @param array|null $tags |
||
| 956 | */ |
||
| 957 | 885 | public function setReadPreference($readPreference, $tags) |
|
| 962 | |||
| 963 | /** |
||
| 964 | * Sets the write concern used by this class. |
||
| 965 | * |
||
| 966 | * @param string $writeConcern |
||
| 967 | */ |
||
| 968 | 895 | public function setWriteConcern($writeConcern) |
|
| 972 | |||
| 973 | /** |
||
| 974 | * @return string |
||
| 975 | */ |
||
| 976 | 11 | public function getWriteConcern() |
|
| 980 | |||
| 981 | /** |
||
| 982 | * Whether there is a write concern configured for this class. |
||
| 983 | * |
||
| 984 | * @return bool |
||
| 985 | */ |
||
| 986 | 547 | public function hasWriteConcern() |
|
| 990 | |||
| 991 | /** |
||
| 992 | * Sets the change tracking policy used by this class. |
||
| 993 | * |
||
| 994 | * @param int $policy |
||
| 995 | */ |
||
| 996 | 887 | public function setChangeTrackingPolicy($policy) |
|
| 1000 | |||
| 1001 | /** |
||
| 1002 | * Whether the change tracking policy of this class is "deferred explicit". |
||
| 1003 | * |
||
| 1004 | * @return bool |
||
| 1005 | */ |
||
| 1006 | 61 | public function isChangeTrackingDeferredExplicit() |
|
| 1010 | |||
| 1011 | /** |
||
| 1012 | * Whether the change tracking policy of this class is "deferred implicit". |
||
| 1013 | * |
||
| 1014 | * @return bool |
||
| 1015 | */ |
||
| 1016 | 567 | public function isChangeTrackingDeferredImplicit() |
|
| 1020 | |||
| 1021 | /** |
||
| 1022 | * Whether the change tracking policy of this class is "notify". |
||
| 1023 | * |
||
| 1024 | * @return bool |
||
| 1025 | */ |
||
| 1026 | 308 | public function isChangeTrackingNotify() |
|
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Gets the ReflectionProperties of the mapped class. |
||
| 1033 | * |
||
| 1034 | * @return array An array of ReflectionProperty instances. |
||
| 1035 | */ |
||
| 1036 | 97 | public function getReflectionProperties() |
|
| 1040 | |||
| 1041 | /** |
||
| 1042 | * Gets a ReflectionProperty for a specific field of the mapped class. |
||
| 1043 | * |
||
| 1044 | * @param string $name |
||
| 1045 | * |
||
| 1046 | * @return \ReflectionProperty |
||
| 1047 | */ |
||
| 1048 | public function getReflectionProperty($name) |
||
| 1052 | |||
| 1053 | /** |
||
| 1054 | * {@inheritDoc} |
||
| 1055 | */ |
||
| 1056 | 1370 | public function getName() |
|
| 1060 | |||
| 1061 | /** |
||
| 1062 | * The namespace this Document class belongs to. |
||
| 1063 | * |
||
| 1064 | * @return string $namespace The namespace name. |
||
| 1065 | */ |
||
| 1066 | public function getNamespace() |
||
| 1070 | |||
| 1071 | /** |
||
| 1072 | * Returns the database this Document is mapped to. |
||
| 1073 | * |
||
| 1074 | * @return string $db The database name. |
||
| 1075 | */ |
||
| 1076 | 1294 | public function getDatabase() |
|
| 1080 | |||
| 1081 | /** |
||
| 1082 | * Set the database this Document is mapped to. |
||
| 1083 | * |
||
| 1084 | * @param string $db The database name |
||
| 1085 | */ |
||
| 1086 | 92 | public function setDatabase($db) |
|
| 1090 | |||
| 1091 | /** |
||
| 1092 | * Get the collection this Document is mapped to. |
||
| 1093 | * |
||
| 1094 | * @return string $collection The collection name. |
||
| 1095 | */ |
||
| 1096 | 1295 | public function getCollection() |
|
| 1100 | |||
| 1101 | /** |
||
| 1102 | * Sets the collection this Document is mapped to. |
||
| 1103 | * |
||
| 1104 | * @param array|string $name |
||
| 1105 | * |
||
| 1106 | * @throws \InvalidArgumentException |
||
| 1107 | */ |
||
| 1108 | 1474 | public function setCollection($name) |
|
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Get whether or not the documents collection is capped. |
||
| 1125 | * |
||
| 1126 | * @return bool |
||
| 1127 | */ |
||
| 1128 | 5 | public function getCollectionCapped() |
|
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Set whether or not the documents collection is capped. |
||
| 1135 | * |
||
| 1136 | * @param bool $bool |
||
| 1137 | */ |
||
| 1138 | 1 | public function setCollectionCapped($bool) |
|
| 1142 | |||
| 1143 | /** |
||
| 1144 | * Get the collection size |
||
| 1145 | * |
||
| 1146 | * @return int |
||
| 1147 | */ |
||
| 1148 | 5 | public function getCollectionSize() |
|
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Set the collection size. |
||
| 1155 | * |
||
| 1156 | * @param int $size |
||
| 1157 | */ |
||
| 1158 | 1 | public function setCollectionSize($size) |
|
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Get the collection max. |
||
| 1165 | * |
||
| 1166 | * @return int |
||
| 1167 | */ |
||
| 1168 | 5 | public function getCollectionMax() |
|
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Set the collection max. |
||
| 1175 | * |
||
| 1176 | * @param int $max |
||
| 1177 | */ |
||
| 1178 | 1 | public function setCollectionMax($max) |
|
| 1182 | |||
| 1183 | /** |
||
| 1184 | * Returns TRUE if this Document is mapped to a collection FALSE otherwise. |
||
| 1185 | * |
||
| 1186 | * @return bool |
||
| 1187 | */ |
||
| 1188 | public function isMappedToCollection() |
||
| 1192 | |||
| 1193 | /** |
||
| 1194 | * Validates the storage strategy of a mapping for consistency |
||
| 1195 | * @param array $mapping |
||
| 1196 | * @throws MappingException |
||
| 1197 | */ |
||
| 1198 | 1387 | private function applyStorageStrategy(array &$mapping) |
|
| 1241 | |||
| 1242 | /** |
||
| 1243 | * Map a single embedded document. |
||
| 1244 | * |
||
| 1245 | * @param array $mapping The mapping information. |
||
| 1246 | */ |
||
| 1247 | 6 | public function mapOneEmbedded(array $mapping) |
|
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Map a collection of embedded documents. |
||
| 1256 | * |
||
| 1257 | * @param array $mapping The mapping information. |
||
| 1258 | */ |
||
| 1259 | 5 | public function mapManyEmbedded(array $mapping) |
|
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Map a single document reference. |
||
| 1268 | * |
||
| 1269 | * @param array $mapping The mapping information. |
||
| 1270 | */ |
||
| 1271 | 2 | public function mapOneReference(array $mapping) |
|
| 1277 | |||
| 1278 | /** |
||
| 1279 | * Map a collection of document references. |
||
| 1280 | * |
||
| 1281 | * @param array $mapping The mapping information. |
||
| 1282 | */ |
||
| 1283 | 1 | public function mapManyReference(array $mapping) |
|
| 1289 | |||
| 1290 | /** |
||
| 1291 | * INTERNAL: |
||
| 1292 | * Adds a field mapping without completing/validating it. |
||
| 1293 | * This is mainly used to add inherited field mappings to derived classes. |
||
| 1294 | * |
||
| 1295 | * @param array $fieldMapping |
||
| 1296 | */ |
||
| 1297 | 116 | public function addInheritedFieldMapping(array $fieldMapping) |
|
| 1307 | |||
| 1308 | /** |
||
| 1309 | * INTERNAL: |
||
| 1310 | * Adds an association mapping without completing/validating it. |
||
| 1311 | * This is mainly used to add inherited association mappings to derived classes. |
||
| 1312 | * |
||
| 1313 | * @param array $mapping |
||
| 1314 | * |
||
| 1315 | * |
||
| 1316 | * @throws MappingException |
||
| 1317 | */ |
||
| 1318 | 68 | public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/) |
|
| 1322 | |||
| 1323 | /** |
||
| 1324 | * Checks whether the class has a mapped association with the given field name. |
||
| 1325 | * |
||
| 1326 | * @param string $fieldName |
||
| 1327 | * @return bool |
||
| 1328 | */ |
||
| 1329 | 32 | public function hasReference($fieldName) |
|
| 1333 | |||
| 1334 | /** |
||
| 1335 | * Checks whether the class has a mapped embed with the given field name. |
||
| 1336 | * |
||
| 1337 | * @param string $fieldName |
||
| 1338 | * @return bool |
||
| 1339 | */ |
||
| 1340 | 5 | public function hasEmbed($fieldName) |
|
| 1344 | |||
| 1345 | /** |
||
| 1346 | * {@inheritDoc} |
||
| 1347 | * |
||
| 1348 | * Checks whether the class has a mapped association (embed or reference) with the given field name. |
||
| 1349 | */ |
||
| 1350 | 7 | public function hasAssociation($fieldName) |
|
| 1354 | |||
| 1355 | /** |
||
| 1356 | * {@inheritDoc} |
||
| 1357 | * |
||
| 1358 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1359 | * is a single valued association. |
||
| 1360 | */ |
||
| 1361 | public function isSingleValuedAssociation($fieldName) |
||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * {@inheritDoc} |
||
| 1368 | * |
||
| 1369 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1370 | * is a collection valued association. |
||
| 1371 | */ |
||
| 1372 | public function isCollectionValuedAssociation($fieldName) |
||
| 1376 | |||
| 1377 | /** |
||
| 1378 | * Checks whether the class has a mapped association for the specified field |
||
| 1379 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1380 | * |
||
| 1381 | * @param string $fieldName |
||
| 1382 | * @return bool TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1383 | */ |
||
| 1384 | public function isSingleValuedReference($fieldName) |
||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Checks whether the class has a mapped association for the specified field |
||
| 1392 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1393 | * |
||
| 1394 | * @param string $fieldName |
||
| 1395 | * @return bool TRUE if the association exists and is collection-valued, FALSE otherwise. |
||
| 1396 | */ |
||
| 1397 | public function isCollectionValuedReference($fieldName) |
||
| 1402 | |||
| 1403 | /** |
||
| 1404 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1405 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1406 | * |
||
| 1407 | * @param string $fieldName |
||
| 1408 | * @return bool TRUE if the association exists and is single-valued, FALSE otherwise. |
||
| 1409 | */ |
||
| 1410 | public function isSingleValuedEmbed($fieldName) |
||
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1418 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1419 | * |
||
| 1420 | * @param string $fieldName |
||
| 1421 | * @return bool TRUE if the association exists and is collection-valued, FALSE otherwise. |
||
| 1422 | */ |
||
| 1423 | public function isCollectionValuedEmbed($fieldName) |
||
| 1428 | |||
| 1429 | /** |
||
| 1430 | * Sets the ID generator used to generate IDs for instances of this class. |
||
| 1431 | * |
||
| 1432 | * @param AbstractIdGenerator $generator |
||
| 1433 | */ |
||
| 1434 | 1306 | public function setIdGenerator($generator) |
|
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Casts the identifier to its portable PHP type. |
||
| 1441 | * |
||
| 1442 | * @param mixed $id |
||
| 1443 | * @return mixed $id |
||
| 1444 | */ |
||
| 1445 | 590 | public function getPHPIdentifierValue($id) |
|
| 1450 | |||
| 1451 | /** |
||
| 1452 | * Casts the identifier to its database type. |
||
| 1453 | * |
||
| 1454 | * @param mixed $id |
||
| 1455 | * @return mixed $id |
||
| 1456 | */ |
||
| 1457 | 654 | public function getDatabaseIdentifierValue($id) |
|
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Sets the document identifier of a document. |
||
| 1465 | * |
||
| 1466 | * The value will be converted to a PHP type before being set. |
||
| 1467 | * |
||
| 1468 | * @param object $document |
||
| 1469 | * @param mixed $id |
||
| 1470 | */ |
||
| 1471 | 519 | public function setIdentifierValue($document, $id) |
|
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Gets the document identifier as a PHP type. |
||
| 1479 | * |
||
| 1480 | * @param object $document |
||
| 1481 | * @return mixed $id |
||
| 1482 | */ |
||
| 1483 | 602 | public function getIdentifierValue($document) |
|
| 1487 | |||
| 1488 | /** |
||
| 1489 | * {@inheritDoc} |
||
| 1490 | * |
||
| 1491 | * Since MongoDB only allows exactly one identifier field this is a proxy |
||
| 1492 | * to {@see getIdentifierValue()} and returns an array with the identifier |
||
| 1493 | * field as a key. |
||
| 1494 | */ |
||
| 1495 | public function getIdentifierValues($object) |
||
| 1499 | |||
| 1500 | /** |
||
| 1501 | * Get the document identifier object as a database type. |
||
| 1502 | * |
||
| 1503 | * @param object $document |
||
| 1504 | * |
||
| 1505 | * @return ObjectId $id The ObjectId |
||
| 1506 | */ |
||
| 1507 | 31 | public function getIdentifierObject($document) |
|
| 1511 | |||
| 1512 | /** |
||
| 1513 | * Sets the specified field to the specified value on the given document. |
||
| 1514 | * |
||
| 1515 | * @param object $document |
||
| 1516 | * @param string $field |
||
| 1517 | * @param mixed $value |
||
| 1518 | */ |
||
| 1519 | 8 | public function setFieldValue($document, $field, $value) |
|
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Gets the specified field's value off the given document. |
||
| 1532 | * |
||
| 1533 | * @param object $document |
||
| 1534 | * @param string $field |
||
| 1535 | * |
||
| 1536 | * @return mixed |
||
| 1537 | */ |
||
| 1538 | 27 | public function getFieldValue($document, $field) |
|
| 1546 | |||
| 1547 | /** |
||
| 1548 | * Gets the mapping of a field. |
||
| 1549 | * |
||
| 1550 | * @param string $fieldName The field name. |
||
| 1551 | * |
||
| 1552 | * @return array The field mapping. |
||
| 1553 | * |
||
| 1554 | * @throws MappingException If the $fieldName is not found in the fieldMappings array. |
||
| 1555 | */ |
||
| 1556 | 167 | public function getFieldMapping($fieldName) |
|
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Gets mappings of fields holding embedded document(s). |
||
| 1566 | * |
||
| 1567 | * @return array of field mappings |
||
| 1568 | */ |
||
| 1569 | 558 | public function getEmbeddedFieldsMappings() |
|
| 1578 | |||
| 1579 | /** |
||
| 1580 | * Gets the field mapping by its DB name. |
||
| 1581 | * E.g. it returns identifier's mapping when called with _id. |
||
| 1582 | * |
||
| 1583 | * @param string $dbFieldName |
||
| 1584 | * |
||
| 1585 | * @return array |
||
| 1586 | * @throws MappingException |
||
| 1587 | */ |
||
| 1588 | 4 | public function getFieldMappingByDbFieldName($dbFieldName) |
|
| 1598 | |||
| 1599 | /** |
||
| 1600 | * Check if the field is not null. |
||
| 1601 | * |
||
| 1602 | * @param string $fieldName The field name |
||
| 1603 | * |
||
| 1604 | * @return bool TRUE if the field is not null, FALSE otherwise. |
||
| 1605 | */ |
||
| 1606 | 1 | public function isNullable($fieldName) |
|
| 1614 | |||
| 1615 | /** |
||
| 1616 | * Checks whether the document has a discriminator field and value configured. |
||
| 1617 | * |
||
| 1618 | * @return bool |
||
| 1619 | */ |
||
| 1620 | 492 | public function hasDiscriminator() |
|
| 1624 | |||
| 1625 | /** |
||
| 1626 | * Sets the type of Id generator to use for the mapped class. |
||
| 1627 | * |
||
| 1628 | * @param string $generatorType Generator type. |
||
| 1629 | */ |
||
| 1630 | 885 | public function setIdGeneratorType($generatorType) |
|
| 1634 | |||
| 1635 | /** |
||
| 1636 | * Sets the Id generator options. |
||
| 1637 | * |
||
| 1638 | * @param array $generatorOptions Generator options. |
||
| 1639 | */ |
||
| 1640 | public function setIdGeneratorOptions($generatorOptions) |
||
| 1644 | |||
| 1645 | /** |
||
| 1646 | * @return bool |
||
| 1647 | */ |
||
| 1648 | 565 | public function isInheritanceTypeNone() |
|
| 1652 | |||
| 1653 | /** |
||
| 1654 | * Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy. |
||
| 1655 | * |
||
| 1656 | * @return bool |
||
| 1657 | */ |
||
| 1658 | 884 | public function isInheritanceTypeSingleCollection() |
|
| 1662 | |||
| 1663 | /** |
||
| 1664 | * Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy. |
||
| 1665 | * |
||
| 1666 | * @return bool |
||
| 1667 | */ |
||
| 1668 | public function isInheritanceTypeCollectionPerClass() |
||
| 1672 | |||
| 1673 | /** |
||
| 1674 | * Sets the mapped subclasses of this class. |
||
| 1675 | * |
||
| 1676 | * @param string[] $subclasses The names of all mapped subclasses. |
||
| 1677 | */ |
||
| 1678 | 2 | public function setSubclasses(array $subclasses) |
|
| 1688 | |||
| 1689 | /** |
||
| 1690 | * Sets the parent class names. |
||
| 1691 | * Assumes that the class names in the passed array are in the order: |
||
| 1692 | * directParent -> directParentParent -> directParentParentParent ... -> root. |
||
| 1693 | * |
||
| 1694 | * @param string[] $classNames |
||
| 1695 | */ |
||
| 1696 | 1361 | public function setParentClasses(array $classNames) |
|
| 1706 | |||
| 1707 | /** |
||
| 1708 | * Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us. |
||
| 1709 | * |
||
| 1710 | * @return bool TRUE if the class uses the AUTO generator, FALSE otherwise. |
||
| 1711 | */ |
||
| 1712 | public function isIdGeneratorAuto() |
||
| 1716 | |||
| 1717 | /** |
||
| 1718 | * Checks whether the class will use a collection to generate incremented identifiers. |
||
| 1719 | * |
||
| 1720 | * @return bool TRUE if the class uses the INCREMENT generator, FALSE otherwise. |
||
| 1721 | */ |
||
| 1722 | public function isIdGeneratorIncrement() |
||
| 1726 | |||
| 1727 | /** |
||
| 1728 | * Checks whether the class will generate a uuid id. |
||
| 1729 | * |
||
| 1730 | * @return bool TRUE if the class uses the UUID generator, FALSE otherwise. |
||
| 1731 | */ |
||
| 1732 | public function isIdGeneratorUuid() |
||
| 1736 | |||
| 1737 | /** |
||
| 1738 | * Checks whether the class uses no id generator. |
||
| 1739 | * |
||
| 1740 | * @return bool TRUE if the class does not use any id generator, FALSE otherwise. |
||
| 1741 | */ |
||
| 1742 | public function isIdGeneratorNone() |
||
| 1746 | |||
| 1747 | /** |
||
| 1748 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1749 | * value to use depending on the column type. |
||
| 1750 | * |
||
| 1751 | * @param array $mapping The version field mapping array |
||
| 1752 | * |
||
| 1753 | * @throws LockException |
||
| 1754 | */ |
||
| 1755 | 67 | public function setVersionMapping(array &$mapping) |
|
| 1764 | |||
| 1765 | /** |
||
| 1766 | * Sets whether this class is to be versioned for optimistic locking. |
||
| 1767 | * |
||
| 1768 | * @param bool $bool |
||
| 1769 | */ |
||
| 1770 | 885 | public function setVersioned($bool) |
|
| 1774 | |||
| 1775 | /** |
||
| 1776 | * Sets the name of the field that is to be used for versioning if this class is |
||
| 1777 | * versioned for optimistic locking. |
||
| 1778 | * |
||
| 1779 | * @param string $versionField |
||
| 1780 | */ |
||
| 1781 | 885 | public function setVersionField($versionField) |
|
| 1785 | |||
| 1786 | /** |
||
| 1787 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1788 | * value to use depending on the column type. |
||
| 1789 | * |
||
| 1790 | * @param array $mapping The version field mapping array |
||
| 1791 | * |
||
| 1792 | * @throws LockException |
||
| 1793 | */ |
||
| 1794 | 22 | public function setLockMapping(array &$mapping) |
|
| 1803 | |||
| 1804 | /** |
||
| 1805 | * Sets whether this class is to allow pessimistic locking. |
||
| 1806 | * |
||
| 1807 | * @param bool $bool |
||
| 1808 | */ |
||
| 1809 | public function setLockable($bool) |
||
| 1813 | |||
| 1814 | /** |
||
| 1815 | * Sets the name of the field that is to be used for storing whether a document |
||
| 1816 | * is currently locked or not. |
||
| 1817 | * |
||
| 1818 | * @param string $lockField |
||
| 1819 | */ |
||
| 1820 | public function setLockField($lockField) |
||
| 1824 | |||
| 1825 | /** |
||
| 1826 | * Marks this class as read only, no change tracking is applied to it. |
||
| 1827 | */ |
||
| 1828 | 5 | public function markReadOnly() |
|
| 1832 | |||
| 1833 | /** |
||
| 1834 | * {@inheritDoc} |
||
| 1835 | */ |
||
| 1836 | public function getFieldNames() |
||
| 1840 | |||
| 1841 | /** |
||
| 1842 | * {@inheritDoc} |
||
| 1843 | */ |
||
| 1844 | public function getAssociationNames() |
||
| 1848 | |||
| 1849 | /** |
||
| 1850 | * {@inheritDoc} |
||
| 1851 | */ |
||
| 1852 | 23 | public function getTypeOfField($fieldName) |
|
| 1857 | |||
| 1858 | /** |
||
| 1859 | * {@inheritDoc} |
||
| 1860 | */ |
||
| 1861 | 4 | public function getAssociationTargetClass($assocName) |
|
| 1869 | |||
| 1870 | /** |
||
| 1871 | * Retrieve the collectionClass associated with an association |
||
| 1872 | * |
||
| 1873 | * @param string $assocName |
||
| 1874 | */ |
||
| 1875 | 1 | public function getAssociationCollectionClass($assocName) |
|
| 1887 | |||
| 1888 | /** |
||
| 1889 | * {@inheritDoc} |
||
| 1890 | */ |
||
| 1891 | public function isAssociationInverseSide($fieldName) |
||
| 1895 | |||
| 1896 | /** |
||
| 1897 | * {@inheritDoc} |
||
| 1898 | */ |
||
| 1899 | public function getAssociationMappedByTargetField($fieldName) |
||
| 1903 | |||
| 1904 | /** |
||
| 1905 | * Map a field. |
||
| 1906 | * |
||
| 1907 | * @param array $mapping The mapping information. |
||
| 1908 | * |
||
| 1909 | * @return array |
||
| 1910 | * |
||
| 1911 | * @throws MappingException |
||
| 1912 | */ |
||
| 1913 | 1399 | public function mapField(array $mapping) |
|
| 2087 | |||
| 2088 | /** |
||
| 2089 | * Determines which fields get serialized. |
||
| 2090 | * |
||
| 2091 | * It is only serialized what is necessary for best unserialization performance. |
||
| 2092 | * That means any metadata properties that are not set or empty or simply have |
||
| 2093 | * their default value are NOT serialized. |
||
| 2094 | * |
||
| 2095 | * Parts that are also NOT serialized because they can not be properly unserialized: |
||
| 2096 | * - reflClass (ReflectionClass) |
||
| 2097 | * - reflFields (ReflectionProperty array) |
||
| 2098 | * |
||
| 2099 | * @return array The names of all the fields that should be serialized. |
||
| 2100 | */ |
||
| 2101 | 6 | public function __sleep() |
|
| 2175 | |||
| 2176 | /** |
||
| 2177 | * Restores some state that can not be serialized/unserialized. |
||
| 2178 | * |
||
| 2179 | */ |
||
| 2180 | 6 | public function __wakeup() |
|
| 2196 | |||
| 2197 | /** |
||
| 2198 | * Creates a new instance of the mapped class, without invoking the constructor. |
||
| 2199 | * |
||
| 2200 | * @return object |
||
| 2201 | */ |
||
| 2202 | 354 | public function newInstance() |
|
| 2206 | } |
||
| 2207 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..