class ClassMetadata implements ClassMetadata (View source)

Metadata class.

Constants

MANY_TO_ONE

MANY_TO_MANY

CASCADE_PERSIST

CASCADE_REMOVE

CASCADE_MERGE

CASCADE_DETACH

CASCADE_REFRESH

CASCADE_TRANSLATION

CASCADE_ALL

GENERATOR_TYPE_NONE

No strategy has been set so far.

GENERATOR_TYPE_REPOSITORY

The repository will be asked to generate the id.

GENERATOR_TYPE_ASSIGNED

Doctrine will not generate any id for us and you are responsible for manually assigning a valid id string in the document.

Be aware that in PHPCR, the parent of a node must exist.

GENERATOR_TYPE_PARENT

The document uses the parent and name mapping to find its location in the tree.

GENERATOR_TYPE_AUTO

The document uses the parent mapping to find its location in the tree and will use the PHPCR addNodeAutoNamed feature for the node name.

Properties

static protected $validVersionableAnnotations
ReflectionProperty[] $reflFields READ-ONLY: The ReflectionProperty instances of the mapped class.
int $idGenerator READ-ONLY: The ID generator used for generating IDs for this class.
$identifier READ-ONLY: The field name of the document identifier.
$uuidFieldName READ-ONLY: The field name of the UUID field.
$name READ-ONLY: The name of the document class that is stored in the phpcr:class property.
string $namespace READ-ONLY: The namespace the document class is contained in.
string $nodeType READ-ONLY: The JCR Nodetype to be used for this node.
array $mixins READ-ONLY: The JCR Mixins to be used for this node (including inherited mixins).
bool $inheritMixins READ-ONLY: Inherit parent class' mixins (default) or not.
string $node READ-ONLY: The field name of the node.
string $nodename READ-ONLY except on document creation: The field name for the name of the node.
string $parentMapping READ-ONLY except on document creation: The field name for the parent document.
string $customRepositoryClassName READ-ONLY: The name of the custom repository class used for the document class.
array $fieldMappings READ-ONLY: The field mappings of the class.
array $mappings READ-ONLY: The all mappings of the class.
array $lifecycleCallbacks READ-ONLY: The registered lifecycle callbacks for documents of this class.
ReflectionClass $reflClass The ReflectionClass instance of the mapped class.
bool $isMappedSuperclass READ-ONLY: Whether this class describes the mapping of a mapped superclass.
array $referenceMappings READ-ONLY: The reference mappings of the class.
array $childMappings READ-ONLY: The child mappings of the class.
array $childrenMappings READ-ONLY: The children mappings of the class.
array $referrersMappings READ-ONLY: The referrers mappings of the class.
array $mixedReferrersMappings READ-ONLY: The mixed referrers (read only) mappings of the class.
string $localeMapping READ-ONLY: Name of the locale property.
string $depthMapping READ-ONLY: Name of the depth property.
string $versionNameField READ-ONLY: Name of the version name property of this document.
string $versionCreatedField READ-ONLY: Name of the version created property of this document.
array $translatableFields READ-ONLY: List of translatable fields.
bool|string $versionable READ-ONLY: Whether this document should be versioned. If this is not false, it will be one of the values from self::validVersionableAnnotations.
bool $referenceable READ-ONLY: determines if the document is referenceable or not.
bool $uniqueNodeType READ-ONLY: If true, consider this document's node type to be unique among all mappings.
string $translator READ-ONLY: Strategy key to find field translations.
array $parentClasses READ-ONLY: Mapped parent classes.
array $childClasses READ-ONLY: Child class restrictions.
bool $isLeaf READ-ONLY: If the document should be act as a leaf-node and therefore not be allowed children.

Methods

__construct(string $className)

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

initializeReflection(ReflectionService $reflService)

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

wakeupReflection(ReflectionService $reflService)

Restores some state that can not be serialized/unserialized.

RepositoryException|null
isValidNodename(string $nodeName)

Check if this node name is valid. Returns null if valid, an exception otherwise.

validateIdentifier()

Validate Identifier mapping, determine the strategy if none is explicitly set.

validateChildClasses()

Validate that childClasses is empty if isLeaf is true.

assertValidChildClass(ClassMetadata $class)

Assert that the given class FQN can be a child of the document this metadata represents.

validateReferenceable()

Validate whether this class needs to be referenceable.

validateReferences()

Validate association targets actually exist.

validateTranslatables()

Validate translatable fields - ensure that the document has a translator strategy in place.

validateLifecycleCallbacks(ReflectionService $reflService)

Validate lifecycle callbacks.

setIdentifier(string $identifier)

INTERNAL: Sets the mapped identifier field of this class.

setCustomRepositoryClassName(string $repositoryClassName)

Registers a custom repository class for the document class.

