ClassMetadata
class ClassMetadata implements ClassMetadata (View source)
A ClassMetadata instance holds all the object-document mapping metadata of a document and it's references.
Once populated, ClassMetadata instances are usually cached in a serialized form.
IMPORTANT NOTE:
The fields of this class are only public for 2 reasons: 1) To allow fast READ access. 2) To drastically reduce the size of a serialized instance (private/protected members get the whole class name, namespace inclusive, prepended to every property in the serialized representation).
Constants
GENERATOR_TYPE_AUTO |
AUTO means Doctrine will automatically create a new \MongoDB\BSON\ObjectId instance for us. |
GENERATOR_TYPE_INCREMENT |
INCREMENT means a separate collection is used for maintaining and incrementing id generation. Offers full portability. |
GENERATOR_TYPE_UUID |
UUID means Doctrine will generate a uuid for us. |
GENERATOR_TYPE_ALNUM |
ALNUM means Doctrine will generate Alpha-numeric string identifiers, using the INCREMENT generator to ensure identifier uniqueness |
GENERATOR_TYPE_CUSTOM |
CUSTOM means Doctrine expect a class parameter. It will then try to initiate that class and pass other options to the generator. It will throw an Exception if the class does not exist or if an option was passed for that there is not setter in the new generator class. The class will have to be a subtype of AbstractIdGenerator. |
GENERATOR_TYPE_NONE |
NONE means Doctrine will not generate any id for us and you are responsible for manually assigning an id. |
DEFAULT_DISCRIMINATOR_FIELD |
Default discriminator field name. This is used for associations value for associations where a that do not define a "targetDocument" or "discriminatorField" option in their mapping. |
REFERENCE_ONE |
|
REFERENCE_MANY |
|
EMBED_ONE |
|
EMBED_MANY |
|
MANY |
|
ONE |
|
REFERENCE_STORE_AS_ID |
The types of storeAs references |
REFERENCE_STORE_AS_DB_REF |
|
REFERENCE_STORE_AS_DB_REF_WITH_DB |
|
REFERENCE_STORE_AS_REF |
|
INHERITANCE_TYPE_NONE |
NONE means the class does not participate in an inheritance hierarchy and therefore does not need an inheritance mapping type. |
INHERITANCE_TYPE_SINGLE_COLLECTION |
SINGLE_COLLECTION means the class will be persisted according to the rules of Single Collection Inheritance. |
INHERITANCE_TYPE_COLLECTION_PER_CLASS |
COLLECTION_PER_CLASS means the class will be persisted according to the rules of Concrete Collection Inheritance. |
CHANGETRACKING_DEFERRED_IMPLICIT |
DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time by doing a property-by-property comparison with the original data. This will be done for all entities that are in MANAGED state at commit-time. This is the default change tracking policy. |
CHANGETRACKING_DEFERRED_EXPLICIT |
DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time by doing a property-by-property comparison with the original data. This will be done only for entities that were explicitly saved (through persist() or a cascade). |
CHANGETRACKING_NOTIFY |
NOTIFY means that Doctrine relies on the entities sending out notifications when their properties change. Such entity classes must implement the NotifyPropertyChanged interface. |
STORAGE_STRATEGY_SET |
SET means that fields will be written to the database using a $set operator |
STORAGE_STRATEGY_INCREMENT |
INCREMENT means that fields will be written to the database by calculating the difference and using the $inc operator |
STORAGE_STRATEGY_PUSH_ALL |
|
STORAGE_STRATEGY_ADD_TO_SET |
|
STORAGE_STRATEGY_ATOMIC_SET |
|
STORAGE_STRATEGY_ATOMIC_SET_ARRAY |
|
STORAGE_STRATEGY_SET_ARRAY |
|
ALLOWED_GRIDFS_FIELDS |
|
Properties
string|null | $db | READ-ONLY: The name of the mongo database the document is mapped to. | |
string | $collection | READ-ONLY: The name of the mongo collection the document is mapped to. | |
string | $bucketName | READ-ONLY: The name of the GridFS bucket the document is mapped to. | |
bool | $collectionCapped | READ-ONLY: If the collection should be a fixed size. | |
int|null | $collectionSize | READ-ONLY: If the collection is fixed size, its size in bytes. | |
int|null | $collectionMax | READ-ONLY: If the collection is fixed size, the maximum number of elements to store in the collection. | |
string|null | $readPreference | READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set. | |
string[][] | $readPreferenceTags | READ-ONLY Associated with readPreference Allows to specify criteria so that your application can target read operations to specific members, based on custom parameters. | |
string|int|null | $writeConcern | READ-ONLY: Describes the level of acknowledgement requested from MongoDB for write operations. | |
string|null | $identifier | READ-ONLY: The field name of the document identifier. | |
array | $indexes | READ-ONLY: The array of indexes for the document collection. | |
array |
$shardKey | READ-ONLY: Keys and options describing shard key. Only for sharded collections. | |
string | $name | READ-ONLY: The name of the document class. | |
string | $rootDocumentName | READ-ONLY: The name of the document class that is at the root of the mapped document inheritance hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same as {@link $documentName}. | |
string|null | $customRepositoryClassName | The name of the custom repository class used for the document class. | |
array | $parentClasses | READ-ONLY: The names of the parent classes (ancestors). | |
array | $subClasses | READ-ONLY: The names of all subclasses (descendants). | |
ReflectionProperty[] | $reflFields | The ReflectionProperty instances of the mapped class. | |
int | $inheritanceType | READ-ONLY: The inheritance mapping type used by the class. | |
int | $generatorType | READ-ONLY: The Id generator type used by the class. | |
array | $generatorOptions | READ-ONLY: The Id generator options. | |
AbstractIdGenerator|null | $idGenerator | READ-ONLY: The ID generator used for generating IDs for this class. | |
array | $fieldMappings | READ-ONLY: The field mappings of the class. | |
array | $associationMappings | READ-ONLY: The association mappings of the class. | |
array | $alsoLoadMethods | READ-ONLY: Array of fields to also load with a given method. | |
array | $lifecycleCallbacks | READ-ONLY: The registered lifecycle callbacks for documents of this class. | |
mixed | $discriminatorValue | READ-ONLY: The discriminator value of this class. | |
mixed | $discriminatorMap | READ-ONLY: The discriminator map of all mapped classes in the hierarchy. | |
string|null | $discriminatorField | READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION inheritance mapping. | |
string|null | $defaultDiscriminatorValue | READ-ONLY: The default value for discriminatorField in case it's not set in the document | |
bool | $isMappedSuperclass | READ-ONLY: Whether this class describes the mapping of a mapped superclass. | |
bool | $isEmbeddedDocument | READ-ONLY: Whether this class describes the mapping of a embedded document. | |
bool | $isQueryResultDocument | READ-ONLY: Whether this class describes the mapping of an aggregation result document. | |
bool | $isFile | READ-ONLY: Whether this class describes the mapping of a gridFS file | |
int|null | $chunkSizeBytes | READ-ONLY: The default chunk size in bytes for the file | |
int | $changeTrackingPolicy | READ-ONLY: The policy used for change-tracking on entities of this class. | |
bool | $isVersioned | READ-ONLY: A flag for whether or not instances of this class are to be versioned with optimistic locking. | |
string|null | $versionField | READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). | |
bool | $isLockable | READ-ONLY: A flag for whether or not instances of this class are to allow pessimistic locking. | |
mixed | $lockField | READ-ONLY: The name of the field which is used for locking a document. | |
ReflectionClass | $reflClass | The ReflectionClass instance of the mapped class. | |
bool | $isReadOnly | READ_ONLY: A flag for whether or not this document is read-only. |
Methods
Initializes a new ClassMetadata instance that will hold the object-document mapping metadata of the class with the given name.
Helper method to get reference id of ref* type references
Returns a fully qualified field name for a given reference
{@inheritDoc}
{@inheritDoc}
INTERNAL: Sets the mapped identifier field of this class.
{@inheritDoc}
Since MongoDB only allows exactly one identifier field this will always return an array with only one value
{@inheritDoc}
Sets the inheritance type used by the class and it's subclasses.
Checks whether a mapped field is inherited from an entity superclass.
Registers a custom repository class for the document class.
Dispatches the lifecycle event of the given document by invoking all registered callbacks.
Checks whether the class has callbacks registered for a lifecycle event.
Gets the registered lifecycle callbacks for an event.
Adds a lifecycle callback for documents of this class.
Sets the lifecycle callbacks for documents of this class.
Registers a method for loading document data before field hydration.
Sets the AlsoLoad methods for documents of this class.
Sets the discriminator field.
Sets the discriminator values used by this class.
Sets the default discriminator value to be used for this class Used for SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value
Sets the discriminator value for this class.
Add a index for this Document.
Returns the array of indexes for this Document.
Checks whether this document has indexes or not.
Set shard key for this Document.
No description
Checks whether this document has shard key or not.
Sets the read preference used by this class.
Sets the write concern used by this class.
No description
Whether there is a write concern configured for this class.
Sets the change tracking policy used by this class.
Whether the change tracking policy of this class is "deferred explicit".
Whether the change tracking policy of this class is "deferred implicit".
Whether the change tracking policy of this class is "notify".
Gets the ReflectionProperties of the mapped class.
Gets a ReflectionProperty for a specific field of the mapped class.
{@inheritDoc}
Returns the database this Document is mapped to.
Set the database this Document is mapped to.
Get the collection this Document is mapped to.
Sets the collection this Document is mapped to.
No description
No description
No description
No description
Get whether or not the documents collection is capped.
Set whether or not the documents collection is capped.
Get the collection size
Set the collection size.
Get the collection max.
Set the collection max.
Returns TRUE if this Document is mapped to a collection FALSE otherwise.
Map a single embedded document.
Map a collection of embedded documents.
Map a single document reference.
Map a collection of document references.
INTERNAL: Adds a field mapping without completing/validating it.
INTERNAL: Adds an association mapping without completing/validating it.
Checks whether the class has a mapped association with the given field name.
Checks whether the class has a mapped embed with the given field name.
{@inheritDoc}
{@inheritDoc}
{@inheritDoc}
Checks whether the class has a mapped association for the specified field and if yes, checks whether it is a single-valued association (to-one).
Checks whether the class has a mapped association for the specified field and if yes, checks whether it is a collection-valued association (to-many).
Checks whether the class has a mapped embedded document for the specified field and if yes, checks whether it is a single-valued association (to-one).
Checks whether the class has a mapped embedded document for the specified field and if yes, checks whether it is a collection-valued association (to-many).
Sets the ID generator used to generate IDs for instances of this class.
Casts the identifier to its portable PHP type.
Casts the identifier to its database type.
Sets the document identifier of a document.
Gets the document identifier as a PHP type.
{@inheritDoc}
Get the document identifier object as a database type.
Sets the specified field to the specified value on the given document.
Gets the specified field's value off the given document.
Gets the mapping of a field.
Gets mappings of fields holding embedded document(s).
Gets the field mapping by its DB name.
Check if the field is not null.
Checks whether the document has a discriminator field and value configured.
Sets the type of Id generator to use for the mapped class.
Sets the Id generator options.
No description
Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy.
Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy.
Sets the mapped subclasses of this class.
Sets the parent class names.
Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us.
Checks whether the class will use a collection to generate incremented identifiers.
Checks whether the class will generate a uuid id.
Checks whether the class uses no id generator.
Sets the version field mapping used for versioning. Sets the default value to use depending on the column type.
Sets whether this class is to be versioned for optimistic locking.
Sets the name of the field that is to be used for versioning if this class is versioned for optimistic locking.
Sets the version field mapping used for versioning. Sets the default value to use depending on the column type.
Sets whether this class is to allow pessimistic locking.
Sets the name of the field that is to be used for storing whether a document is currently locked or not.
Marks this class as read only, no change tracking is applied to it.
{@inheritDoc}
{@inheritDoc}
{@inheritDoc}
{@inheritDoc}
Retrieve the collectionClass associated with an association
{@inheritDoc}
{@inheritDoc}
Map a field.
Determines which fields get serialized.
Restores some state that can not be serialized/unserialized.
Creates a new instance of the mapped class, without invoking the constructor.
Details
at line 508
__construct(string $documentName)
Initializes a new ClassMetadata instance that will hold the object-document mapping metadata of the class with the given name.
at line 526
static mixed
getReferenceId($reference, string $storeAs)
Helper method to get reference id of ref* type references
at line 550
static
getReferenceFieldName(string $storeAs, string $pathPrefix = '')
Returns a fully qualified field name for a given reference
at line 562
getReflectionClass()
{@inheritDoc}
at line 570
isIdentifier($fieldName)
{@inheritDoc}
at line 579
setIdentifier(string|null $identifier)
INTERNAL: Sets the mapped identifier field of this class.
at line 590
getIdentifier()
{@inheritDoc}
Since MongoDB only allows exactly one identifier field this will always return an array with only one value
at line 601
getIdentifierFieldNames()
Since MongoDB only allows exactly one identifier field this will always return an array with only one value
return (string|null)[]
at line 609
hasField($fieldName)
{@inheritDoc}
at line 617
setInheritanceType(int $type)
Sets the inheritance type used by the class and it's subclasses.
at line 625
isInheritedField(string $fieldName)
Checks whether a mapped field is inherited from an entity superclass.
at line 633
setCustomRepositoryClass(string|null $repositoryClassName)
Registers a custom repository class for the document class.
at line 649
invokeLifecycleCallbacks(string $event, object $document, array|null $arguments = null)
Dispatches the lifecycle event of the given document by invoking all registered callbacks.
at line 671
hasLifecycleCallbacks(string $event)
Checks whether the class has callbacks registered for a lifecycle event.
at line 679
getLifecycleCallbacks(string $event)
Gets the registered lifecycle callbacks for an event.
at line 689
addLifecycleCallback(string $callback, string $event)
Adds a lifecycle callback for documents of this class.
If the callback is already registered, this is a NOOP.
at line 703
setLifecycleCallbacks(array $callbacks)
Sets the lifecycle callbacks for documents of this class.
Any previously registered callbacks are overwritten.
at line 716
registerAlsoLoadMethod(string $method, $fields)
Registers a method for loading document data before field hydration.
Note: A method may be registered multiple times for different fields. it will be invoked only once for the first field found.
at line 726
setAlsoLoadMethods(array $methods)
Sets the AlsoLoad methods for documents of this class.
Any previously registered methods are overwritten.
at line 743
setDiscriminatorField(array|string|null $discriminatorField)
Sets the discriminator field.
The field name is the the unmapped database field. Discriminator values are only used to discern the hydration class and are not mapped to class properties.
at line 780
setDiscriminatorMap(array $map)
Sets the discriminator values used by this class.
Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
at line 807
setDefaultDiscriminatorValue(string|null $defaultDiscriminatorValue)
Sets the default discriminator value to be used for this class Used for SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value
at line 833
setDiscriminatorValue(string $value)
Sets the discriminator value for this class.
Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single collection.
at line 846
addIndex(array $keys, array $options = [])
Add a index for this Document.
at line 872
getIndexes()
Returns the array of indexes for this Document.
at line 880
hasIndexes()
Checks whether this document has indexes or not.
at line 890
setShardKey(array $keys, array $options = [])
Set shard key for this Document.
at line 935
getShardKey()
at line 943
isSharded()
Checks whether this document has shard key or not.
at line 951
setReadPreference(string|null $readPreference, array $tags)
Sets the read preference used by this class.
at line 962
setWriteConcern(string|int|null $writeConcern)
Sets the write concern used by this class.
at line 970
int|string|null
getWriteConcern()
at line 978
hasWriteConcern()
Whether there is a write concern configured for this class.
at line 986
setChangeTrackingPolicy(int $policy)
Sets the change tracking policy used by this class.
at line 994
isChangeTrackingDeferredExplicit()
Whether the change tracking policy of this class is "deferred explicit".
at line 1002
isChangeTrackingDeferredImplicit()
Whether the change tracking policy of this class is "deferred implicit".
at line 1010
isChangeTrackingNotify()
Whether the change tracking policy of this class is "notify".
at line 1018
getReflectionProperties()
Gets the ReflectionProperties of the mapped class.
at line 1026
getReflectionProperty(string $name)
Gets a ReflectionProperty for a specific field of the mapped class.
at line 1034
getName()
{@inheritDoc}
at line 1042
getDatabase()
Returns the database this Document is mapped to.
at line 1050
setDatabase(string|null $db)
Set the database this Document is mapped to.
at line 1058
getCollection()
Get the collection this Document is mapped to.
at line 1070
setCollection(array|string $name)
Sets the collection this Document is mapped to.
at line 1085
getBucketName()
at line 1090
setBucketName(string $bucketName)
at line 1096
getChunkSizeBytes()
at line 1101
setChunkSizeBytes(int $chunkSizeBytes)
at line 1109
getCollectionCapped()
Get whether or not the documents collection is capped.
at line 1117
setCollectionCapped(bool $bool)
Set whether or not the documents collection is capped.
at line 1125
getCollectionSize()
Get the collection size
at line 1133
setCollectionSize(int $size)
Set the collection size.
at line 1141
getCollectionMax()
Get the collection max.
at line 1149
setCollectionMax(int $max)
Set the collection max.
at line 1157
isMappedToCollection()
Returns TRUE if this Document is mapped to a collection FALSE otherwise.
at line 1214
mapOneEmbedded(array $mapping)
Map a single embedded document.
at line 1224
mapManyEmbedded(array $mapping)
Map a collection of embedded documents.
at line 1234
mapOneReference(array $mapping)
Map a single document reference.
at line 1244
mapManyReference(array $mapping)
Map a collection of document references.
at line 1256
addInheritedFieldMapping(array $fieldMapping)
INTERNAL: Adds a field mapping without completing/validating it.
This is mainly used to add inherited field mappings to derived classes.
at line 1274
addInheritedAssociationMapping(array $mapping)
INTERNAL: Adds an association mapping without completing/validating it.
This is mainly used to add inherited association mappings to derived classes.
at line 1282
hasReference(string $fieldName)
Checks whether the class has a mapped association with the given field name.
at line 1290
hasEmbed(string $fieldName)
Checks whether the class has a mapped embed with the given field name.
at line 1300
hasAssociation($fieldName)
{@inheritDoc}
Checks whether the class has a mapped association (embed or reference) with the given field name.
at line 1311
isSingleValuedAssociation($fieldName)
{@inheritDoc}
Checks whether the class has a mapped reference or embed for the specified field and is a single valued association.
at line 1322
isCollectionValuedAssociation($fieldName)
{@inheritDoc}
Checks whether the class has a mapped reference or embed for the specified field and is a collection valued association.
at line 1331
isSingleValuedReference(string $fieldName)
Checks whether the class has a mapped association for the specified field and if yes, checks whether it is a single-valued association (to-one).
at line 1341
isCollectionValuedReference(string $fieldName)
Checks whether the class has a mapped association for the specified field and if yes, checks whether it is a collection-valued association (to-many).
at line 1351
isSingleValuedEmbed(string $fieldName)
Checks whether the class has a mapped embedded document for the specified field and if yes, checks whether it is a single-valued association (to-one).
at line 1361
isCollectionValuedEmbed(string $fieldName)
Checks whether the class has a mapped embedded document for the specified field and if yes, checks whether it is a collection-valued association (to-many).
at line 1370
setIdGenerator(AbstractIdGenerator $generator)
Sets the ID generator used to generate IDs for instances of this class.
at line 1382
mixed
getPHPIdentifierValue(mixed $id)
Casts the identifier to its portable PHP type.
at line 1395
mixed
getDatabaseIdentifierValue(mixed $id)
Casts the identifier to its database type.
at line 1408
setIdentifierValue(object $document, $id)
Sets the document identifier of a document.
The value will be converted to a PHP type before being set.
at line 1419
mixed
getIdentifierValue(object $document)
Gets the document identifier as a PHP type.
at line 1431
getIdentifierValues($object)
{@inheritDoc}
Since MongoDB only allows exactly one identifier field this is a proxy to {see getIdentifierValue()} and returns an array with the identifier field as a key.
at line 1441
mixed
getIdentifierObject(object $document)
Get the document identifier object as a database type.
at line 1451
setFieldValue(object $document, string $field, $value)
Sets the specified field to the specified value on the given document.
at line 1467
mixed
getFieldValue(object $document, string $field)
Gets the specified field's value off the given document.
at line 1481
getFieldMapping(string $fieldName)
Gets the mapping of a field.
at line 1492
getEmbeddedFieldsMappings()
Gets mappings of fields holding embedded document(s).
at line 1508
getFieldMappingByDbFieldName(string $dbFieldName)
Gets the field mapping by its DB name.
E.g. it returns identifier's mapping when called with _id.
at line 1522
isNullable(string $fieldName)
Check if the field is not null.
at line 1531
hasDiscriminator()
Checks whether the document has a discriminator field and value configured.
at line 1539
setIdGeneratorType(int $generatorType)
Sets the type of Id generator to use for the mapped class.
at line 1547
setIdGeneratorOptions(array $generatorOptions)
Sets the Id generator options.
at line 1552
isInheritanceTypeNone()
at line 1560
isInheritanceTypeSingleCollection()
Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy.
at line 1568
isInheritanceTypeCollectionPerClass()
Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy.
at line 1578
setSubclasses(array $subclasses)
Sets the mapped subclasses of this class.
at line 1592
setParentClasses(array $classNames)
Sets the parent class names.
Assumes that the class names in the passed array are in the order: directParent -> directParentParent -> directParentParentParent ... -> root.
at line 1606
isIdGeneratorAuto()
Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us.
at line 1614
isIdGeneratorIncrement()
Checks whether the class will use a collection to generate incremented identifiers.
at line 1622
isIdGeneratorUuid()
Checks whether the class will generate a uuid id.
at line 1630
isIdGeneratorNone()
Checks whether the class uses no id generator.
at line 1641
setVersionMapping(array $mapping)
Sets the version field mapping used for versioning. Sets the default value to use depending on the column type.
at line 1654
setVersioned(bool $bool)
Sets whether this class is to be versioned for optimistic locking.
at line 1663
setVersionField(string|null $versionField)
Sets the name of the field that is to be used for versioning if this class is versioned for optimistic locking.
at line 1674
setLockMapping(array $mapping)
Sets the version field mapping used for versioning. Sets the default value to use depending on the column type.
at line 1687
setLockable(bool $bool)
Sets whether this class is to allow pessimistic locking.
at line 1696
setLockField(string $lockField)
Sets the name of the field that is to be used for storing whether a document is currently locked or not.
at line 1704
markReadOnly()
Marks this class as read only, no change tracking is applied to it.
at line 1712
getFieldNames()
{@inheritDoc}
at line 1720
getAssociationNames()
{@inheritDoc}
at line 1728
getTypeOfField($fieldName)
{@inheritDoc}
at line 1737
getAssociationTargetClass($assocName)
{@inheritDoc}
at line 1749
getAssociationCollectionClass(string $assocName)
Retrieve the collectionClass associated with an association
at line 1765
isAssociationInverseSide($fieldName)
{@inheritDoc}
at line 1773
getAssociationMappedByTargetField($fieldName)
{@inheritDoc}
at line 1783
mapField(array $mapping)
Map a field.
at line 1960
array
__sleep()
Determines which fields get serialized.
It is only serialized what is necessary for best unserialization performance. That means any metadata properties that are not set or empty or simply have their default value are NOT serialized.
Parts that are also NOT serialized because they can not be properly unserialized: - reflClass (ReflectionClass) - reflFields (ReflectionProperty array)
at line 2043
__wakeup()
Restores some state that can not be serialized/unserialized.
at line 2063
newInstance()
Creates a new instance of the mapped class, without invoking the constructor.