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|null $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|int|null $readPreference READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set.
string[][]|null $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.
string|null $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 $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 $discriminatorField READ-ONLY: The definition of the discriminator field used in SINGLE_COLLECTION inheritance mapping.
string $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

__construct(string $documentName)

Initializes a new ClassMetadata instance that will hold the object-document mapping metadata of the class with the given name.

static mixed
getReferenceId($reference, string $storeAs)

Helper method to get reference id of ref* type references

static 
getReferenceFieldName(string $storeAs, string $pathPrefix = '')

Returns a fully qualified field name for a given reference

getReflectionClass()

{@inheritDoc}

isIdentifier($fieldName)

{@inheritDoc}

setIdentifier(string|null $identifier)

INTERNAL: Sets the mapped identifier field of this class.

getIdentifier()

{@inheritDoc}

getIdentifierFieldNames()

{@inheritDoc}

hasField($fieldName)

{@inheritDoc}

setInheritanceType(int $type)

Sets the inheritance type used by the class and it's subclasses.

isInheritedField(string $fieldName)

Checks whether a mapped field is inherited from an entity superclass.

setCustomRepositoryClass(string|null $repositoryClassName)

Registers a custom repository class for the document class.

invokeLifecycleCallbacks(string $event, object $document, array|null $arguments = null)

Dispatches the lifecycle event of the given document by invoking all registered callbacks.

hasLifecycleCallbacks(string $event)

Checks whether the class has callbacks registered for a lifecycle event.

getLifecycleCallbacks(string $event)

Gets the registered lifecycle callbacks for an event.

addLifecycleCallback(string $callback, string $event)

Adds a lifecycle callback for documents of this class.

setLifecycleCallbacks(array $callbacks)

Sets the lifecycle callbacks for documents of this class.

registerAlsoLoadMethod(string $method, $fields)

Registers a method for loading document data before field hydration.

setAlsoLoadMethods(array $methods)

Sets the AlsoLoad methods for documents of this class.

setDiscriminatorField(string|array $discriminatorField)

Sets the discriminator field.

setDiscriminatorMap(array $map)

Sets the discriminator values used by this class.

setDefaultDiscriminatorValue(string|null $defaultDiscriminatorValue)

Sets the default discriminator value to be used for this class Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value

setDiscriminatorValue(string $value)

Sets the discriminator value for this class.

addIndex(array $keys, array $options = [])

Add a index for this Document.

getIndexes()

Returns the array of indexes for this Document.

hasIndexes()

Checks whether this document has indexes or not.

setShardKey(array $keys, array $options = [])

Set shard key for this Document.

getShardKey()

No description

isSharded()

Checks whether this document has shard key or not.

setReadPreference(null|string|int $readPreference, array|null $tags)

Sets the read preference used by this class.

setWriteConcern(string|int|null $writeConcern)

Sets the write concern used by this class.

int|null|string
getWriteConcern()

No description

hasWriteConcern()

Whether there is a write concern configured for this class.

setChangeTrackingPolicy(int $policy)

Sets the change tracking policy used by this class.

isChangeTrackingDeferredExplicit()

Whether the change tracking policy of this class is "deferred explicit".

isChangeTrackingDeferredImplicit()

Whether the change tracking policy of this class is "deferred implicit".

isChangeTrackingNotify()

Whether the change tracking policy of this class is "notify".

getReflectionProperties()

Gets the ReflectionProperties of the mapped class.

getReflectionProperty(string $name)

Gets a ReflectionProperty for a specific field of the mapped class.

getName()

{@inheritDoc}

getDatabase()

Returns the database this Document is mapped to.

setDatabase(string|null $db)

Set the database this Document is mapped to.

getCollection()

Get the collection this Document is mapped to.

setCollection(array|string $name)

Sets the collection this Document is mapped to.

getBucketName()

No description

setBucketName(string $bucketName)

No description

getChunkSizeBytes()

No description

setChunkSizeBytes(int $chunkSizeBytes)

No description

getCollectionCapped()

Get whether or not the documents collection is capped.

setCollectionCapped(bool $bool)

Set whether or not the documents collection is capped.