bool
hasLifecycleCallbacks(string $lifecycleEvent)

Whether the class has any attached lifecycle listeners or callbacks 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.

setVersioned(string|bool $versionable)

No description

setReferenceable(bool $referenceable)

No description

setUniqueNodeType(bool $uniqueNodeType)

No description

bool
hasUniqueNodeType()

Return true if this document has a unique node type among all mappings.

setNodeType(string $nodeType)

No description

string
getNodeType()

Return the JCR node type to be used for this node.

setMixins(array $mixins)

Set the JCR mixins.

array
getMixins()

Return the JCR mixins to be used for this node.

setInheritMixins(bool $inheritMixins)

Set whether to inherit mixins from parent.

bool
getInheritMixins()

Return whether to inherit mixins from parent.

getReflectionProperties()

Gets the ReflectionProperties of the mapped class.

getReflectionProperty(string $name)

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

string
getNamespace()

The namespace this Document class belongs to.

mapId(array $mapping, ClassMetadata $inherited = null)

No description

mapNode(array $mapping, ClassMetadata $inherited = null)

No description

mapNodename(array $mapping, ClassMetadata $inherited = null)

No description

mapParentDocument(array $mapping, ClassMetadata $inherited = null)

No description

mapChild(array $mapping, ClassMetadata $inherited = null)

No description

mapChildren(array $mapping, ClassMetadata $inherited = null)

No description

mapReferrers(array $mapping, ClassMetadata $inherited = null)

No description

mapMixedReferrers(array $mapping, ClassMetadata $inherited = null)

No description

mapLocale(array $mapping, ClassMetadata $inherited = null)

No description

mapDepth(array $mapping, ClassMetadata $inherited = null)

No description

mapVersionName(array $mapping, ClassMetadata $inherited = null)

No description

mapVersionCreated(array $mapping, ClassMetadata $inherited = null)

No description

mapLifecycleCallbacks(array $mapping)

No description

mixed
validateAndCompleteFieldMapping(array $mapping, ClassMetadata $inherited = null, bool $isField = true, string $phpcrLabel = 'property')

No description

validateAndCompleteAssociationMapping($mapping, ClassMetadata $inherited = null, $phpcrLabel = 'property')

No description

validateClassMapping()

Finalize the mapping and make sure that it is consistent.

mapManyToOne($mapping, ClassMetadata $inherited = null)

No description

mapManyToMany($mapping, ClassMetadata $inherited = null)

No description

setIdGenerator(string $generator)

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

setTranslator($translator)

Sets the translator strategy key.

setParentClasses(array $parentClasses)

Set the mapped parent classes.

array
getParentClasses()

Return the mapped parent classes.

string[]
getChildClasses()

Return the class names or interfaces that children of this document must be an instance of.

setChildClasses(array $childClasses)

Set the class names or interfaces that children of this document must be instance of.

bool
isLeaf()

Return true if this is designated as a leaf node.

setIsLeaf(bool $isLeaf)

Set if this document should act as a leaf node.

bool
isIdGeneratorRepository()

Checks whether the class will generate an id via the repository.

bool
isIdGeneratorNone()

Checks whether the class uses no id generator.

getName()

{@inheritdoc}

getIdentifier()

{@inheritdoc}

array
getIdentifierFieldNames()

Get identifier field names of this class.

getReflectionClass()

{@inheritdoc}

isIdentifier($fieldName)

{@inheritdoc}

hasField($fieldName)

{@inheritdoc}

hasAssociation($fieldName)

{@inheritdoc}

array
getAssociation($fieldName)

No description

isSingleValuedAssociation($fieldName)

{@inheritdoc}

isCollectionValuedAssociation($fieldName)

{@inheritdoc}

getFieldNames()

{@inheritdoc}

getAssociationNames()

{@inheritdoc}

getTypeOfField($fieldName)

{@inheritdoc}

getAssociationTargetClass($fieldName)

{@inheritdoc}

getAssociationMappedByTargetField($assocName)

{@inheritdoc}

isAssociationInverseSide($assocName)

{@inheritdoc}

bool
isInheritedField($fieldName)

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

bool
isNullable(string $fieldName)

Check if the field is nullable or not.

mapField(array $mapping, ClassMetadata $inherited = null)

Map a field.

array
__sleep()

Determines which fields get serialized.

object
newInstance()

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

setIdentifierValue(object $document, mixed $id)

Sets the document identifier of a document.

string
getIdentifierValue(object $document)

Gets the document identifier.

array
getIdentifierValues(object $document)

Get identifier values of this document.

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

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

mixed|null
getFieldValue(object $document, string $field)

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

array
getFieldMapping(string $fieldName)

Gets the mapping of a (regular) field that holds some data but not a reference to another object.

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

