class ClassMetadata extends ComponentMetadata implements TableOwner (View source)

A ClassMetadata instance holds all the object-relational mapping metadata of an entity and its associations.

Properties

protected string $className from ComponentMetadata
protected ComponentMetadata|null $parent from ComponentMetadata
protected ReflectionClass|null $reflectionClass The ReflectionClass instance of the component class. from ComponentMetadata
protected CacheMetadata|null $cache from ComponentMetadata
protected Property[] $declaredProperties from ComponentMetadata
protected string $customRepositoryClassName The name of the custom repository class used for the entity class.
bool $isMappedSuperclass READ-ONLY: Whether this class describes the mapping of a mapped superclass.
bool $isEmbeddedClass READ-ONLY: Whether this class describes the mapping of an embeddable class.
protected string[] $subClasses The names of all subclasses (descendants).
string[][] $lifecycleCallbacks READ-ONLY: The registered lifecycle callbacks for entities of this class.
mixed[][] $entityListeners READ-ONLY: The registered entity listeners.
string[] $identifier READ-ONLY: The field names of all fields that are part of the identifier/primary key of the mapped entity class.
string $inheritanceType READ-ONLY: The inheritance mapping type used by the class.
string $changeTrackingPolicy READ-ONLY: The policy used for change-tracking on entities of this class.
mixed $discriminatorValue READ-ONLY: The discriminator value of this class.
string[] $discriminatorMap READ-ONLY: The discriminator map of all mapped classes in the hierarchy.
DiscriminatorColumnMetadata $discriminatorColumn READ-ONLY: The definition of the discriminator column used in JOINED and SINGLE_TABLE inheritance mappings.
TableMetadata $table READ-ONLY: The primary table metadata.
string[] $fieldNames READ-ONLY: An array of field names. Used to look up field names from column names.
FieldMetadata|null $versionProperty READ-ONLY: The field which is used for versioning in optimistic locking (if any).
protected NamingStrategy $namingStrategy NamingStrategy determining the default column and table names.
protected ValueGenerationPlan $valueGenerationPlan Value generation plan is responsible for generating values for auto-generated fields.

Methods

__construct(string $entityName, ClassMetadataBuildingContext $metadataBuildingContext)

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

getClassName()

No description

setParent(ComponentMetadata $parent)

No description

getParent()

No description

getReflectionClass()

No description

setCache(CacheMetadata|null $cache = null)

No description

getCache()

No description

iterable|Property[]
addDeclaredProperty(Property $property)

No description

hasDeclaredProperty(string $propertyName)

No description

iterable|Property[]
getPropertiesIterator()

No description

getProperty(string $propertyName)

No description

hasProperty(string $propertyName)

No description

setClassName(string $className)

No description

getAncestorsIterator()

No description

getRootClassName()

No description

__clone()

Handles metadata cloning nicely.

string
__toString()

Creates a string representation of this instance.

string[]
__sleep()

Determines which fields get serialized.

wakeupReflection(ReflectionService $reflectionService)

Restores some state that can not be serialized/unserialized.

validateIdentifier()

Validates Identifier.

validateAssociations()

Validates association targets actually exist.

validateLifecycleCallbacks(ReflectionService $reflectionService)

Validates lifecycle callbacks.

setChangeTrackingPolicy(string $policy)

Sets the change tracking policy used by this class.

bool
isIdentifier(string $fieldName)

Checks whether a field is part of the identifier/primary key field(s).

isIdentifierComposite()

No description

validateAndCompleteFieldMapping(FieldMetadata $property)

Validates & completes the basic mapping information for field mapping.

validateAndCompleteVersionFieldMapping(VersionFieldMetadata $property)

Validates & completes the basic mapping information for field mapping.

validateAndCompleteAssociationMapping(AssociationMetadata $property)

Validates & completes the basic mapping information that is common to all association mappings (one-to-one, many-ot-one, one-to-many, many-to-many).

validateAndCompleteToOneAssociationMetadata(ToOneAssociationMetadata $property)

Validates & completes a to-one association mapping.

