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 |
||
| 54 | class ClassMetadata implements BaseClassMetadata |
||
| 55 | { |
||
| 56 | /* The Id generator types. */ |
||
| 57 | /** |
||
| 58 | * AUTO means Doctrine will automatically create a new \MongoDB\BSON\ObjectId instance for us. |
||
| 59 | */ |
||
| 60 | public const GENERATOR_TYPE_AUTO = 1; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * INCREMENT means a separate collection is used for maintaining and incrementing id generation. |
||
| 64 | * Offers full portability. |
||
| 65 | */ |
||
| 66 | public const GENERATOR_TYPE_INCREMENT = 2; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * UUID means Doctrine will generate a uuid for us. |
||
| 70 | */ |
||
| 71 | public const GENERATOR_TYPE_UUID = 3; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * ALNUM means Doctrine will generate Alpha-numeric string identifiers, using the INCREMENT |
||
| 75 | * generator to ensure identifier uniqueness |
||
| 76 | */ |
||
| 77 | public const GENERATOR_TYPE_ALNUM = 4; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * CUSTOM means Doctrine expect a class parameter. It will then try to initiate that class |
||
| 81 | * and pass other options to the generator. It will throw an Exception if the class |
||
| 82 | * does not exist or if an option was passed for that there is not setter in the new |
||
| 83 | * generator class. |
||
| 84 | * |
||
| 85 | * The class will have to be a subtype of AbstractIdGenerator. |
||
| 86 | */ |
||
| 87 | public const GENERATOR_TYPE_CUSTOM = 5; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * NONE means Doctrine will not generate any id for us and you are responsible for manually |
||
| 91 | * assigning an id. |
||
| 92 | */ |
||
| 93 | public const GENERATOR_TYPE_NONE = 6; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Default discriminator field name. |
||
| 97 | * |
||
| 98 | * This is used for associations value for associations where a that do not define a "targetDocument" or |
||
| 99 | * "discriminatorField" option in their mapping. |
||
| 100 | */ |
||
| 101 | public const DEFAULT_DISCRIMINATOR_FIELD = '_doctrine_class_name'; |
||
| 102 | |||
| 103 | public const REFERENCE_ONE = 1; |
||
| 104 | public const REFERENCE_MANY = 2; |
||
| 105 | public const EMBED_ONE = 3; |
||
| 106 | public const EMBED_MANY = 4; |
||
| 107 | public const MANY = 'many'; |
||
| 108 | public const ONE = 'one'; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * The types of storeAs references |
||
| 112 | */ |
||
| 113 | public const REFERENCE_STORE_AS_ID = 'id'; |
||
| 114 | public const REFERENCE_STORE_AS_DB_REF = 'dbRef'; |
||
| 115 | public const REFERENCE_STORE_AS_DB_REF_WITH_DB = 'dbRefWithDb'; |
||
| 116 | public const REFERENCE_STORE_AS_REF = 'ref'; |
||
| 117 | |||
| 118 | /* The inheritance mapping types */ |
||
| 119 | /** |
||
| 120 | * NONE means the class does not participate in an inheritance hierarchy |
||
| 121 | * and therefore does not need an inheritance mapping type. |
||
| 122 | */ |
||
| 123 | public const INHERITANCE_TYPE_NONE = 1; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * SINGLE_COLLECTION means the class will be persisted according to the rules of |
||
| 127 | * <tt>Single Collection Inheritance</tt>. |
||
| 128 | */ |
||
| 129 | public const INHERITANCE_TYPE_SINGLE_COLLECTION = 2; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * COLLECTION_PER_CLASS means the class will be persisted according to the rules |
||
| 133 | * of <tt>Concrete Collection Inheritance</tt>. |
||
| 134 | */ |
||
| 135 | public const INHERITANCE_TYPE_COLLECTION_PER_CLASS = 3; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time |
||
| 139 | * by doing a property-by-property comparison with the original data. This will |
||
| 140 | * be done for all entities that are in MANAGED state at commit-time. |
||
| 141 | * |
||
| 142 | * This is the default change tracking policy. |
||
| 143 | */ |
||
| 144 | public const CHANGETRACKING_DEFERRED_IMPLICIT = 1; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time |
||
| 148 | * by doing a property-by-property comparison with the original data. This will |
||
| 149 | * be done only for entities that were explicitly saved (through persist() or a cascade). |
||
| 150 | */ |
||
| 151 | public const CHANGETRACKING_DEFERRED_EXPLICIT = 2; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * NOTIFY means that Doctrine relies on the entities sending out notifications |
||
| 155 | * when their properties change. Such entity classes must implement |
||
| 156 | * the <tt>NotifyPropertyChanged</tt> interface. |
||
| 157 | */ |
||
| 158 | public const CHANGETRACKING_NOTIFY = 3; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * SET means that fields will be written to the database using a $set operator |
||
| 162 | */ |
||
| 163 | public const STORAGE_STRATEGY_SET = 'set'; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * INCREMENT means that fields will be written to the database by calculating |
||
| 167 | * the difference and using the $inc operator |
||
| 168 | */ |
||
| 169 | public const STORAGE_STRATEGY_INCREMENT = 'increment'; |
||
| 170 | |||
| 171 | public const STORAGE_STRATEGY_PUSH_ALL = 'pushAll'; |
||
| 172 | public const STORAGE_STRATEGY_ADD_TO_SET = 'addToSet'; |
||
| 173 | public const STORAGE_STRATEGY_ATOMIC_SET = 'atomicSet'; |
||
| 174 | public const STORAGE_STRATEGY_ATOMIC_SET_ARRAY = 'atomicSetArray'; |
||
| 175 | public const STORAGE_STRATEGY_SET_ARRAY = 'setArray'; |
||
| 176 | |||
| 177 | private const ALLOWED_GRIDFS_FIELDS = ['_id', 'chunkSize', 'filename', 'length', 'metadata', 'uploadDate']; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * READ-ONLY: The name of the mongo database the document is mapped to. |
||
| 181 | * |
||
| 182 | * @var string|null |
||
| 183 | */ |
||
| 184 | public $db; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * READ-ONLY: The name of the mongo collection the document is mapped to. |
||
| 188 | * |
||
| 189 | * @var string |
||
| 190 | */ |
||
| 191 | public $collection; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * READ-ONLY: The name of the GridFS bucket the document is mapped to. |
||
| 195 | * |
||
| 196 | * @var string|null |
||
| 197 | */ |
||
| 198 | public $bucketName; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * READ-ONLY: If the collection should be a fixed size. |
||
| 202 | * |
||
| 203 | * @var bool |
||
| 204 | */ |
||
| 205 | public $collectionCapped = false; |
||
| 206 | |||
| 207 | /** |
||
| 208 | * READ-ONLY: If the collection is fixed size, its size in bytes. |
||
| 209 | * |
||
| 210 | * @var int|null |
||
| 211 | */ |
||
| 212 | public $collectionSize; |
||
| 213 | |||
| 214 | /** |
||
| 215 | * READ-ONLY: If the collection is fixed size, the maximum number of elements to store in the collection. |
||
| 216 | * |
||
| 217 | * @var int|null |
||
| 218 | */ |
||
| 219 | public $collectionMax; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set. |
||
| 223 | * |
||
| 224 | * @var string|int|null |
||
| 225 | */ |
||
| 226 | public $readPreference; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * READ-ONLY Associated with readPreference Allows to specify criteria so that your application can target read |
||
| 230 | * operations to specific members, based on custom parameters. |
||
| 231 | * |
||
| 232 | * @var string[][]|null |
||
| 233 | */ |
||
| 234 | public $readPreferenceTags; |
||
| 235 | |||
| 236 | /** |
||
| 237 | * READ-ONLY: Describes the level of acknowledgement requested from MongoDB for write operations. |
||
| 238 | * |
||
| 239 | * @var string|int|null |
||
| 240 | */ |
||
| 241 | public $writeConcern; |
||
| 242 | |||
| 243 | /** |
||
| 244 | * READ-ONLY: The field name of the document identifier. |
||
| 245 | * |
||
| 246 | * @var string|null |
||
| 247 | */ |
||
| 248 | public $identifier; |
||
| 249 | |||
| 250 | /** |
||
| 251 | * READ-ONLY: The array of indexes for the document collection. |
||
| 252 | * |
||
| 253 | * @var array |
||
| 254 | */ |
||
| 255 | public $indexes = []; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * READ-ONLY: Keys and options describing shard key. Only for sharded collections. |
||
| 259 | * |
||
| 260 | * @var string|null |
||
| 261 | */ |
||
| 262 | public $shardKey; |
||
| 263 | |||
| 264 | /** |
||
| 265 | * READ-ONLY: The name of the document class. |
||
| 266 | * |
||
| 267 | * @var string |
||
| 268 | */ |
||
| 269 | public $name; |
||
| 270 | |||
| 271 | /** |
||
| 272 | * READ-ONLY: The name of the document class that is at the root of the mapped document inheritance |
||
| 273 | * hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same |
||
| 274 | * as {@link $documentName}. |
||
| 275 | * |
||
| 276 | * @var string |
||
| 277 | */ |
||
| 278 | public $rootDocumentName; |
||
| 279 | |||
| 280 | /** |
||
| 281 | * The name of the custom repository class used for the document class. |
||
| 282 | * (Optional). |
||
| 283 | * |
||
| 284 | * @var string|null |
||
| 285 | */ |
||
| 286 | public $customRepositoryClassName; |
||
| 287 | |||
| 288 | /** |
||
| 289 | * READ-ONLY: The names of the parent classes (ancestors). |
||
| 290 | * |
||
| 291 | * @var array |
||
| 292 | */ |
||
| 293 | public $parentClasses = []; |
||
| 294 | |||
| 295 | /** |
||
| 296 | * READ-ONLY: The names of all subclasses (descendants). |
||
| 297 | * |
||
| 298 | * @var array |
||
| 299 | */ |
||
| 300 | public $subClasses = []; |
||
| 301 | |||
| 302 | /** |
||
| 303 | * The ReflectionProperty instances of the mapped class. |
||
| 304 | * |
||
| 305 | * @var ReflectionProperty[] |
||
| 306 | */ |
||
| 307 | public $reflFields = []; |
||
| 308 | |||
| 309 | /** |
||
| 310 | * READ-ONLY: The inheritance mapping type used by the class. |
||
| 311 | * |
||
| 312 | * @var int |
||
| 313 | */ |
||
| 314 | public $inheritanceType = self::INHERITANCE_TYPE_NONE; |
||
| 315 | |||
| 316 | /** |
||
| 317 | * READ-ONLY: The Id generator type used by the class. |
||
| 318 | * |
||
| 319 | * @var int |
||
| 320 | */ |
||
| 321 | public $generatorType = self::GENERATOR_TYPE_AUTO; |
||
| 322 | |||
| 323 | /** |
||
| 324 | * READ-ONLY: The Id generator options. |
||
| 325 | * |
||
| 326 | * @var array |
||
| 327 | */ |
||
| 328 | public $generatorOptions = []; |
||
| 329 | |||
| 330 | /** |
||
| 331 | * READ-ONLY: The ID generator used for generating IDs for this class. |
||
| 332 | * |
||
| 333 | * @var AbstractIdGenerator |
||
| 334 | */ |
||
| 335 | public $idGenerator; |
||
| 336 | |||
| 337 | /** |
||
| 338 | * READ-ONLY: The field mappings of the class. |
||
| 339 | * Keys are field names and values are mapping definitions. |
||
| 340 | * |
||
| 341 | * The mapping definition array has the following values: |
||
| 342 | * |
||
| 343 | * - <b>fieldName</b> (string) |
||
| 344 | * The name of the field in the Document. |
||
| 345 | * |
||
| 346 | * - <b>id</b> (boolean, optional) |
||
| 347 | * Marks the field as the primary key of the document. Multiple fields of an |
||
| 348 | * document can have the id attribute, forming a composite key. |
||
| 349 | * |
||
| 350 | * @var array |
||
| 351 | */ |
||
| 352 | public $fieldMappings = []; |
||
| 353 | |||
| 354 | /** |
||
| 355 | * READ-ONLY: The association mappings of the class. |
||
| 356 | * Keys are field names and values are mapping definitions. |
||
| 357 | * |
||
| 358 | * @var array |
||
| 359 | */ |
||
| 360 | public $associationMappings = []; |
||
| 361 | |||
| 362 | /** |
||
| 363 | * READ-ONLY: Array of fields to also load with a given method. |
||
| 364 | * |
||
| 365 | * @var array |
||
| 366 | */ |
||
| 367 | public $alsoLoadMethods = []; |
||
| 368 | |||
| 369 | /** |
||
| 370 | * READ-ONLY: The registered lifecycle callbacks for documents of this class. |
||
| 371 | * |
||
| 372 | * @var array |
||
| 373 | */ |
||
| 374 | public $lifecycleCallbacks = []; |
||
| 375 | |||
| 376 | /** |
||
| 377 | * READ-ONLY: The discriminator value of this class. |
||
| 378 | * |
||
| 379 | * <b>This does only apply to the JOINED and SINGLE_COLLECTION inheritance mapping strategies |
||
| 380 | * where a discriminator field is used.</b> |
||
| 381 | * |
||
| 382 | * @see discriminatorField |
||
| 383 | * |
||
| 384 | * @var mixed |
||
| 385 | */ |
||
| 386 | public $discriminatorValue; |
||
| 387 | |||
| 388 | /** |
||
| 389 | * READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
||
| 390 | * |
||
| 391 | * <b>This does only apply to the SINGLE_COLLECTION inheritance mapping strategy |
||
| 392 | * where a discriminator field is used.</b> |
||
| 393 | * |
||
| 394 | * @see discriminatorField |
||
| 395 | * |
||
| 396 | * @var mixed |
||
| 397 | */ |
||
| 398 | public $discriminatorMap = []; |
||
| 399 | |||
| 400 | /** |
||
| 401 | * READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION |
||
| 402 | * inheritance mapping. |
||
| 403 | * |
||
| 404 | * @var string |
||
| 405 | */ |
||
| 406 | public $discriminatorField; |
||
| 407 | |||
| 408 | /** |
||
| 409 | * READ-ONLY: The default value for discriminatorField in case it's not set in the document |
||
| 410 | * |
||
| 411 | * @see discriminatorField |
||
| 412 | * |
||
| 413 | * @var string |
||
| 414 | */ |
||
| 415 | public $defaultDiscriminatorValue; |
||
| 416 | |||
| 417 | /** |
||
| 418 | * READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
||
| 419 | * |
||
| 420 | * @var bool |
||
| 421 | */ |
||
| 422 | public $isMappedSuperclass = false; |
||
| 423 | |||
| 424 | /** |
||
| 425 | * READ-ONLY: Whether this class describes the mapping of a embedded document. |
||
| 426 | * |
||
| 427 | * @var bool |
||
| 428 | */ |
||
| 429 | public $isEmbeddedDocument = false; |
||
| 430 | |||
| 431 | /** |
||
| 432 | * READ-ONLY: Whether this class describes the mapping of an aggregation result document. |
||
| 433 | * |
||
| 434 | * @var bool |
||
| 435 | */ |
||
| 436 | public $isQueryResultDocument = false; |
||
| 437 | |||
| 438 | /** |
||
| 439 | * READ-ONLY: Whether this class describes the mapping of a gridFS file |
||
| 440 | * |
||
| 441 | * @var bool |
||
| 442 | */ |
||
| 443 | public $isFile = false; |
||
| 444 | |||
| 445 | /** |
||
| 446 | * READ-ONLY: The default chunk size in bytes for the file |
||
| 447 | * |
||
| 448 | * @var int|null |
||
| 449 | */ |
||
| 450 | public $chunkSizeBytes; |
||
| 451 | |||
| 452 | /** |
||
| 453 | * READ-ONLY: The policy used for change-tracking on entities of this class. |
||
| 454 | * |
||
| 455 | * @var int |
||
| 456 | */ |
||
| 457 | public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT; |
||
| 458 | |||
| 459 | /** |
||
| 460 | * READ-ONLY: A flag for whether or not instances of this class are to be versioned |
||
| 461 | * with optimistic locking. |
||
| 462 | * |
||
| 463 | * @var bool $isVersioned |
||
| 464 | */ |
||
| 465 | public $isVersioned = false; |
||
| 466 | |||
| 467 | /** |
||
| 468 | * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). |
||
| 469 | * |
||
| 470 | * @var string|null $versionField |
||
| 471 | */ |
||
| 472 | public $versionField; |
||
| 473 | |||
| 474 | /** |
||
| 475 | * READ-ONLY: A flag for whether or not instances of this class are to allow pessimistic |
||
| 476 | * locking. |
||
| 477 | * |
||
| 478 | * @var bool $isLockable |
||
| 479 | */ |
||
| 480 | public $isLockable = false; |
||
| 481 | |||
| 482 | /** |
||
| 483 | * READ-ONLY: The name of the field which is used for locking a document. |
||
| 484 | * |
||
| 485 | * @var mixed $lockField |
||
| 486 | */ |
||
| 487 | public $lockField; |
||
| 488 | |||
| 489 | /** |
||
| 490 | * The ReflectionClass instance of the mapped class. |
||
| 491 | * |
||
| 492 | * @var ReflectionClass |
||
| 493 | */ |
||
| 494 | public $reflClass; |
||
| 495 | |||
| 496 | /** |
||
| 497 | * READ_ONLY: A flag for whether or not this document is read-only. |
||
| 498 | * |
||
| 499 | * @var bool |
||
| 500 | */ |
||
| 501 | public $isReadOnly; |
||
| 502 | |||
| 503 | /** @var InstantiatorInterface|null */ |
||
| 504 | private $instantiator; |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Initializes a new ClassMetadata instance that will hold the object-document mapping |
||
| 508 | * metadata of the class with the given name. |
||
| 509 | */ |
||
| 510 | 1551 | public function __construct(string $documentName) |
|
| 511 | { |
||
| 512 | 1551 | $this->name = $documentName; |
|
| 513 | 1551 | $this->rootDocumentName = $documentName; |
|
| 514 | 1551 | $this->reflClass = new ReflectionClass($documentName); |
|
| 515 | 1551 | $this->setCollection($this->reflClass->getShortName()); |
|
| 516 | 1551 | $this->instantiator = new Instantiator(); |
|
|
|
|||
| 517 | 1551 | } |
|
| 518 | |||
| 519 | /** |
||
| 520 | * Helper method to get reference id of ref* type references |
||
| 521 | * |
||
| 522 | * @internal |
||
| 523 | * |
||
| 524 | * @param mixed $reference |
||
| 525 | * |
||
| 526 | * @return mixed |
||
| 527 | */ |
||
| 528 | 117 | public static function getReferenceId($reference, string $storeAs) |
|
| 529 | { |
||
| 530 | 117 | return $storeAs === self::REFERENCE_STORE_AS_ID ? $reference : $reference[self::getReferencePrefix($storeAs) . 'id']; |
|
| 531 | } |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Returns the reference prefix used for a reference |
||
| 535 | */ |
||
| 536 | 185 | private static function getReferencePrefix(string $storeAs) : string |
|
| 537 | { |
||
| 538 | 185 | if (! in_array($storeAs, [self::REFERENCE_STORE_AS_REF, self::REFERENCE_STORE_AS_DB_REF, self::REFERENCE_STORE_AS_DB_REF_WITH_DB])) { |
|
| 539 | throw new LogicException('Can only get a reference prefix for DBRef and reference arrays'); |
||
| 540 | } |
||
| 541 | |||
| 542 | 185 | return $storeAs === self::REFERENCE_STORE_AS_REF ? '' : '$'; |
|
| 543 | } |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Returns a fully qualified field name for a given reference |
||
| 547 | * |
||
| 548 | * @internal |
||
| 549 | * |
||
| 550 | * @param string $pathPrefix The field path prefix |
||
| 551 | */ |
||
| 552 | 137 | public static function getReferenceFieldName(string $storeAs, string $pathPrefix = '') : string |
|
| 553 | { |
||
| 554 | 137 | if ($storeAs === self::REFERENCE_STORE_AS_ID) { |
|
| 555 | 97 | return $pathPrefix; |
|
| 556 | } |
||
| 557 | |||
| 558 | 125 | return ($pathPrefix ? $pathPrefix . '.' : '') . static::getReferencePrefix($storeAs) . 'id'; |
|
| 559 | } |
||
| 560 | |||
| 561 | /** |
||
| 562 | * {@inheritDoc} |
||
| 563 | */ |
||
| 564 | 1436 | public function getReflectionClass() : ReflectionClass |
|
| 565 | { |
||
| 566 | 1436 | if (! $this->reflClass) { |
|
| 567 | $this->reflClass = new ReflectionClass($this->name); |
||
| 568 | } |
||
| 569 | |||
| 570 | 1436 | return $this->reflClass; |
|
| 571 | } |
||
| 572 | |||
| 573 | /** |
||
| 574 | * {@inheritDoc} |
||
| 575 | */ |
||
| 576 | 333 | public function isIdentifier($fieldName) : bool |
|
| 577 | { |
||
| 578 | 333 | return $this->identifier === $fieldName; |
|
| 579 | } |
||
| 580 | |||
| 581 | /** |
||
| 582 | * INTERNAL: |
||
| 583 | * Sets the mapped identifier field of this class. |
||
| 584 | */ |
||
| 585 | 916 | public function setIdentifier(?string $identifier) : void |
|
| 586 | { |
||
| 587 | 916 | $this->identifier = $identifier; |
|
| 588 | 916 | } |
|
| 589 | |||
| 590 | /** |
||
| 591 | * {@inheritDoc} |
||
| 592 | * |
||
| 593 | * Since MongoDB only allows exactly one identifier field |
||
| 594 | * this will always return an array with only one value |
||
| 595 | */ |
||
| 596 | 39 | public function getIdentifier() : array |
|
| 597 | { |
||
| 598 | 39 | return [$this->identifier]; |
|
| 599 | } |
||
| 600 | |||
| 601 | /** |
||
| 602 | * {@inheritDoc} |
||
| 603 | * |
||
| 604 | * Since MongoDB only allows exactly one identifier field |
||
| 605 | * this will always return an array with only one value |
||
| 606 | */ |
||
| 607 | 100 | public function getIdentifierFieldNames() : array |
|
| 608 | { |
||
| 609 | 100 | return [$this->identifier]; |
|
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * {@inheritDoc} |
||
| 614 | */ |
||
| 615 | 912 | public function hasField($fieldName) : bool |
|
| 616 | { |
||
| 617 | 912 | return isset($this->fieldMappings[$fieldName]); |
|
| 618 | } |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Sets the inheritance type used by the class and it's subclasses. |
||
| 622 | */ |
||
| 623 | 932 | public function setInheritanceType(int $type) : void |
|
| 624 | { |
||
| 625 | 932 | $this->inheritanceType = $type; |
|
| 626 | 932 | } |
|
| 627 | |||
| 628 | /** |
||
| 629 | * Checks whether a mapped field is inherited from an entity superclass. |
||
| 630 | */ |
||
| 631 | 1432 | public function isInheritedField(string $fieldName) : bool |
|
| 632 | { |
||
| 633 | 1432 | return isset($this->fieldMappings[$fieldName]['inherited']); |
|
| 634 | } |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Registers a custom repository class for the document class. |
||
| 638 | */ |
||
| 639 | 864 | public function setCustomRepositoryClass(?string $repositoryClassName) : void |
|
| 640 | { |
||
| 641 | 864 | if ($this->isEmbeddedDocument || $this->isQueryResultDocument) { |
|
| 642 | return; |
||
| 643 | } |
||
| 644 | |||
| 645 | 864 | $this->customRepositoryClassName = $repositoryClassName; |
|
| 646 | 864 | } |
|
| 647 | |||
| 648 | /** |
||
| 649 | * Dispatches the lifecycle event of the given document by invoking all |
||
| 650 | * registered callbacks. |
||
| 651 | * |
||
| 652 | * @throws InvalidArgumentException If document class is not this class or |
||
| 653 | * a Proxy of this class. |
||
| 654 | */ |
||
| 655 | 637 | public function invokeLifecycleCallbacks(string $event, object $document, ?array $arguments = null) : void |
|
| 656 | { |
||
| 657 | 637 | if (! $document instanceof $this->name) { |
|
| 658 | 1 | throw new InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, get_class($document))); |
|
| 659 | } |
||
| 660 | |||
| 661 | 636 | if (empty($this->lifecycleCallbacks[$event])) { |
|
| 662 | 621 | return; |
|
| 663 | } |
||
| 664 | |||
| 665 | 189 | foreach ($this->lifecycleCallbacks[$event] as $callback) { |
|
| 666 | 189 | if ($arguments !== null) { |
|
| 667 | 188 | call_user_func_array([$document, $callback], $arguments); |
|
| 668 | } else { |
||
| 669 | 189 | $document->$callback(); |
|
| 670 | } |
||
| 671 | } |
||
| 672 | 189 | } |
|
| 673 | |||
| 674 | /** |
||
| 675 | * Checks whether the class has callbacks registered for a lifecycle event. |
||
| 676 | */ |
||
| 677 | public function hasLifecycleCallbacks(string $event) : bool |
||
| 678 | { |
||
| 679 | return ! empty($this->lifecycleCallbacks[$event]); |
||
| 680 | } |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Gets the registered lifecycle callbacks for an event. |
||
| 684 | */ |
||
| 685 | public function getLifecycleCallbacks(string $event) : array |
||
| 686 | { |
||
| 687 | return $this->lifecycleCallbacks[$event] ?? []; |
||
| 688 | } |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Adds a lifecycle callback for documents of this class. |
||
| 692 | * |
||
| 693 | * If the callback is already registered, this is a NOOP. |
||
| 694 | */ |
||
| 695 | 835 | public function addLifecycleCallback(string $callback, string $event) : void |
|
| 696 | { |
||
| 697 | 835 | if (isset($this->lifecycleCallbacks[$event]) && in_array($callback, $this->lifecycleCallbacks[$event])) { |
|
| 698 | 1 | return; |
|
| 699 | } |
||
| 700 | |||
| 701 | 835 | $this->lifecycleCallbacks[$event][] = $callback; |
|
| 702 | 835 | } |
|
| 703 | |||
| 704 | /** |
||
| 705 | * Sets the lifecycle callbacks for documents of this class. |
||
| 706 | * |
||
| 707 | * Any previously registered callbacks are overwritten. |
||
| 708 | */ |
||
| 709 | 915 | public function setLifecycleCallbacks(array $callbacks) : void |
|
| 710 | { |
||
| 711 | 915 | $this->lifecycleCallbacks = $callbacks; |
|
| 712 | 915 | } |
|
| 713 | |||
| 714 | /** |
||
| 715 | * Registers a method for loading document data before field hydration. |
||
| 716 | * |
||
| 717 | * Note: A method may be registered multiple times for different fields. |
||
| 718 | * it will be invoked only once for the first field found. |
||
| 719 | * |
||
| 720 | * @param array|string $fields Database field name(s) |
||
| 721 | */ |
||
| 722 | 14 | public function registerAlsoLoadMethod(string $method, $fields) : void |
|
| 723 | { |
||
| 724 | 14 | $this->alsoLoadMethods[$method] = is_array($fields) ? $fields : [$fields]; |
|
| 725 | 14 | } |
|
| 726 | |||
| 727 | /** |
||
| 728 | * Sets the AlsoLoad methods for documents of this class. |
||
| 729 | * |
||
| 730 | * Any previously registered methods are overwritten. |
||
| 731 | */ |
||
| 732 | 915 | public function setAlsoLoadMethods(array $methods) : void |
|
| 733 | { |
||
| 734 | 915 | $this->alsoLoadMethods = $methods; |
|
| 735 | 915 | } |
|
| 736 | |||
| 737 | /** |
||
| 738 | * Sets the discriminator field. |
||
| 739 | * |
||
| 740 | * The field name is the the unmapped database field. Discriminator values |
||
| 741 | * are only used to discern the hydration class and are not mapped to class |
||
| 742 | * properties. |
||
| 743 | * |
||
| 744 | * @param string|array $discriminatorField |
||
| 745 | * |
||
| 746 | * @throws MappingException If the discriminator field conflicts with the |
||
| 747 | * "name" attribute of a mapped field. |
||
| 748 | */ |
||
| 749 | 941 | public function setDiscriminatorField($discriminatorField) : void |
|
| 750 | { |
||
| 751 | 941 | if ($this->isFile) { |
|
| 752 | throw MappingException::discriminatorNotAllowedForGridFS($this->name); |
||
| 753 | } |
||
| 754 | |||
| 755 | 941 | if ($discriminatorField === null) { |
|
| 756 | 873 | $this->discriminatorField = null; |
|
| 757 | |||
| 758 | 873 | return; |
|
| 759 | } |
||
| 760 | |||
| 761 | // Handle array argument with name/fieldName keys for BC |
||
| 762 | 137 | if (is_array($discriminatorField)) { |
|
| 763 | if (isset($discriminatorField['name'])) { |
||
| 764 | $discriminatorField = $discriminatorField['name']; |
||
| 765 | } elseif (isset($discriminatorField['fieldName'])) { |
||
| 766 | $discriminatorField = $discriminatorField['fieldName']; |
||
| 767 | } |
||
| 768 | } |
||
| 769 | |||
| 770 | 137 | foreach ($this->fieldMappings as $fieldMapping) { |
|
| 771 | 4 | if ($discriminatorField === $fieldMapping['name']) { |
|
| 772 | 4 | throw MappingException::discriminatorFieldConflict($this->name, $discriminatorField); |
|
| 773 | } |
||
| 774 | } |
||
| 775 | |||
| 776 | 136 | $this->discriminatorField = $discriminatorField; |
|
| 777 | 136 | } |
|
| 778 | |||
| 779 | /** |
||
| 780 | * Sets the discriminator values used by this class. |
||
| 781 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
||
| 782 | * |
||
| 783 | * @throws MappingException |
||
| 784 | */ |
||
| 785 | 934 | public function setDiscriminatorMap(array $map) : void |
|
| 786 | { |
||
| 787 | 934 | if ($this->isFile) { |
|
| 788 | throw MappingException::discriminatorNotAllowedForGridFS($this->name); |
||
| 789 | } |
||
| 790 | |||
| 791 | 934 | foreach ($map as $value => $className) { |
|
| 792 | 132 | $this->discriminatorMap[$value] = $className; |
|
| 793 | 132 | if ($this->name === $className) { |
|
| 794 | 124 | $this->discriminatorValue = $value; |
|
| 795 | } else { |
||
| 796 | 131 | if (! class_exists($className)) { |
|
| 797 | throw MappingException::invalidClassInDiscriminatorMap($className, $this->name); |
||
| 798 | } |
||
| 799 | 131 | if (is_subclass_of($className, $this->name)) { |
|
| 800 | 132 | $this->subClasses[] = $className; |
|
| 801 | } |
||
| 802 | } |
||
| 803 | } |
||
| 804 | 934 | } |
|
| 805 | |||
| 806 | /** |
||
| 807 | * Sets the default discriminator value to be used for this class |
||
| 808 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value |
||
| 809 | * |
||
| 810 | * @throws MappingException |
||
| 811 | */ |
||
| 812 | 918 | public function setDefaultDiscriminatorValue(?string $defaultDiscriminatorValue) : void |
|
| 813 | { |
||
| 814 | 918 | if ($this->isFile) { |
|
| 815 | throw MappingException::discriminatorNotAllowedForGridFS($this->name); |
||
| 816 | } |
||
| 817 | |||
| 818 | 918 | if ($defaultDiscriminatorValue === null) { |
|
| 819 | 915 | $this->defaultDiscriminatorValue = null; |
|
| 820 | |||
| 821 | 915 | return; |
|
| 822 | } |
||
| 823 | |||
| 824 | 68 | if (! array_key_exists($defaultDiscriminatorValue, $this->discriminatorMap)) { |
|
| 825 | throw MappingException::invalidDiscriminatorValue($defaultDiscriminatorValue, $this->name); |
||
| 826 | } |
||
| 827 | |||
| 828 | 68 | $this->defaultDiscriminatorValue = $defaultDiscriminatorValue; |
|
| 829 | 68 | } |
|
| 830 | |||
| 831 | /** |
||
| 832 | * Sets the discriminator value for this class. |
||
| 833 | * Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single |
||
| 834 | * collection. |
||
| 835 | * |
||
| 836 | * @throws MappingException |
||
| 837 | */ |
||
| 838 | 3 | public function setDiscriminatorValue(string $value) : void |
|
| 839 | { |
||
| 840 | 3 | if ($this->isFile) { |
|
| 841 | throw MappingException::discriminatorNotAllowedForGridFS($this->name); |
||
| 842 | } |
||
| 843 | |||
| 844 | 3 | $this->discriminatorMap[$value] = $this->name; |
|
| 845 | 3 | $this->discriminatorValue = $value; |
|
| 846 | 3 | } |
|
| 847 | |||
| 848 | /** |
||
| 849 | * Add a index for this Document. |
||
| 850 | */ |
||
| 851 | 217 | public function addIndex(array $keys, array $options = []) : void |
|
| 852 | { |
||
| 853 | 217 | $this->indexes[] = [ |
|
| 854 | 'keys' => array_map(static function ($value) { |
||
| 855 | 217 | if ($value === 1 || $value === -1) { |
|
| 856 | 65 | return (int) $value; |
|
| 857 | } |
||
| 858 | 217 | if (is_string($value)) { |
|
| 859 | 217 | $lower = strtolower($value); |
|
| 860 | 217 | if ($lower === 'asc') { |
|
| 861 | 210 | return 1; |
|
| 862 | } |
||
| 863 | |||
| 864 | 72 | if ($lower === 'desc') { |
|
| 865 | return -1; |
||
| 866 | } |
||
| 867 | } |
||
| 868 | 72 | return $value; |
|
| 869 | 217 | }, $keys), |
|
| 870 | 217 | 'options' => $options, |
|
| 871 | ]; |
||
| 872 | 217 | } |
|
| 873 | |||
| 874 | /** |
||
| 875 | * Returns the array of indexes for this Document. |
||
| 876 | */ |
||
| 877 | 26 | public function getIndexes() : array |
|
| 881 | |||
| 882 | /** |
||
| 883 | * Checks whether this document has indexes or not. |
||
| 884 | */ |
||
| 885 | public function hasIndexes() : bool |
||
| 886 | { |
||
| 887 | return $this->indexes ? true : false; |
||
| 888 | } |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Set shard key for this Document. |
||
| 892 | * |
||
| 893 | * @throws MappingException |
||
| 894 | */ |
||
| 895 | 100 | public function setShardKey(array $keys, array $options = []) : void |
|
| 896 | { |
||
| 897 | 100 | if ($this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_COLLECTION && $this->shardKey !== null) { |
|
| 898 | 2 | throw MappingException::shardKeyInSingleCollInheritanceSubclass($this->getName()); |
|
| 899 | } |
||
| 900 | |||
| 901 | 100 | if ($this->isEmbeddedDocument) { |
|
| 902 | 2 | throw MappingException::embeddedDocumentCantHaveShardKey($this->getName()); |
|
| 903 | } |
||
| 904 | |||
| 905 | 98 | foreach (array_keys($keys) as $field) { |
|
| 906 | 98 | if (! isset($this->fieldMappings[$field])) { |
|
| 907 | 91 | continue; |
|
| 908 | } |
||
| 909 | |||
| 910 | 7 | if (in_array($this->fieldMappings[$field]['type'], ['many', 'collection'])) { |
|
| 911 | 3 | throw MappingException::noMultiKeyShardKeys($this->getName(), $field); |
|
| 912 | } |
||
| 913 | |||
| 914 | 4 | if ($this->fieldMappings[$field]['strategy'] !== static::STORAGE_STRATEGY_SET) { |
|
| 915 | 4 | throw MappingException::onlySetStrategyAllowedInShardKey($this->getName(), $field); |
|
| 916 | } |
||
| 917 | } |
||
| 918 | |||
| 919 | 94 | $this->shardKey = [ |
|
| 920 | 'keys' => array_map(static function ($value) { |
||
| 921 | 94 | if ($value === 1 || $value === -1) { |
|
| 922 | 5 | return (int) $value; |
|
| 923 | } |
||
| 924 | 94 | if (is_string($value)) { |
|
| 925 | 94 | $lower = strtolower($value); |
|
| 926 | 94 | if ($lower === 'asc') { |
|
| 927 | 92 | return 1; |
|
| 928 | } |
||
| 929 | |||
| 930 | 67 | if ($lower === 'desc') { |
|
| 931 | return -1; |
||
| 932 | } |
||
| 933 | } |
||
| 934 | 67 | return $value; |
|
| 935 | 94 | }, $keys), |
|
| 936 | 94 | 'options' => $options, |
|
| 937 | ]; |
||
| 938 | 94 | } |
|
| 939 | |||
| 940 | 26 | public function getShardKey() : array |
|
| 941 | { |
||
| 942 | 26 | return $this->shardKey; |
|
| 943 | } |
||
| 944 | |||
| 945 | /** |
||
| 946 | * Checks whether this document has shard key or not. |
||
| 947 | */ |
||
| 948 | 1153 | public function isSharded() : bool |
|
| 949 | { |
||
| 950 | 1153 | return $this->shardKey ? true : false; |
|
| 951 | } |
||
| 952 | |||
| 953 | /** |
||
| 954 | * Sets the read preference used by this class. |
||
| 955 | * |
||
| 956 | * @param string|int|null $readPreference |
||
| 957 | * @param array|null $tags |
||
| 958 | */ |
||
| 959 | 915 | public function setReadPreference($readPreference, $tags) : void |
|
| 960 | { |
||
| 961 | 915 | $this->readPreference = $readPreference; |
|
| 962 | 915 | $this->readPreferenceTags = $tags; |
|
| 963 | 915 | } |
|
| 964 | |||
| 965 | /** |
||
| 966 | * Sets the write concern used by this class. |
||
| 967 | * |
||
| 968 | * @param string|int|null $writeConcern |
||
| 969 | */ |
||
| 970 | 925 | public function setWriteConcern($writeConcern) : void |
|
| 971 | { |
||
| 972 | 925 | $this->writeConcern = $writeConcern; |
|
| 973 | 925 | } |
|
| 974 | |||
| 975 | /** |
||
| 976 | * @return int|string|null |
||
| 977 | */ |
||
| 978 | 11 | public function getWriteConcern() |
|
| 979 | { |
||
| 980 | 11 | return $this->writeConcern; |
|
| 981 | } |
||
| 982 | |||
| 983 | /** |
||
| 984 | * Whether there is a write concern configured for this class. |
||
| 985 | */ |
||
| 986 | 584 | public function hasWriteConcern() : bool |
|
| 987 | { |
||
| 988 | 584 | return $this->writeConcern !== null; |
|
| 989 | } |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Sets the change tracking policy used by this class. |
||
| 993 | */ |
||
| 994 | 917 | public function setChangeTrackingPolicy(int $policy) : void |
|
| 995 | { |
||
| 996 | 917 | $this->changeTrackingPolicy = $policy; |
|
| 997 | 917 | } |
|
| 998 | |||
| 999 | /** |
||
| 1000 | * Whether the change tracking policy of this class is "deferred explicit". |
||
| 1001 | */ |
||
| 1002 | 64 | public function isChangeTrackingDeferredExplicit() : bool |
|
| 1003 | { |
||
| 1004 | 64 | return $this->changeTrackingPolicy === self::CHANGETRACKING_DEFERRED_EXPLICIT; |
|
| 1005 | } |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Whether the change tracking policy of this class is "deferred implicit". |
||
| 1009 | */ |
||
| 1010 | 607 | public function isChangeTrackingDeferredImplicit() : bool |
|
| 1014 | |||
| 1015 | /** |
||
| 1016 | * Whether the change tracking policy of this class is "notify". |
||
| 1017 | */ |
||
| 1018 | 335 | public function isChangeTrackingNotify() : bool |
|
| 1019 | { |
||
| 1020 | 335 | return $this->changeTrackingPolicy === self::CHANGETRACKING_NOTIFY; |
|
| 1021 | } |
||
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Gets the ReflectionProperties of the mapped class. |
||
| 1025 | */ |
||
| 1026 | 100 | public function getReflectionProperties() : array |
|
| 1027 | { |
||
| 1028 | 100 | return $this->reflFields; |
|
| 1029 | } |
||
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Gets a ReflectionProperty for a specific field of the mapped class. |
||
| 1033 | */ |
||
| 1034 | public function getReflectionProperty(string $name) : ReflectionProperty |
||
| 1035 | { |
||
| 1036 | return $this->reflFields[$name]; |
||
| 1037 | } |
||
| 1038 | |||
| 1039 | /** |
||
| 1040 | * {@inheritDoc} |
||
| 1041 | */ |
||
| 1042 | 1440 | public function getName() : string |
|
| 1043 | { |
||
| 1044 | 1440 | return $this->name; |
|
| 1045 | } |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Returns the database this Document is mapped to. |
||
| 1049 | */ |
||
| 1050 | 1361 | public function getDatabase() : ?string |
|
| 1051 | { |
||
| 1052 | 1361 | return $this->db; |
|
| 1053 | } |
||
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Set the database this Document is mapped to. |
||
| 1057 | */ |
||
| 1058 | 111 | public function setDatabase(?string $db) : void |
|
| 1062 | |||
| 1063 | /** |
||
| 1064 | * Get the collection this Document is mapped to. |
||
| 1065 | */ |
||
| 1066 | 1353 | public function getCollection() : string |
|
| 1070 | |||
| 1071 | /** |
||
| 1072 | * Sets the collection this Document is mapped to. |
||
| 1073 | * |
||
| 1074 | * @param array|string $name |
||
| 1075 | * |
||
| 1076 | * @throws InvalidArgumentException |
||
| 1077 | */ |
||
| 1078 | 1551 | public function setCollection($name) : void |
|
| 1092 | |||
| 1093 | 18 | public function getBucketName() : ?string |
|
| 1097 | |||
| 1098 | 78 | public function setBucketName(string $bucketName) : void |
|
| 1103 | |||
| 1104 | 9 | public function getChunkSizeBytes() : ?int |
|
| 1108 | |||
| 1109 | 78 | public function setChunkSizeBytes(int $chunkSizeBytes) : void |
|
| 1113 | |||
| 1114 | /** |
||
| 1115 | * Get whether or not the documents collection is capped. |
||
| 1116 | */ |
||
| 1117 | 5 | public function getCollectionCapped() : bool |
|
| 1121 | |||
| 1122 | /** |
||
| 1123 | * Set whether or not the documents collection is capped. |
||
| 1124 | */ |
||
| 1125 | 1 | public function setCollectionCapped(bool $bool) : void |
|
| 1129 | |||
| 1130 | /** |
||
| 1131 | * Get the collection size |
||
| 1132 | */ |
||
| 1133 | 5 | public function getCollectionSize() : ?int |
|
| 1137 | |||
| 1138 | /** |
||
| 1139 | * Set the collection size. |
||
| 1140 | */ |
||
| 1141 | 1 | public function setCollectionSize(int $size) : void |
|
| 1145 | |||
| 1146 | /** |
||
| 1147 | * Get the collection max. |
||
| 1148 | */ |
||
| 1149 | 5 | public function getCollectionMax() : ?int |
|
| 1153 | |||
| 1154 | /** |
||
| 1155 | * Set the collection max. |
||
| 1156 | */ |
||
| 1157 | 1 | public function setCollectionMax(int $max) : void |
|
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Returns TRUE if this Document is mapped to a collection FALSE otherwise. |
||
| 1164 | */ |
||
| 1165 | public function isMappedToCollection() : bool |
||
| 1169 | |||
| 1170 | /** |
||
| 1171 | * Validates the storage strategy of a mapping for consistency |
||
| 1172 | * |
||
| 1173 | * @throws MappingException |
||
| 1174 | */ |
||
| 1175 | 1458 | private function applyStorageStrategy(array &$mapping) : void |
|
| 1218 | |||
| 1219 | /** |
||
| 1220 | * Map a single embedded document. |
||
| 1221 | */ |
||
| 1222 | 6 | public function mapOneEmbedded(array $mapping) : void |
|
| 1228 | |||
| 1229 | /** |
||
| 1230 | * Map a collection of embedded documents. |
||
| 1231 | */ |
||
| 1232 | 5 | public function mapManyEmbedded(array $mapping) : void |
|
| 1238 | |||
| 1239 | /** |
||
| 1240 | * Map a single document reference. |
||
| 1241 | */ |
||
| 1242 | 2 | public function mapOneReference(array $mapping) : void |
|
| 1248 | |||
| 1249 | /** |
||
| 1250 | * Map a collection of document references. |
||
| 1251 | */ |
||
| 1252 | 1 | public function mapManyReference(array $mapping) : void |
|
| 1258 | |||
| 1259 | /** |
||
| 1260 | * INTERNAL: |
||
| 1261 | * Adds a field mapping without completing/validating it. |
||
| 1262 | * This is mainly used to add inherited field mappings to derived classes. |
||
| 1263 | */ |
||
| 1264 | 138 | public function addInheritedFieldMapping(array $fieldMapping) : void |
|
| 1274 | |||
| 1275 | /** |
||
| 1276 | * INTERNAL: |
||
| 1277 | * Adds an association mapping without completing/validating it. |
||
| 1278 | * This is mainly used to add inherited association mappings to derived classes. |
||
| 1279 | * |
||
| 1280 | * @throws MappingException |
||
| 1281 | */ |
||
| 1282 | 90 | public function addInheritedAssociationMapping(array $mapping) : void |
|
| 1286 | |||
| 1287 | /** |
||
| 1288 | * Checks whether the class has a mapped association with the given field name. |
||
| 1289 | */ |
||
| 1290 | 32 | public function hasReference(string $fieldName) : bool |
|
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Checks whether the class has a mapped embed with the given field name. |
||
| 1297 | */ |
||
| 1298 | 5 | public function hasEmbed(string $fieldName) : bool |
|
| 1302 | |||
| 1303 | /** |
||
| 1304 | * {@inheritDoc} |
||
| 1305 | * |
||
| 1306 | * Checks whether the class has a mapped association (embed or reference) with the given field name. |
||
| 1307 | */ |
||
| 1308 | 7 | public function hasAssociation($fieldName) : bool |
|
| 1312 | |||
| 1313 | /** |
||
| 1314 | * {@inheritDoc} |
||
| 1315 | * |
||
| 1316 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1317 | * is a single valued association. |
||
| 1318 | */ |
||
| 1319 | public function isSingleValuedAssociation($fieldName) : bool |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * {@inheritDoc} |
||
| 1326 | * |
||
| 1327 | * Checks whether the class has a mapped reference or embed for the specified field and |
||
| 1328 | * is a collection valued association. |
||
| 1329 | */ |
||
| 1330 | public function isCollectionValuedAssociation($fieldName) : bool |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * Checks whether the class has a mapped association for the specified field |
||
| 1337 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1338 | */ |
||
| 1339 | public function isSingleValuedReference(string $fieldName) : bool |
||
| 1344 | |||
| 1345 | /** |
||
| 1346 | * Checks whether the class has a mapped association for the specified field |
||
| 1347 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1348 | */ |
||
| 1349 | public function isCollectionValuedReference(string $fieldName) : bool |
||
| 1354 | |||
| 1355 | /** |
||
| 1356 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1357 | * and if yes, checks whether it is a single-valued association (to-one). |
||
| 1358 | */ |
||
| 1359 | public function isSingleValuedEmbed(string $fieldName) : bool |
||
| 1364 | |||
| 1365 | /** |
||
| 1366 | * Checks whether the class has a mapped embedded document for the specified field |
||
| 1367 | * and if yes, checks whether it is a collection-valued association (to-many). |
||
| 1368 | */ |
||
| 1369 | public function isCollectionValuedEmbed(string $fieldName) : bool |
||
| 1374 | |||
| 1375 | /** |
||
| 1376 | * Sets the ID generator used to generate IDs for instances of this class. |
||
| 1377 | */ |
||
| 1378 | 1376 | public function setIdGenerator(AbstractIdGenerator $generator) : void |
|
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Casts the identifier to its portable PHP type. |
||
| 1385 | * |
||
| 1386 | * @param mixed $id |
||
| 1387 | * |
||
| 1388 | * @return mixed $id |
||
| 1389 | */ |
||
| 1390 | 636 | public function getPHPIdentifierValue($id) |
|
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Casts the identifier to its database type. |
||
| 1398 | * |
||
| 1399 | * @param mixed $id |
||
| 1400 | * |
||
| 1401 | * @return mixed $id |
||
| 1402 | */ |
||
| 1403 | 700 | public function getDatabaseIdentifierValue($id) |
|
| 1408 | |||
| 1409 | /** |
||
| 1410 | * Sets the document identifier of a document. |
||
| 1411 | * |
||
| 1412 | * The value will be converted to a PHP type before being set. |
||
| 1413 | * |
||
| 1414 | * @param mixed $id |
||
| 1415 | */ |
||
| 1416 | 555 | public function setIdentifierValue(object $document, $id) : void |
|
| 1421 | |||
| 1422 | /** |
||
| 1423 | * Gets the document identifier as a PHP type. |
||
| 1424 | * |
||
| 1425 | * @return mixed $id |
||
| 1426 | */ |
||
| 1427 | 640 | public function getIdentifierValue(object $document) |
|
| 1431 | |||
| 1432 | /** |
||
| 1433 | * {@inheritDoc} |
||
| 1434 | * |
||
| 1435 | * Since MongoDB only allows exactly one identifier field this is a proxy |
||
| 1436 | * to {@see getIdentifierValue()} and returns an array with the identifier |
||
| 1437 | * field as a key. |
||
| 1438 | */ |
||
| 1439 | public function getIdentifierValues($object) : array |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * Get the document identifier object as a database type. |
||
| 1446 | * |
||
| 1447 | * @return mixed $id |
||
| 1448 | */ |
||
| 1449 | 31 | public function getIdentifierObject(object $document) |
|
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Sets the specified field to the specified value on the given document. |
||
| 1456 | * |
||
| 1457 | * @param mixed $value |
||
| 1458 | */ |
||
| 1459 | 8 | public function setFieldValue(object $document, string $field, $value) : void |
|
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Gets the specified field's value off the given document. |
||
| 1472 | * |
||
| 1473 | * @return mixed |
||
| 1474 | */ |
||
| 1475 | 32 | public function getFieldValue(object $document, string $field) |
|
| 1483 | |||
| 1484 | /** |
||
| 1485 | * Gets the mapping of a field. |
||
| 1486 | * |
||
| 1487 | * @throws MappingException If the $fieldName is not found in the fieldMappings array. |
||
| 1488 | */ |
||
| 1489 | 174 | public function getFieldMapping(string $fieldName) : array |
|
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Gets mappings of fields holding embedded document(s). |
||
| 1499 | */ |
||
| 1500 | 585 | public function getEmbeddedFieldsMappings() : array |
|
| 1509 | |||
| 1510 | /** |
||
| 1511 | * Gets the field mapping by its DB name. |
||
| 1512 | * E.g. it returns identifier's mapping when called with _id. |
||
| 1513 | * |
||
| 1514 | * @throws MappingException |
||
| 1515 | */ |
||
| 1516 | 13 | public function getFieldMappingByDbFieldName(string $dbFieldName) : array |
|
| 1526 | |||
| 1527 | /** |
||
| 1528 | * Check if the field is not null. |
||
| 1529 | */ |
||
| 1530 | 1 | public function isNullable(string $fieldName) : bool |
|
| 1538 | |||
| 1539 | /** |
||
| 1540 | * Checks whether the document has a discriminator field and value configured. |
||
| 1541 | */ |
||
| 1542 | 515 | public function hasDiscriminator() : bool |
|
| 1546 | |||
| 1547 | /** |
||
| 1548 | * Sets the type of Id generator to use for the mapped class. |
||
| 1549 | */ |
||
| 1550 | 915 | public function setIdGeneratorType(int $generatorType) : void |
|
| 1554 | |||
| 1555 | /** |
||
| 1556 | * Sets the Id generator options. |
||
| 1557 | */ |
||
| 1558 | public function setIdGeneratorOptions(array $generatorOptions) : void |
||
| 1562 | |||
| 1563 | 604 | public function isInheritanceTypeNone() : bool |
|
| 1567 | |||
| 1568 | /** |
||
| 1569 | * Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy. |
||
| 1570 | */ |
||
| 1571 | 914 | public function isInheritanceTypeSingleCollection() : bool |
|
| 1575 | |||
| 1576 | /** |
||
| 1577 | * Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy. |
||
| 1578 | */ |
||
| 1579 | public function isInheritanceTypeCollectionPerClass() : bool |
||
| 1583 | |||
| 1584 | /** |
||
| 1585 | * Sets the mapped subclasses of this class. |
||
| 1586 | * |
||
| 1587 | * @param string[] $subclasses The names of all mapped subclasses. |
||
| 1588 | */ |
||
| 1589 | 2 | public function setSubclasses(array $subclasses) : void |
|
| 1595 | |||
| 1596 | /** |
||
| 1597 | * Sets the parent class names. |
||
| 1598 | * Assumes that the class names in the passed array are in the order: |
||
| 1599 | * directParent -> directParentParent -> directParentParentParent ... -> root. |
||
| 1600 | * |
||
| 1601 | * @param string[] $classNames |
||
| 1602 | */ |
||
| 1603 | 1431 | public function setParentClasses(array $classNames) : void |
|
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us. |
||
| 1616 | */ |
||
| 1617 | public function isIdGeneratorAuto() : bool |
||
| 1621 | |||
| 1622 | /** |
||
| 1623 | * Checks whether the class will use a collection to generate incremented identifiers. |
||
| 1624 | */ |
||
| 1625 | public function isIdGeneratorIncrement() : bool |
||
| 1629 | |||
| 1630 | /** |
||
| 1631 | * Checks whether the class will generate a uuid id. |
||
| 1632 | */ |
||
| 1633 | public function isIdGeneratorUuid() : bool |
||
| 1637 | |||
| 1638 | /** |
||
| 1639 | * Checks whether the class uses no id generator. |
||
| 1640 | */ |
||
| 1641 | public function isIdGeneratorNone() : bool |
||
| 1645 | |||
| 1646 | /** |
||
| 1647 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1648 | * value to use depending on the column type. |
||
| 1649 | * |
||
| 1650 | * @throws LockException |
||
| 1651 | */ |
||
| 1652 | 106 | public function setVersionMapping(array &$mapping) : void |
|
| 1661 | |||
| 1662 | /** |
||
| 1663 | * Sets whether this class is to be versioned for optimistic locking. |
||
| 1664 | */ |
||
| 1665 | 915 | public function setVersioned(bool $bool) : void |
|
| 1669 | |||
| 1670 | /** |
||
| 1671 | * Sets the name of the field that is to be used for versioning if this class is |
||
| 1672 | * versioned for optimistic locking. |
||
| 1673 | */ |
||
| 1674 | 915 | public function setVersionField(?string $versionField) : void |
|
| 1678 | |||
| 1679 | /** |
||
| 1680 | * Sets the version field mapping used for versioning. Sets the default |
||
| 1681 | * value to use depending on the column type. |
||
| 1682 | * |
||
| 1683 | * @throws LockException |
||
| 1684 | */ |
||
| 1685 | 22 | public function setLockMapping(array &$mapping) : void |
|
| 1694 | |||
| 1695 | /** |
||
| 1696 | * Sets whether this class is to allow pessimistic locking. |
||
| 1697 | */ |
||
| 1698 | public function setLockable(bool $bool) : void |
||
| 1702 | |||
| 1703 | /** |
||
| 1704 | * Sets the name of the field that is to be used for storing whether a document |
||
| 1705 | * is currently locked or not. |
||
| 1706 | */ |
||
| 1707 | public function setLockField(string $lockField) : void |
||
| 1711 | |||
| 1712 | /** |
||
| 1713 | * Marks this class as read only, no change tracking is applied to it. |
||
| 1714 | */ |
||
| 1715 | 5 | public function markReadOnly() : void |
|
| 1719 | |||
| 1720 | /** |
||
| 1721 | * {@inheritDoc} |
||
| 1722 | */ |
||
| 1723 | public function getFieldNames() : array |
||
| 1727 | |||
| 1728 | /** |
||
| 1729 | * {@inheritDoc} |
||
| 1730 | */ |
||
| 1731 | public function getAssociationNames() : array |
||
| 1735 | |||
| 1736 | /** |
||
| 1737 | * {@inheritDoc} |
||
| 1738 | */ |
||
| 1739 | 23 | public function getTypeOfField($fieldName) : ?string |
|
| 1744 | |||
| 1745 | /** |
||
| 1746 | * {@inheritDoc} |
||
| 1747 | */ |
||
| 1748 | 4 | public function getAssociationTargetClass($assocName) : string |
|
| 1756 | |||
| 1757 | /** |
||
| 1758 | * Retrieve the collectionClass associated with an association |
||
| 1759 | */ |
||
| 1760 | 1 | public function getAssociationCollectionClass(string $assocName) : string |
|
| 1772 | |||
| 1773 | /** |
||
| 1774 | * {@inheritDoc} |
||
| 1775 | */ |
||
| 1776 | public function isAssociationInverseSide($fieldName) : bool |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * {@inheritDoc} |
||
| 1783 | */ |
||
| 1784 | public function getAssociationMappedByTargetField($fieldName) |
||
| 1788 | |||
| 1789 | /** |
||
| 1790 | * Map a field. |
||
| 1791 | * |
||
| 1792 | * @throws MappingException |
||
| 1793 | */ |
||
| 1794 | 1474 | public function mapField(array $mapping) : array |
|
| 1977 | |||
| 1978 | /** |
||
| 1979 | * Determines which fields get serialized. |
||
| 1980 | * |
||
| 1981 | * It is only serialized what is necessary for best unserialization performance. |
||
| 1982 | * That means any metadata properties that are not set or empty or simply have |
||
| 1983 | * their default value are NOT serialized. |
||
| 1984 | * |
||
| 1985 | * Parts that are also NOT serialized because they can not be properly unserialized: |
||
| 1986 | * - reflClass (ReflectionClass) |
||
| 1987 | * - reflFields (ReflectionProperty array) |
||
| 1988 | * |
||
| 1989 | * @return array The names of all the fields that should be serialized. |
||
| 1990 | */ |
||
| 1991 | 6 | public function __sleep() |
|
| 2070 | |||
| 2071 | /** |
||
| 2072 | * Restores some state that can not be serialized/unserialized. |
||
| 2073 | */ |
||
| 2074 | 6 | public function __wakeup() |
|
| 2090 | |||
| 2091 | /** |
||
| 2092 | * Creates a new instance of the mapped class, without invoking the constructor. |
||
| 2093 | */ |
||
| 2094 | 368 | public function newInstance() : object |
|
| 2098 | |||
| 2099 | 80 | private function isAllowedGridFSField(string $name) : bool |
|
| 2103 | } |
||
| 2104 |
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..