Dispatches the lifecycle event of the given document to the registered lifecycle callbacks and lifecycle listeners.

getUuidFieldName()

No description

bool
isUuid(string $fieldName)

Whether $fieldName is the universally unique identifier of the document.

string
fullyQualifiedClassName(string $className)

No description

Details

__construct(string $className)

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

Parameters

string $className The name of the document class the new instance is used for.

initializeReflection(ReflectionService $reflService)

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

Parameters

ReflectionService $reflService

wakeupReflection(ReflectionService $reflService)

Restores some state that can not be serialized/unserialized.

Parameters

ReflectionService $reflService

RepositoryException|null isValidNodename(string $nodeName)

Check if this node name is valid. Returns null if valid, an exception otherwise.

Parameters

string $nodeName The node local name

Return Value

RepositoryException|null

validateIdentifier()

Validate Identifier mapping, determine the strategy if none is explicitly set.

Exceptions

MappingException if no identifiers are mapped

validateChildClasses()

Validate that childClasses is empty if isLeaf is true.

Exceptions

MappingException if there is a conflict between isLeaf and childClasses.

assertValidChildClass(ClassMetadata $class)

Assert that the given class FQN can be a child of the document this metadata represents.

Parameters

ClassMetadata $class

Exceptions

OutOfBoundsException

validateReferenceable()

Validate whether this class needs to be referenceable.

The document needs to be either referenceable or full versionable. Simple versioning does not imply referenceable.

Exceptions

MappingException if there is an invalid reference mapping

validateReferences()

Validate association targets actually exist.

Exceptions

MappingException if there is an invalid reference mapping

validateTranslatables()

Validate translatable fields - ensure that the document has a translator strategy in place.

Exceptions

MappingException if there is an inconsistency with translation

validateLifecycleCallbacks(ReflectionService $reflService)

Validate lifecycle callbacks.

Parameters

ReflectionService $reflService

Exceptions

MappingException if a declared callback does not exist

setIdentifier(string $identifier)

INTERNAL: Sets the mapped identifier field of this class.

Parameters

string $identifier

setCustomRepositoryClassName(string $repositoryClassName)

Registers a custom repository class for the document class.

Parameters

string $repositoryClassName The class name of the custom repository.

bool hasLifecycleCallbacks(string $lifecycleEvent)

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

Parameters

string $lifecycleEvent

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.

Note: If the same callback is registered more than once, the old one will be overridden.

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

setVersioned(string|bool $versionable)

Parameters

string|bool $versionable A valid versionable annotation or false to disable versioning.

setReferenceable(bool $referenceable)

Parameters

bool $referenceable

setUniqueNodeType(bool $uniqueNodeType)

Parameters

bool $uniqueNodeType

bool hasUniqueNodeType()

Return true if this document has a unique node type among all mappings.

Return Value

bool

setNodeType(string $nodeType)

Parameters

string $nodeType

string getNodeType()

Return the JCR node type to be used for this node.

Return Value

string

setMixins(array $mixins)

Set the JCR mixins.

Parameters

array $mixins

array getMixins()

Return the JCR mixins to be used for this node.

Return Value

array

setInheritMixins(bool $inheritMixins)

Set whether to inherit mixins from parent.

Parameters

bool $inheritMixins

bool getInheritMixins()

Return whether to inherit mixins from parent.

Return Value

bool

ReflectionProperty[] getReflectionProperties()

Gets the ReflectionProperties of the mapped class.

Return Value

ReflectionProperty[]

ReflectionProperty getReflectionProperty(string $name)

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

Parameters

string $name

Return Value

ReflectionProperty

string getNamespace()

The namespace this Document class belongs to.

Return Value

string $namespace The namespace name.

