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

Properties

string $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.
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 $namespace READ-ONLY: The namespace the document class is contained in.
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 $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.
string $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.
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.
mixed $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(mixed $reference, string $storeAs)

Helper method to get reference id of ref* type references

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

Returns a fully qualified field name for a given reference

getReflectionClass()

{@inheritDoc}

isIdentifier($fieldName)

{@inheritDoc}

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

bool
isInheritedField(string $fieldName)

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

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

bool
hasLifecycleCallbacks(string $event)

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

array
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, array|string $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 $discriminatorField)

Sets the discriminator field.

setDiscriminatorMap(array $map)

Sets the discriminator values used by this class.

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

array
getIndexes()

Returns the array of indexes for this Document.

bool
hasIndexes()

Checks whether this document has indexes or not.

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

Set shard key for this Document.

array
getShardKey()

No description

bool
isSharded()

Checks whether this document has shard key or not.

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

Sets the read preference used by this class.

setWriteConcern(string $writeConcern)

Sets the write concern used by this class.

string
getWriteConcern()

No description

bool
hasWriteConcern()

Whether there is a write concern configured for this class.

setChangeTrackingPolicy(int $policy)

Sets the change tracking policy used by this class.

bool
isChangeTrackingDeferredExplicit()

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

bool
isChangeTrackingDeferredImplicit()

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

bool
isChangeTrackingNotify()

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

array
getReflectionProperties()

Gets the ReflectionProperties of the mapped class.

getReflectionProperty(string $name)

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

getName()

{@inheritDoc}

string
getNamespace()

The namespace this Document class belongs to.

string
getDatabase()

Returns the database this Document is mapped to.

setDatabase(string $db)

Set the database this Document is mapped to.

string
getCollection()

Get the collection this Document is mapped to.

setCollection(array|string $name)

Sets the collection this Document is mapped to.

bool
getCollectionCapped()

Get whether or not the documents collection is capped.

setCollectionCapped(bool $bool)

Set whether or not the documents collection is capped.

int
getCollectionSize()

Get the collection size

setCollectionSize(int $size)

Set the collection size.

int
getCollectionMax()

Get the collection max.

setCollectionMax(int $max)

Set the collection max.

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

bool
hasReference(string $fieldName)

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

bool
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}

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

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

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

bool
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, mixed $id)

Sets the document identifier of a document.

mixed
getIdentifierValue(object $document)

Gets the document identifier as a PHP type.

getIdentifierValues($object)

{@inheritDoc}

ObjectId
getIdentifierObject(object $document)

Get the document identifier object as a database type.

setFieldValue(object $document, string $field, mixed $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.

array
getFieldMapping(string $fieldName)

Gets the mapping of a field.

array
getEmbeddedFieldsMappings()

Gets mappings of fields holding embedded document(s).

array
getFieldMappingByDbFieldName(string $dbFieldName)

Gets the field mapping by its DB name.

bool
isNullable(string $fieldName)

Check if the field is not null.

bool
hasDiscriminator()

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

setIdGeneratorType(string $generatorType)

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

setIdGeneratorOptions(array $generatorOptions)

Sets the Id generator options.

bool
isInheritanceTypeNone()

No description

bool
isInheritanceTypeSingleCollection()

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

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

bool
isIdGeneratorAuto()

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

bool
isIdGeneratorIncrement()

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

bool
isIdGeneratorUuid()

Checks whether the class will generate a uuid id.

bool
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 $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}

array
mapField(array $mapping)

Map a field.

array
__sleep()

Determines which fields get serialized.

__wakeup()

Restores some state that can not be serialized/unserialized.

object
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 The name of the document class the new instance is used for.

static mixed getReferenceId(mixed $reference, string $storeAs)

Helper method to get reference id of ref* type references

Parameters

mixed $reference
string $storeAs

Return Value

mixed

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

Returns a fully qualified field name for a given reference

Parameters

string $storeAs
string $pathPrefix The field path prefix

Return Value

string

getReflectionClass()

{@inheritDoc}

isIdentifier($fieldName)

{@inheritDoc}

Parameters

$fieldName

setIdentifier(string $identifier)

INTERNAL: Sets the mapped identifier field of this class.

Parameters

string $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

bool isInheritedField(string $fieldName)

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

Parameters

string $fieldName

Return Value

bool TRUE if the field is inherited, FALSE otherwise.

setCustomRepositoryClass(string $repositoryClassName)

Registers a custom repository class for the document class.

Parameters

string $repositoryClassName The class name of the custom repository.

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 Lifecycle event
object $document Document on which the event occurred
array|null $arguments Arguments to pass to all callbacks

Exceptions

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

bool hasLifecycleCallbacks(string $event)

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

Parameters

string $event Lifecycle event

Return Value

bool

array getLifecycleCallbacks(string $event)

Gets the registered lifecycle callbacks for an event.

Parameters

string $event

Return Value

array

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, array|string $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 Method name
array|string $fields Database field name(s)

setAlsoLoadMethods(array $methods)

Sets the AlsoLoad methods for documents of this class.

Any previously registered methods are overwritten.

Parameters

array $methods

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

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

Add a index for this Document.

Parameters

array $keys Array of keys for the index.
array $options Array of options for the index.

array getIndexes()

Returns the array of indexes for this Document.

Return Value

array $indexes The array of indexes.

bool hasIndexes()

Checks whether this document has indexes or not.

Return Value

bool

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

Set shard key for this Document.

Parameters

array $keys Array of document keys.
array $options Array of sharding options.