getCollectionSize()

Get the collection size

setCollectionSize(int $size)

Set the collection size.

getCollectionMax()

Get the collection max.

setCollectionMax(int $max)

Set the collection max.

isMappedToCollection()

Returns TRUE if this Document is mapped to a collection FALSE otherwise.

mapOneEmbedded(array $mapping)

Map a single embedded document.

mapManyEmbedded(array $mapping)

Map a collection of embedded documents.

mapOneReference(array $mapping)

Map a single document reference.

mapManyReference(array $mapping)

Map a collection of document references.

addInheritedFieldMapping(array $fieldMapping)

INTERNAL: Adds a field mapping without completing/validating it.

addInheritedAssociationMapping(array $mapping)

INTERNAL: Adds an association mapping without completing/validating it.

hasReference(string $fieldName)

Checks whether the class has a mapped association with the given field name.

hasEmbed(string $fieldName)

Checks whether the class has a mapped embed with the given field name.

hasAssociation($fieldName)

{@inheritDoc}

isSingleValuedAssociation($fieldName)

{@inheritDoc}

isCollectionValuedAssociation($fieldName)

{@inheritDoc}

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).

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).

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).

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).

setIdGenerator(AbstractIdGenerator $generator)

Sets the ID generator used to generate IDs for instances of this class.

mixed
getPHPIdentifierValue(mixed $id)

Casts the identifier to its portable PHP type.

mixed
getDatabaseIdentifierValue(mixed $id)

Casts the identifier to its database type.

setIdentifierValue(object $document, $id)

Sets the document identifier of a document.

mixed
getIdentifierValue(object $document)

Gets the document identifier as a PHP type.

getIdentifierValues($object)

{@inheritDoc}

mixed
getIdentifierObject(object $document)

Get the document identifier object as a database type.

setFieldValue(object $document, string $field, $value)

Sets the specified field to the specified value on the given document.

mixed
getFieldValue(object $document, string $field)

Gets the specified field's value off the given document.

getFieldMapping(string $fieldName)

Gets the mapping of a field.

getEmbeddedFieldsMappings()

Gets mappings of fields holding embedded document(s).

getFieldMappingByDbFieldName(string $dbFieldName)

Gets the field mapping by its DB name.

isNullable(string $fieldName)

Check if the field is not null.

hasDiscriminator()

Checks whether the document has a discriminator field and value configured.

setIdGeneratorType(int $generatorType)

Sets the type of Id generator to use for the mapped class.

setIdGeneratorOptions(array $generatorOptions)

Sets the Id generator options.

isInheritanceTypeNone()

No description

isInheritanceTypeSingleCollection()

Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy.

isInheritanceTypeCollectionPerClass()

Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy.

setSubclasses(array $subclasses)

Sets the mapped subclasses of this class.

setParentClasses(array $classNames)

Sets the parent class names.

isIdGeneratorAuto()

Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us.

isIdGeneratorIncrement()

Checks whether the class will use a collection to generate incremented identifiers.

isIdGeneratorUuid()

Checks whether the class will generate a uuid id.

isIdGeneratorNone()

Checks whether the class uses no id generator.

setVersionMapping(array $mapping)

Sets the version field mapping used for versioning. Sets the default value to use depending on the column type.

setVersioned(bool $bool)

Sets whether this class is to be versioned for optimistic locking.

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.

setLockMapping(array $mapping)

Sets the version field mapping used for versioning. Sets the default value to use depending on the column type.

setLockable(bool $bool)

Sets whether this class is to allow pessimistic locking.

setLockField(string $lockField)

Sets the name of the field that is to be used for storing whether a document is currently locked or not.

markReadOnly()

Marks this class as read only, no change tracking is applied to it.

getFieldNames()

{@inheritDoc}

getAssociationNames()

{@inheritDoc}

getTypeOfField($fieldName)

{@inheritDoc}

getAssociationTargetClass($assocName)

{@inheritDoc}

getAssociationCollectionClass(string $assocName)

Retrieve the collectionClass associated with an association

isAssociationInverseSide($fieldName)

{@inheritDoc}

getAssociationMappedByTargetField($fieldName)

