Symfony2 API
Class

Symfony\Component\Validator\Mapping\ClassMetadata

class ClassMetadata extends ElementMetadata implements MetadataInterface, ClassBasedInterface, PropertyMetadataContainerInterface

Represents all the configured constraints on a given class.

Properties

string $name
string $defaultGroup
MemberMetadata[] $members
PropertyMetadata[] $properties
GetterMetadata[] $getters
array $groupSequence
Boolean $groupSequenceProvider

Methods

__construct(string $class)

Constructs a metadata for the given class

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

Implementation of the Visitor design pattern.

array __sleep()

Returns the names of the properties that should be serialized.

string getClassName()

Returns the name of the backing PHP class.

string getDefaultGroup()

Returns the name of the default group for this class

ElementMetadata addConstraint(Constraint $constraint)

Adds a constraint to this element.

ClassMetadata addPropertyConstraint(string $property, Constraint $constraint)

Adds a constraint to the given property.

ClassMetadata addGetterConstraint(string $property, Constraint $constraint)

Adds a constraint to the getter of the given property.

mergeConstraints(ClassMetadata $source)

Merges the constraints of the given metadata into this object.

Boolean hasMemberMetadatas(string $property)

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

MemberMetadata[] getMemberMetadatas(string $property)

Returns all metadatas of members describing the given property.

Boolean hasPropertyMetadata(string $property)

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

PropertyMetadataInterface[] getPropertyMetadata(string $property)

Returns all metadata instances for the given named property.

array getConstrainedProperties()

Returns all properties for which constraints are defined.

ClassMetadata setGroupSequence(array $groups)

Sets the default group sequence for this class.

Boolean hasGroupSequence()

Returns whether this class has an overridden default group sequence.

array getGroupSequence()

Returns the default group sequence for this class.

ReflectionClass getReflectionClass()

Returns a ReflectionClass instance for this class.

setGroupSequenceProvider(Boolean $active)

Sets whether a group sequence provider should be used.

Boolean isGroupSequenceProvider()

Returns whether the class is a group sequence provider.

Details

at line 75
public __construct(string $class)

Constructs a metadata for the given class

Parameters

string $class

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

Implementation of the Visitor design pattern.

Calls {@link ValidationVisitorInterface::visit} and then forwards the
<tt>accept()</tt>-call to all property metadata instances.

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

at line 125
public array __sleep()

Returns the names of the properties that should be serialized.

Return Value

array

at line 143
public string getClassName()

Returns the name of the backing PHP class.

Return Value

string The fully qualified class name

at line 163
public string getDefaultGroup()

Returns the name of the default group for this class

For each class, the group "Default" is an alias for the group
"<ClassName>", where <ClassName> 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 "<ClassName>".

Return Value

string The name of the default group

at line 171
public ElementMetadata addConstraint(Constraint $constraint)

Adds a constraint to this element.

Parameters

Constraint $constraint

Return Value

ElementMetadata

at line 193
public ClassMetadata 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

ClassMetadata This object

at line 219
public ClassMetadata 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

ClassMetadata This object

at line 239
public mergeConstraints(ClassMetadata $source)

Merges the constraints of the given metadata into this object.

Parameters

ClassMetadata $source The source metadata

at line 287
public Boolean hasMemberMetadatas(string $property)

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

Parameters

string $property The name of the property

Return Value

Boolean

at line 299
public MemberMetadata[] getMemberMetadatas(string $property)

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 307
public Boolean hasPropertyMetadata(string $property)

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

Parameters

string $property The property name.

Return Value

Boolean

at line 315
public 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 <tt>BadMethodCallException</tt>).

Parameters

string $property The property name.

Return Value

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

at line 325
public array getConstrainedProperties()

Returns all properties for which constraints are defined.

Return Value

array An array of property names

at line 339
public ClassMetadata setGroupSequence(array $groups)

Sets the default group sequence for this class.

Parameters

array $groups An array of group names

Return Value

ClassMetadata

Exceptions

GroupDefinitionException

at line 363
public Boolean hasGroupSequence()

Returns whether this class has an overridden default group sequence.

Return Value

Boolean

at line 373
public array getGroupSequence()

Returns the default group sequence for this class.

Return Value

array An array of group names

at line 383
public ReflectionClass getReflectionClass()

Returns a ReflectionClass instance for this class.

Return Value

ReflectionClass

at line 399
public setGroupSequenceProvider(Boolean $active)

Sets whether a group sequence provider should be used.

Parameters

Boolean $active

Exceptions

GroupDefinitionException

at line 417
public Boolean isGroupSequenceProvider()

Returns whether the class is a group sequence provider.

Return Value

Boolean