validateAndCompleteToManyAssociationMetadata(ToManyAssociationMetadata $property)

Validates & completes a to-many association mapping.

validateAndCompleteOneToOneMapping(OneToOneAssociationMetadata $property)

Validates & completes a one-to-one association mapping.

validateAndCompleteManyToOneMapping(ManyToOneAssociationMetadata $property)

Validates & completes a many-to-one association mapping.

validateAndCompleteOneToManyMapping(OneToManyAssociationMetadata $property)

Validates & completes a one-to-many association mapping.

validateAndCompleteManyToManyMapping(ManyToManyAssociationMetadata $property)

Validates & completes a many-to-many association mapping.

getIdentifierFieldNames()

{@inheritDoc}

string
getSingleIdentifierFieldName()

Gets the name of the single id field. Note that this only works on entity classes that have a single-field pk.

setIdentifier(array $identifier)

INTERNAL: Sets the mapped identifier/primary key fields of this class.

getIdentifier()

{@inheritDoc}

hasField($fieldName)

{@inheritDoc}

getIdentifierColumns(EntityManagerInterface $em)

Returns an array with identifier column names and their corresponding ColumnMetadata.

getTableName()

Gets the name of the primary table.

getSchemaName()

Gets primary table's schema name.

getTemporaryIdTableName()

Gets the table name to use for temporary identifier tables of this class.

setSubclasses(array $subclasses)

Sets the mapped subclasses of this class.

string[]
getSubClasses()

No description

setInheritanceType(int $type)

Sets the inheritance type used by the class and its subclasses.

setPropertyOverride(Property $property)

Sets the override property mapping for an entity relationship.

bool
isRootEntity()

Checks if this entity is the root in any entity-inheritance-hierarchy.

bool
isInheritedProperty(string $fieldName)

Checks whether a mapped field is inherited from a superclass.

setTable(TableMetadata $table)

Sets the owner table metadata.

getColumn(string $columnName)

No description

addProperty(Property $property)

Add a property mapping.

addInheritedProperty(Property $property)

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

setCustomRepositoryClassName(string|null $repositoryClassName)

Registers a custom repository class for the entity class.

getCustomRepositoryClassName()

No description

bool
hasLifecycleCallbacks(string $lifecycleEvent)

Whether the class has any attached lifecycle listeners or callbacks for a lifecycle event.

string[]
getLifecycleCallbacks(string $event)

Gets the registered lifecycle callbacks for an event.

addLifecycleCallback(string $callback, string $event)

Adds a lifecycle callback for entities of this class.

setLifecycleCallbacks(array $callbacks)

Sets the lifecycle callbacks for entities of this class.

addEntityListener(string $eventName, string $class, string $method)

Adds a entity listener for entities of this class.

setDiscriminatorColumn(DiscriminatorColumnMetadata $discriminatorColumn)

Sets the discriminator column definition.

setDiscriminatorMap(array $map)

Sets the discriminator values used by this class.

addDiscriminatorMapClass($name, string $className)

Adds one entry of the discriminator map with a new class and corresponding name.

getValueGenerationPlan()

No description

setValueGenerationPlan(ValueGenerationPlan $valueGenerationPlan)

No description

asReadOnly()

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

isReadOnly()

Whether this class is read only or not.

isVersioned()

No description

mapEmbedded(array $mapping)

Map Embedded Class

inlineEmbeddable($property, ClassMetadata $embeddable)

Inline the embeddable class

Details

__construct(string $entityName, ClassMetadataBuildingContext $metadataBuildingContext)

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

Parameters

string $entityName
ClassMetadataBuildingContext $metadataBuildingContext

getClassName()

setParent(ComponentMetadata $parent)

Parameters

ComponentMetadata $parent

getParent()

getReflectionClass()

setCache(CacheMetadata|null $cache = null)

Parameters

CacheMetadata|null $cache

getCache()

iterable|Property[] getDeclaredPropertiesIterator()

Return Value

iterable|Property[]

addDeclaredProperty(Property $property)

Parameters

Property $property

Exceptions

ReflectionException
MappingException