{@inheritDoc}

mapField(array $mapping)

Map a field.

array
__sleep()

Determines which fields get serialized.

__wakeup()

Restores some state that can not be serialized/unserialized.

newInstance()

Creates a new instance of the mapped class, without invoking the constructor.

Details

__construct(string $documentName)

Initializes a new ClassMetadata instance that will hold the object-document mapping metadata of the class with the given name.

Parameters

string $documentName

static mixed getReferenceId($reference, string $storeAs)

Helper method to get reference id of ref* type references

Parameters

$reference
string $storeAs

Return Value

mixed

static getReferenceFieldName(string $storeAs, string $pathPrefix = '')

Returns a fully qualified field name for a given reference

Parameters

string $storeAs
string $pathPrefix

getReflectionClass()

{@inheritDoc}

isIdentifier($fieldName)

{@inheritDoc}

Parameters

$fieldName

setIdentifier(string|null $identifier)

INTERNAL: Sets the mapped identifier field of this class.

Parameters

string|null $identifier

getIdentifier()

{@inheritDoc}

Since MongoDB only allows exactly one identifier field this will always return an array with only one value

getIdentifierFieldNames()

{@inheritDoc}

Since MongoDB only allows exactly one identifier field this will always return an array with only one value

hasField($fieldName)

{@inheritDoc}

Parameters

$fieldName

setInheritanceType(int $type)

Sets the inheritance type used by the class and it's subclasses.

Parameters

int $type

isInheritedField(string $fieldName)

Checks whether a mapped field is inherited from an entity superclass.

Parameters

string $fieldName

setCustomRepositoryClass(string|null $repositoryClassName)

Registers a custom repository class for the document class.

Parameters

string|null $repositoryClassName

invokeLifecycleCallbacks(string $event, object $document, array|null $arguments = null)

Dispatches the lifecycle event of the given document by invoking all registered callbacks.

Parameters

string $event
object $document
array|null $arguments

Exceptions

InvalidArgumentException If document class is not this class or a Proxy of this class.

hasLifecycleCallbacks(string $event)

Checks whether the class has callbacks registered for a lifecycle event.

Parameters

string $event

getLifecycleCallbacks(string $event)

Gets the registered lifecycle callbacks for an event.

Parameters

string $event

addLifecycleCallback(string $callback, string $event)

Adds a lifecycle callback for documents of this class.

If the callback is already registered, this is a NOOP.

Parameters

string $callback
string $event

setLifecycleCallbacks(array $callbacks)

Sets the lifecycle callbacks for documents of this class.

Any previously registered callbacks are overwritten.

Parameters

array $callbacks

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.

Parameters

string $method
$fields

setAlsoLoadMethods(array $methods)

Sets the AlsoLoad methods for documents of this class.

Any previously registered methods are overwritten.

Parameters

array $methods