Exceptions

MappingException

array getShardKey()

Return Value

array

bool isSharded()

Checks whether this document has shard key or not.

Return Value

bool

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

Sets the read preference used by this class.

Parameters

string $readPreference
array|null $tags

setWriteConcern(string $writeConcern)

Sets the write concern used by this class.

Parameters

string $writeConcern

string getWriteConcern()

Return Value

string

bool hasWriteConcern()

Whether there is a write concern configured for this class.

Return Value

bool

setChangeTrackingPolicy(int $policy)

Sets the change tracking policy used by this class.

Parameters

int $policy

bool isChangeTrackingDeferredExplicit()

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

Return Value

bool

bool isChangeTrackingDeferredImplicit()

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

Return Value

bool

bool isChangeTrackingNotify()

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

Return Value

bool

array getReflectionProperties()

Gets the ReflectionProperties of the mapped class.

Return Value

array An array of ReflectionProperty instances.

ReflectionProperty getReflectionProperty(string $name)

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

Parameters

string $name

Return Value

ReflectionProperty

getName()

{@inheritDoc}

string getNamespace()

The namespace this Document class belongs to.

Return Value

string $namespace The namespace name.

string getDatabase()

Returns the database this Document is mapped to.

Return Value

string $db The database name.

setDatabase(string $db)

Set the database this Document is mapped to.

Parameters

string $db The database name

string getCollection()

Get the collection this Document is mapped to.

Return Value

string $collection The collection name.

setCollection(array|string $name)

Sets the collection this Document is mapped to.

Parameters

array|string $name

Exceptions

InvalidArgumentException

bool getCollectionCapped()

Get whether or not the documents collection is capped.

Return Value

bool

setCollectionCapped(bool $bool)

Set whether or not the documents collection is capped.

Parameters

bool $bool

int getCollectionSize()

Get the collection size

Return Value

int

setCollectionSize(int $size)

Set the collection size.

Parameters

int $size

int getCollectionMax()

Get the collection max.

Return Value

int

setCollectionMax(int $max)

Set the collection max.

Parameters

int $max

bool isMappedToCollection()

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

Return Value

bool

mapOneEmbedded(array $mapping)

Map a single embedded document.

Parameters

array $mapping The mapping information.

mapManyEmbedded(array $mapping)

Map a collection of embedded documents.

Parameters

array $mapping The mapping information.

mapOneReference(array $mapping)

Map a single document reference.

Parameters

array $mapping The mapping information.

mapManyReference(array $mapping)

Map a collection of document references.

Parameters

array $mapping The mapping information.

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

bool hasReference(string $fieldName)

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

Parameters

string $fieldName

Return Value

bool

bool hasEmbed(string $fieldName)

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

Parameters

string $fieldName

Return Value

bool

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

bool 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

Return Value

bool TRUE if the association exists and is single-valued, FALSE otherwise.

bool 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

Return Value

bool TRUE if the association exists and is collection-valued, FALSE otherwise.

bool 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

Return Value

bool TRUE if the association exists and is single-valued, FALSE otherwise.

bool 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

Return Value

bool TRUE if the association exists and is collection-valued, FALSE otherwise.

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, mixed $id)

Sets the document identifier of a document.

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

Parameters

object $document
mixed $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

ObjectId getIdentifierObject(object $document)

Get the document identifier object as a database type.

Parameters

object $document

Return Value

ObjectId $id The ObjectId

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

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

Parameters

object $document
string $field
mixed $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

array getFieldMapping(string $fieldName)

Gets the mapping of a field.

Parameters

string $fieldName The field name.

Return Value

array The field mapping.

Exceptions

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

array getEmbeddedFieldsMappings()

Gets mappings of fields holding embedded document(s).

Return Value

array of field mappings

array 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

Return Value

array

Exceptions

MappingException

bool isNullable(string $fieldName)

Check if the field is not null.

Parameters

string $fieldName The field name

Return Value

bool TRUE if the field is not null, FALSE otherwise.

bool hasDiscriminator()

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

Return Value

bool

setIdGeneratorType(string $generatorType)

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

Parameters

string $generatorType Generator type.

setIdGeneratorOptions(array $generatorOptions)

Sets the Id generator options.

Parameters

array $generatorOptions Generator options.

bool isInheritanceTypeNone()

Return Value

bool

bool isInheritanceTypeSingleCollection()

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

Return Value

bool

bool isInheritanceTypeCollectionPerClass()

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

Return Value

bool

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

bool isIdGeneratorAuto()

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

Return Value

bool TRUE if the class uses the AUTO generator, FALSE otherwise.

bool isIdGeneratorIncrement()

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

Return Value

bool TRUE if the class uses the INCREMENT generator, FALSE otherwise.

bool isIdGeneratorUuid()

Checks whether the class will generate a uuid id.

Return Value

bool TRUE if the class uses the UUID generator, FALSE otherwise.

bool isIdGeneratorNone()

Checks whether the class uses no id generator.

Return Value

bool TRUE if the class does not use any id generator, FALSE otherwise.

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 The version field mapping array

Exceptions

LockException

setVersioned(bool $bool)

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

Parameters

bool $bool

setVersionField(string $versionField)

Sets the name of the field that is to be used for versioning if this class is versioned for optimistic locking.

Parameters

string $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 The version field mapping array

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

array mapField(array $mapping)

Map a field.

Parameters

array $mapping The mapping information.

Return Value

array

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.

object newInstance()

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

Return Value

object