class ClassMetadata extends ElementMetadata implements ClassMetadataInterface

Default implementation of {@link ClassMetadataInterface}.

This class supports serialization and cloning.

Properties

Constraint[] $constraints from GenericMetadata
array $constraintsByGroup from GenericMetadata
int $cascadingStrategy The strategy for cascading objects. from GenericMetadata
int $traversalStrategy The strategy for traversing traversable objects.
string $name
string $defaultGroup
MemberMetadata[][] $members
PropertyMetadata[] $properties
GetterMetadata[] $getters
array $groupSequence
bool $groupSequenceProvider

Methods

string[]
__sleep()

Returns the names of the properties that should be serialized.

__clone()

Clones this object.

$this
addConstraint(Constraint $constraint)

Adds a constraint.

$this
addConstraints(array $constraints)

Adds an list of constraints.

getConstraints()

Returns all constraints of this element.

bool
hasConstraints()

Returns whether this element has any constraints.

findConstraints(string $group)

Returns all constraints for a given validation group.

int
getCascadingStrategy()

Class nodes are never cascaded.

int
getTraversalStrategy()

Returns the strategy for traversing traversable objects.

accept(ValidationVisitorInterface $visitor, mixed $value, string|string[] $group, string $propertyPath, $propagatedGroup = null) deprecated

Exists for compatibility with the deprecated {@link Symfony\Component\Validator\MetadataInterface}.

__construct(string $class)

Constructs a metadata for the given class.

string
getClassName()

Returns the name of the backing PHP class.

string
getDefaultGroup()

Returns the name of the default group for this class.

$this
addPropertyConstraint(string $property, Constraint $constraint)

Adds a constraint to the given property.

$this
addPropertyConstraints(string $property, array $constraints)

No description

$this
addGetterConstraint(string $property, Constraint $constraint)

Adds a constraint to the getter of the given property.

$this
addGetterMethodConstraint(string $property, string $method, Constraint $constraint)

Adds a constraint to the getter of the given property.

$this
addGetterConstraints(string $property, array $constraints)

No description

$this
addGetterMethodConstraints(string $property, string $method, array $constraints)

No description

mergeConstraints(ClassMetadata $source)

Merges the constraints of the given metadata into this object.

addMemberMetadata(MemberMetadata $metadata) deprecated

Adds a member metadata.

bool
hasMemberMetadatas(string $property) deprecated

Returns true if metadatas of members is present for the given property.

getMemberMetadatas(string $property) deprecated

Returns all metadatas of members describing the given property.

bool
hasPropertyMetadata(string $property)

Check if there's any metadata attached to the given named property.

getPropertyMetadata(string $property)

Returns all metadata instances for the given named property.

string[]
getConstrainedProperties()

Returns the names of all constrained properties.

$this
setGroupSequence(string[]|GroupSequence $groupSequence)

Sets the default group sequence for this class.

bool
hasGroupSequence()

Returns whether the "Default" group is overridden by a group sequence.

getGroupSequence()

Returns the group sequence that overrides the "Default" group for this class.

getReflectionClass()

Returns a ReflectionClass instance for this class.

setGroupSequenceProvider(bool $active)

Sets whether a group sequence provider should be used.

bool
isGroupSequenceProvider()

Returns whether the "Default" group is overridden by a dynamic group sequence obtained by the validated objects.

Details

at line 173
string[] __sleep()

Returns the names of the properties that should be serialized.

Return Value

string[]

in GenericMetadata at line 96
__clone()

Clones this object.

at line 222
$this addConstraint(Constraint $constraint)

Adds a constraint.

If the constraint {@link Valid} is added, the cascading strategy will be changed to {@link CascadingStrategy::CASCADE}. Depending on the properties $traverse and $deep of that constraint, the traversal strategy will be set to one of the following:

  • {@link TraversalStrategy::IMPLICIT} if $traverse is enabled and $deep is enabled
  • {@link TraversalStrategy::IMPLICIT} | {@link TraversalStrategy::STOP_RECURSION} if $traverse is enabled, but $deep is disabled
  • {@link TraversalStrategy::NONE} if $traverse is disabled

Parameters

Constraint $constraint

Return Value

$this

Exceptions

ConstraintDefinitionException When trying to add the {@link Traverse} constraint

in GenericMetadata at line 166
$this addConstraints(array $constraints)

Adds an list of constraints.

Parameters

array $constraints The constraints to add

Return Value

$this

in GenericMetadata at line 178
Constraint[] getConstraints()

Returns all constraints of this element.

Return Value

Constraint[] A list of Constraint instances

in GenericMetadata at line 188
bool hasConstraints()

Returns whether this element has any constraints.

Return Value

bool

in GenericMetadata at line 198
Constraint[] findConstraints(string $group)

Returns all constraints for a given validation group.

Parameters

string $group The validation group

Return Value

Constraint[] A list of constraint instances

at line 580
int getCascadingStrategy()

Class nodes are never cascaded.

{@inheritdoc}

Return Value

int The cascading strategy

in GenericMetadata at line 216
int getTraversalStrategy()

Returns the strategy for traversing traversable objects.

Return Value

int The traversal strategy

at line 134
accept(ValidationVisitorInterface $visitor, mixed $value, string|string[] $group, string $propertyPath, $propagatedGroup = null) deprecated