setDiscriminatorField(string|array $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.

Parameters

string|array $discriminatorField

Exceptions

MappingException If the discriminator field conflicts with the "name" attribute of a mapped field.

setDiscriminatorMap(array $map)

Sets the discriminator values used by this class.

Used for JOINED and SINGLE_TABLE inheritance mapping strategies.

Parameters

array $map

Exceptions

MappingException

setDefaultDiscriminatorValue(string|null $defaultDiscriminatorValue)

Sets the default discriminator value to be used for this class Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value

Parameters

string|null $defaultDiscriminatorValue

Exceptions

MappingException

setDiscriminatorValue(string $value)

Sets the discriminator value for this class.

Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single collection.

Parameters

string $value

Exceptions

MappingException

addIndex(array $keys, array $options = [])

Add a index for this Document.

Parameters

array $keys
array $options

getIndexes()

Returns the array of indexes for this Document.

hasIndexes()

Checks whether this document has indexes or not.

setShardKey(array $keys, array $options = [])

Set shard key for this Document.

Parameters

array $keys
array $options

Exceptions

MappingException

getShardKey()

isSharded()

Checks whether this document has shard key or not.

setReadPreference(null|string|int $readPreference, array|null $tags)

Sets the read preference used by this class.

Parameters

null|string|int $readPreference
array|null $tags

setWriteConcern(string|int|null $writeConcern)

Sets the write concern used by this class.

Parameters

string|int|null $writeConcern

int|null|string getWriteConcern()

Return Value

int|null|string

hasWriteConcern()

Whether there is a write concern configured for this class.

setChangeTrackingPolicy(int $policy)

Sets the change tracking policy used by this class.

Parameters

int $policy

isChangeTrackingDeferredExplicit()

Whether the change tracking policy of this class is "deferred explicit".

isChangeTrackingDeferredImplicit()

Whether the change tracking policy of this class is "deferred implicit".

isChangeTrackingNotify()

Whether the change tracking policy of this class is "notify".

getReflectionProperties()

Gets the ReflectionProperties of the mapped class.

getReflectionProperty(string $name)

Gets a ReflectionProperty for a specific field of the mapped class.

Parameters

string $name

getName()

{@inheritDoc}

getDatabase()

Returns the database this Document is mapped to.

setDatabase(string|null $db)

Set the database this Document is mapped to.

Parameters

string|null $db

getCollection()

Get the collection this Document is mapped to.

setCollection(array|string $name)

Sets the collection this Document is mapped to.

Parameters

array|string $name

Exceptions

InvalidArgumentException

getBucketName()

setBucketName(string $bucketName)

Parameters

string $bucketName

getChunkSizeBytes()

setChunkSizeBytes(int $chunkSizeBytes)

Parameters

int $chunkSizeBytes

getCollectionCapped()

Get whether or not the documents collection is capped.

setCollectionCapped(bool $bool)

Set whether or not the documents collection is capped.

Parameters

bool $bool

getCollectionSize()

Get the collection size

setCollectionSize(int $size)

Set the collection size.

Parameters

int $size

getCollectionMax()

Get the collection max.

setCollectionMax(int $max)

Set the collection max.

Parameters

int $max

isMappedToCollection()

Returns TRUE if this Document is mapped to a collection FALSE otherwise.

mapOneEmbedded(array $mapping)

Map a single embedded document.

Parameters

array $mapping

mapManyEmbedded(array $mapping)

Map a collection of embedded documents.

Parameters

array $mapping

mapOneReference(array $mapping)

Map a single document reference.

Parameters

array $mapping

mapManyReference(array $mapping)

Map a collection of document references.

Parameters

array $mapping

addInheritedFieldMapping(array $fieldMapping)

INTERNAL: Adds a field mapping without completing/validating it.

This is mainly used to add inherited field mappings to derived classes.

Parameters

array $fieldMapping

addInheritedAssociationMapping(array $mapping)

INTERNAL: Adds an association mapping without completing/validating it.

This is mainly used to add inherited association mappings to derived classes.

Parameters

array $mapping

Exceptions

MappingException

hasReference(string $fieldName)

Checks whether the class has a mapped association with the given field name.

Parameters

string $fieldName

hasEmbed(string $fieldName)

Checks whether the class has a mapped embed with the given field name.

Parameters

string $fieldName

hasAssociation($fieldName)

{@inheritDoc}

Checks whether the class has a mapped association (embed or reference) with the given field name.

Parameters

$fieldName

isSingleValuedAssociation($fieldName)

{@inheritDoc}

Checks whether the class has a mapped reference or embed for the specified field and is a single valued association.

Parameters

$fieldName

isCollectionValuedAssociation($fieldName)

{@inheritDoc}

Checks whether the class has a mapped reference or embed for the specified field and is a collection valued association.

Parameters

$fieldName

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).

Parameters

string $fieldName

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).

Parameters

string $fieldName

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).

Parameters

string $fieldName

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).

Parameters

string $fieldName

setIdGenerator(AbstractIdGenerator $generator)

Sets the ID generator used to generate IDs for instances of this class.

Parameters

AbstractIdGenerator $generator

mixed getPHPIdentifierValue(mixed $id)

Casts the identifier to its portable PHP type.

Parameters

mixed $id

Return Value

mixed $id

mixed getDatabaseIdentifierValue(mixed $id)

Casts the identifier to its database type.

Parameters

mixed $id

Return Value

mixed $id