mapId(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapNode(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapNodename(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapParentDocument(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapChild(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapChildren(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapReferrers(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapMixedReferrers(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapLocale(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapDepth(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapVersionName(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapVersionCreated(array $mapping, ClassMetadata $inherited = null)

Parameters

array $mapping
ClassMetadata $inherited

mapLifecycleCallbacks(array $mapping)

Parameters

array $mapping

protected mixed validateAndCompleteFieldMapping(array $mapping, ClassMetadata $inherited = null, bool $isField = true, string $phpcrLabel = 'property')

Parameters

array $mapping
ClassMetadata $inherited same field of parent document, if any
bool $isField whether this is a field or an association
string $phpcrLabel the name for the phpcr thing. usually property, except for child where this is name. referrers use false to not set anything.

Return Value

mixed

Exceptions

MappingException

protected validateAndCompleteAssociationMapping($mapping, ClassMetadata $inherited = null, $phpcrLabel = 'property')

Parameters

$mapping
ClassMetadata $inherited
$phpcrLabel

validateClassMapping()

Finalize the mapping and make sure that it is consistent.

Exceptions

MappingException if inconsistencies are discovered.

mapManyToOne($mapping, ClassMetadata $inherited = null)

Parameters

$mapping
ClassMetadata $inherited

mapManyToMany($mapping, ClassMetadata $inherited = null)

Parameters

$mapping
ClassMetadata $inherited

protected setIdGenerator(string $generator)

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

Parameters

string $generator

setTranslator($translator)

Sets the translator strategy key.

Parameters

$translator

setParentClasses(array $parentClasses)

Set the mapped parent classes.

Parameters

array $parentClasses

array getParentClasses()

Return the mapped parent classes.

Return Value

array of mapped class FQNs

string[] getChildClasses()

Return the class names or interfaces that children of this document must be an instance of.

Return Value

string[]

setChildClasses(array $childClasses)

Set the class names or interfaces that children of this document must be instance of.

Parameters

array $childClasses

bool isLeaf()

Return true if this is designated as a leaf node.

Return Value

bool

setIsLeaf(bool $isLeaf)

Set if this document should act as a leaf node.

Parameters

bool $isLeaf

bool isIdGeneratorRepository()

Checks whether the class will generate an id via the repository.

Return Value

bool TRUE if the class uses the Repository 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.

getName()

{@inheritdoc}

getIdentifier()

{@inheritdoc}

array getIdentifierFieldNames()

Get identifier field names of this class.

Since PHPCR only allows exactly one identifier field this is a proxy to {see getIdentifier()} and returns an array.

Return Value

array

getReflectionClass()

{@inheritdoc}

isIdentifier($fieldName)

{@inheritdoc}

Parameters

$fieldName

hasField($fieldName)

{@inheritdoc}

Parameters

$fieldName

hasAssociation($fieldName)

{@inheritdoc}

Parameters

$fieldName

array getAssociation($fieldName)

Parameters

$fieldName

Return Value

array the association mapping with the field of this name

Exceptions

MappingException if the class has no mapping field with this name

isSingleValuedAssociation($fieldName)

{@inheritdoc}

Parameters

$fieldName

isCollectionValuedAssociation($fieldName)

{@inheritdoc}

Parameters

$fieldName

getFieldNames()

{@inheritdoc}

getAssociationNames()

{@inheritdoc}

getTypeOfField($fieldName)

{@inheritdoc}

Parameters

$fieldName

getAssociationTargetClass($fieldName)

{@inheritdoc}

Parameters

$fieldName

getAssociationMappedByTargetField($assocName)

{@inheritdoc}

Parameters

$assocName

isAssociationInverseSide($assocName)

{@inheritdoc}

Parameters

$assocName

bool isInheritedField($fieldName)

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

Parameters

$fieldName

Return Value

bool string class name if the field is inherited, FALSE otherwise.

bool isNullable(string $fieldName)

Check if the field is nullable or not.

Parameters

string $fieldName The field name

Return Value

bool TRUE if the field is nullable, FALSE otherwise.

mapField(array $mapping, ClassMetadata $inherited = null)

Map a field.

  • type - The Doctrine Type of this field.
  • fieldName - The name of the property/field on the mapped php class
  • name - The Property key of this field in the PHPCR document
  • id - True for an ID field.

Parameters

array $mapping
ClassMetadata $inherited

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.

object newInstance()

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

Return Value

object

setIdentifierValue(object $document, mixed $id)

Sets the document identifier of a document.

Parameters

object $document
mixed $id

string getIdentifierValue(object $document)

Gets the document identifier.

Parameters

object $document

Return Value

string $id

array getIdentifierValues(object $document)

Get identifier values of this document.

Since PHPCR only allows exactly one identifier field this is a proxy to {see getIdentifierValue()} and returns an array with the identifier field as a key.

If there is no identifier mapped, returns an empty array as per the specification.

Parameters

object $document

Return Value

array

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|null getFieldValue(object $document, string $field)

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

Parameters

object $document the document to get the field from
string $field the name of the field

Return Value

mixed|null the value of this field for the document or null if not found

array getFieldMapping(string $fieldName)

Gets the mapping of a (regular) field that holds some data but not a reference to another object.

Parameters

string $fieldName The field name.

Return Value

array The field mapping.

Exceptions

MappingException

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

Dispatches the lifecycle event of the given document to the registered lifecycle callbacks and lifecycle listeners.

Parameters

string $lifecycleEvent The lifecycle event.
object $document The Document on which the event occurred.
array $arguments the arguments to pass to the callback

getUuidFieldName()

bool isUuid(string $fieldName)

Whether $fieldName is the universally unique identifier of the document.

Parameters

string $fieldName

Return Value

bool True if $fieldName is mapped as the uuid, false otherwise.

string fullyQualifiedClassName(string $className)

Parameters

string $className

Return Value

string