hasDeclaredProperty(string $propertyName)

Parameters

string $propertyName

iterable|Property[] getPropertiesIterator()

Return Value

iterable|Property[]

getProperty(string $propertyName)

Parameters

string $propertyName

hasProperty(string $propertyName)

Parameters

string $propertyName

ArrayIterator|ColumnMetadata[] getColumnsIterator()

Return Value

ArrayIterator|ColumnMetadata[]

setClassName(string $className)

Parameters

string $className

getAncestorsIterator()

getRootClassName()

__clone()

Handles metadata cloning nicely.

string __toString()

Creates a string representation of this instance.

Return Value

string The string representation of this instance.

string[] __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: - reflectionClass

Return Value

string[] The names of all the fields that should be serialized.

wakeupReflection(ReflectionService $reflectionService)

Restores some state that can not be serialized/unserialized.

Parameters

ReflectionService $reflectionService

validateIdentifier()

Validates Identifier.

Exceptions

MappingException

validateAssociations()

Validates association targets actually exist.

Exceptions

MappingException

validateLifecycleCallbacks(ReflectionService $reflectionService)

Validates lifecycle callbacks.

Parameters

ReflectionService $reflectionService

Exceptions

MappingException

setChangeTrackingPolicy(string $policy)

Sets the change tracking policy used by this class.

Parameters

string $policy

bool isIdentifier(string $fieldName)

Checks whether a field is part of the identifier/primary key field(s).

Parameters

string $fieldName The field name.

Return Value

bool TRUE if the field is part of the table identifier/primary key field(s), FALSE otherwise.

isIdentifierComposite()

protected validateAndCompleteFieldMapping(FieldMetadata $property)

Validates & completes the basic mapping information for field mapping.

Parameters

FieldMetadata $property

Exceptions

MappingException If something is wrong with the mapping.

protected validateAndCompleteVersionFieldMapping(VersionFieldMetadata $property)

Validates & completes the basic mapping information for field mapping.

Parameters

VersionFieldMetadata $property

Exceptions

MappingException If something is wrong with the mapping.

protected validateAndCompleteAssociationMapping(AssociationMetadata $property)

Validates & completes the basic mapping information that is common to all association mappings (one-to-one, many-ot-one, one-to-many, many-to-many).

Parameters

AssociationMetadata $property

Exceptions

MappingException If something is wrong with the mapping.
CacheException If entity is not cacheable.

protected validateAndCompleteToOneAssociationMetadata(ToOneAssociationMetadata $property)

Validates & completes a to-one association mapping.

Parameters

ToOneAssociationMetadata $property The association mapping to validate & complete.

Exceptions

RuntimeException
MappingException

protected validateAndCompleteToManyAssociationMetadata(ToManyAssociationMetadata $property)

Validates & completes a to-many association mapping.

Parameters

ToManyAssociationMetadata $property The association mapping to validate & complete.

Exceptions

MappingException

protected validateAndCompleteOneToOneMapping(OneToOneAssociationMetadata $property)

Validates & completes a one-to-one association mapping.

Parameters

OneToOneAssociationMetadata $property The association mapping to validate & complete.

protected validateAndCompleteManyToOneMapping(ManyToOneAssociationMetadata $property)

Validates & completes a many-to-one association mapping.

Parameters

ManyToOneAssociationMetadata $property The association mapping to validate & complete.

Exceptions

MappingException

protected validateAndCompleteOneToManyMapping(OneToManyAssociationMetadata $property)

Validates & completes a one-to-many association mapping.

Parameters

OneToManyAssociationMetadata $property The association mapping to validate & complete.

Exceptions

MappingException

protected validateAndCompleteManyToManyMapping(ManyToManyAssociationMetadata $property)

Validates & completes a many-to-many association mapping.

Parameters

ManyToManyAssociationMetadata $property The association mapping to validate & complete.

Exceptions

MappingException

getIdentifierFieldNames()

{@inheritDoc}

string getSingleIdentifierFieldName()

Gets the name of the single id field. Note that this only works on entity classes that have a single-field pk.

Return Value