setIdentifierValue(object $document, $id)

Sets the document identifier of a document.

The value will be converted to a PHP type before being set.

Parameters

object $document
$id

mixed getIdentifierValue(object $document)

Gets the document identifier as a PHP type.

Parameters

object $document

Return Value

mixed $id

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.

Parameters

$object

mixed getIdentifierObject(object $document)

Get the document identifier object as a database type.

Parameters

object $document

Return Value

mixed $id

setFieldValue(object $document, string $field, $value)

Sets the specified field to the specified value on the given document.

Parameters

object $document
string $field
$value

mixed getFieldValue(object $document, string $field)

Gets the specified field's value off the given document.

Parameters

object $document
string $field

Return Value

mixed

getFieldMapping(string $fieldName)

Gets the mapping of a field.

Parameters

string $fieldName

Exceptions

MappingException If the $fieldName is not found in the fieldMappings array.

getEmbeddedFieldsMappings()

Gets mappings of fields holding embedded document(s).

getFieldMappingByDbFieldName(string $dbFieldName)

Gets the field mapping by its DB name.

E.g. it returns identifier's mapping when called with _id.

Parameters

string $dbFieldName

Exceptions

MappingException

isNullable(string $fieldName)

Check if the field is not null.

Parameters

string $fieldName

hasDiscriminator()

Checks whether the document has a discriminator field and value configured.

setIdGeneratorType(int $generatorType)

Sets the type of Id generator to use for the mapped class.

Parameters

int $generatorType

setIdGeneratorOptions(array $generatorOptions)

Sets the Id generator options.

Parameters

array $generatorOptions

isInheritanceTypeNone()

isInheritanceTypeSingleCollection()

Checks whether the mapped class uses the SINGLE_COLLECTION inheritance mapping strategy.

isInheritanceTypeCollectionPerClass()

Checks whether the mapped class uses the COLLECTION_PER_CLASS inheritance mapping strategy.

setSubclasses(array $subclasses)

Sets the mapped subclasses of this class.

Parameters

array $subclasses The names of all mapped subclasses.

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.

Parameters

array $classNames

isIdGeneratorAuto()

Checks whether the class will generate a new \MongoDB\BSON\ObjectId instance for us.

isIdGeneratorIncrement()

Checks whether the class will use a collection to generate incremented identifiers.

isIdGeneratorUuid()

Checks whether the class will generate a uuid id.

isIdGeneratorNone()

Checks whether the class uses no id generator.

setVersionMapping(array $mapping)

Sets the version field mapping used for versioning. Sets the default value to use depending on the column type.

Parameters

array $mapping

Exceptions

LockException

setVersioned(bool $bool)

Sets whether this class is to be versioned for optimistic locking.

Parameters

bool $bool

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.

Parameters

string|null $versionField

setLockMapping(array $mapping)

Sets the version field mapping used for versioning. Sets the default value to use depending on the column type.

Parameters

array $mapping

Exceptions

LockException

setLockable(bool $bool)

Sets whether this class is to allow pessimistic locking.

Parameters

bool $bool

setLockField(string $lockField)

Sets the name of the field that is to be used for storing whether a document is currently locked or not.

Parameters

string $lockField

markReadOnly()

Marks this class as read only, no change tracking is applied to it.

getFieldNames()

{@inheritDoc}

getAssociationNames()

{@inheritDoc}

getTypeOfField($fieldName)

{@inheritDoc}

Parameters

$fieldName

getAssociationTargetClass($assocName)

{@inheritDoc}

Parameters

$assocName

getAssociationCollectionClass(string $assocName)

Retrieve the collectionClass associated with an association

Parameters

string $assocName

isAssociationInverseSide($fieldName)

{@inheritDoc}

Parameters

$fieldName

getAssociationMappedByTargetField($fieldName)

{@inheritDoc}

Parameters

$fieldName

mapField(array $mapping)

Map a field.

Parameters

array $mapping

Exceptions

MappingException

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)

Return Value

array The names of all the fields that should be serialized.

__wakeup()

Restores some state that can not be serialized/unserialized.

newInstance()

Creates a new instance of the mapped class, without invoking the constructor.