deprecated since version 2.5, to be removed in 3.0.

Exists for compatibility with the deprecated {@link Symfony\Component\Validator\MetadataInterface}.

Should not be used.

Implemented for backward compatibility with Symfony < 2.5.

Parameters

ValidationVisitorInterface $visitor The visitor implementing the validation logic
mixed $value The value to validate
string|string[] $group The validation group to validate in
string $propertyPath The current property path in the validation graph
$propagatedGroup

Exceptions

BadMethodCallException

at line 118
__construct(string $class)

Constructs a metadata for the given class.

Parameters

string $class

at line 194
string getClassName()

Returns the name of the backing PHP class.

Return Value

string The name of the backing class

at line 214
string getDefaultGroup()

Returns the name of the default group for this class.

For each class, the group "Default" is an alias for the group "", where is the non-namespaced name of the class. All constraints implicitly or explicitly assigned to group "Default" belong to both of these groups, unless the class defines a group sequence.

If a class defines a group sequence, validating the class in "Default" will validate the group sequence. The constraints assigned to "Default" can still be validated by validating the class in "".

Return Value

string The name of the default group

at line 260
$this addPropertyConstraint(string $property, Constraint $constraint)

Adds a constraint to the given property.

Parameters

string $property The name of the property
Constraint $constraint The constraint

Return Value

$this

at line 281
$this addPropertyConstraints(string $property, array $constraints)

Parameters

string $property
array $constraints

Return Value

$this

at line 301
$this addGetterConstraint(string $property, Constraint $constraint)

Adds a constraint to the getter of the given property.

The name of the getter is assumed to be the name of the property with an uppercased first letter and either the prefix "get" or "is".

Parameters

string $property The name of the property
Constraint $constraint The constraint

Return Value

$this

at line 325
$this addGetterMethodConstraint(string $property, string $method, Constraint $constraint)

Adds a constraint to the getter of the given property.

Parameters

string $property The name of the property
string $method The name of the getter method
Constraint $constraint The constraint

Return Value

$this

at line 346
$this addGetterConstraints(string $property, array $constraints)

Parameters

string $property
array $constraints

Return Value

$this

at line 362
$this addGetterMethodConstraints(string $property, string $method, array $constraints)

Parameters

string $property
string $method
array $constraints

Return Value

$this

at line 374
mergeConstraints(ClassMetadata $source)

Merges the constraints of the given metadata into this object.

Parameters

ClassMetadata $source

at line 418
protected addMemberMetadata(MemberMetadata $metadata) deprecated

deprecated since version 2.6, to be removed in 3.0.

Adds a member metadata.

Parameters

MemberMetadata $metadata

at line 434
bool hasMemberMetadatas(string $property) deprecated

deprecated since version 2.6, to be removed in 3.0. Use {@link hasPropertyMetadata} instead.

Returns true if metadatas of members is present for the given property.

Parameters

string $property The name of the property

Return Value

bool

at line 450
MemberMetadata[] getMemberMetadatas(string $property) deprecated

deprecated since version 2.6, to be removed in 3.0. Use {@link getPropertyMetadata} instead.

Returns all metadatas of members describing the given property.

Parameters

string $property The name of the property

Return Value

MemberMetadata[] An array of MemberMetadata

at line 460
bool hasPropertyMetadata(string $property)

Check if there's any metadata attached to the given named property.

Parameters

string $property The property name

Return Value

bool

at line 468
PropertyMetadataInterface[] getPropertyMetadata(string $property)

Returns all metadata instances for the given named property.

If your implementation does not support properties, simply throw an exception in this method (for example a BadMethodCallException).

Parameters

string $property The property name

Return Value

PropertyMetadataInterface[] A list of metadata instances. Empty if no metadata exists for the property.

at line 480
string[] getConstrainedProperties()

Returns the names of all constrained properties.

Return Value

string[] A list of property names

at line 494
$this setGroupSequence(string[]|GroupSequence $groupSequence)

Sets the default group sequence for this class.

Parameters

string[]|GroupSequence $groupSequence An array of group names

Return Value

$this

Exceptions

GroupDefinitionException

at line 520
bool hasGroupSequence()

Returns whether the "Default" group is overridden by a group sequence.

If it is, you can access the group sequence with {@link getGroupSequence()}.

Return Value

bool Returns true if the "Default" group is overridden

at line 528
GroupSequence|null getGroupSequence()

Returns the group sequence that overrides the "Default" group for this class.

Return Value

GroupSequence|null The group sequence or null

at line 538
ReflectionClass getReflectionClass()

Returns a ReflectionClass instance for this class.

Return Value

ReflectionClass

at line 554
setGroupSequenceProvider(bool $active)

Sets whether a group sequence provider should be used.

Parameters

bool $active

Exceptions

GroupDefinitionException

at line 570
bool isGroupSequenceProvider()

Returns whether the "Default" group is overridden by a dynamic group sequence obtained by the validated objects.

If this method returns true, the class must implement {@link \Symfony\Component\Validator\GroupSequenceProviderInterface}. This interface will be used to obtain the group sequence when an object of this class is validated.

Return Value

bool Returns true if the "Default" group is overridden by a dynamic group sequence