string

Exceptions

MappingException If the class has a composite primary key.

setIdentifier(array $identifier)

INTERNAL: Sets the mapped identifier/primary key fields of this class.

Mainly used by the ClassMetadataFactory to assign inherited identifiers.

Parameters

array $identifier

getIdentifier()

{@inheritDoc}

hasField($fieldName)

{@inheritDoc}

Parameters

$fieldName

ColumnMetadata[] getIdentifierColumns(EntityManagerInterface $em)

Returns an array with identifier column names and their corresponding ColumnMetadata.

Parameters

EntityManagerInterface $em

Return Value

ColumnMetadata[]

getTableName()

Gets the name of the primary table.

getSchemaName()

Gets primary table's schema name.

getTemporaryIdTableName()

Gets the table name to use for temporary identifier tables of this class.

setSubclasses(array $subclasses)

Sets the mapped subclasses of this class.

Parameters

array $subclasses The names of all mapped subclasses.

string[] getSubClasses()

Return Value

string[]

setInheritanceType(int $type)

Sets the inheritance type used by the class and its subclasses.

Parameters

int $type

Exceptions

MappingException

setPropertyOverride(Property $property)

Sets the override property mapping for an entity relationship.

Parameters

Property $property

Exceptions

RuntimeException
MappingException
CacheException

bool isRootEntity()

Checks if this entity is the root in any entity-inheritance-hierarchy.

Return Value

bool

bool isInheritedProperty(string $fieldName)

Checks whether a mapped field is inherited from a superclass.

Parameters

string $fieldName

Return Value

bool TRUE if the field is inherited, FALSE otherwise.

setTable(TableMetadata $table)

Sets the owner table metadata.

Parameters

TableMetadata $table

getColumn(string $columnName)

Parameters

string $columnName

addProperty(Property $property)

Add a property mapping.

Parameters

Property $property

Exceptions

RuntimeException
MappingException
CacheException

addInheritedProperty(Property $property)

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

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

Parameters

Property $property

setCustomRepositoryClassName(string|null $repositoryClassName)

Registers a custom repository class for the entity class.

Parameters

string|null $repositoryClassName The class name of the custom mapper.

getCustomRepositoryClassName()

bool hasLifecycleCallbacks(string $lifecycleEvent)

Whether the class has any attached lifecycle listeners or callbacks for a lifecycle event.

Parameters

string $lifecycleEvent

Return Value

bool

string[] getLifecycleCallbacks(string $event)

Gets the registered lifecycle callbacks for an event.

Parameters

string $event

Return Value

string[]

addLifecycleCallback(string $callback, string $event)

Adds a lifecycle callback for entities of this class.

Parameters

string $callback
string $event

setLifecycleCallbacks(array $callbacks)

Sets the lifecycle callbacks for entities of this class.

Any previously registered callbacks are overwritten.

Parameters

array $callbacks

addEntityListener(string $eventName, string $class, string $method)

Adds a entity listener for entities of this class.

Parameters

string $eventName The entity lifecycle event.
string $class The listener class.
string $method The listener callback method.

Exceptions

MappingException

setDiscriminatorColumn(DiscriminatorColumnMetadata $discriminatorColumn)

Sets the discriminator column definition.

Parameters

DiscriminatorColumnMetadata $discriminatorColumn

Exceptions

MappingException

See also

getDiscriminatorColumn()

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

addDiscriminatorMapClass($name, string $className)

Adds one entry of the discriminator map with a new class and corresponding name.

Parameters

$name
string $className

Exceptions

MappingException

getValueGenerationPlan()

setValueGenerationPlan(ValueGenerationPlan $valueGenerationPlan)

Parameters

ValueGenerationPlan $valueGenerationPlan

asReadOnly()

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

isReadOnly()

Whether this class is read only or not.

isVersioned()

mapEmbedded(array $mapping)

Map Embedded Class

Parameters

array $mapping

Exceptions

MappingException

inlineEmbeddable($property, ClassMetadata $embeddable)

Inline the embeddable class

Parameters

$property
ClassMetadata $embeddable