class MemberMetadata
Stores all metadata needed for validating a class property.
The method of accessing the property's value must be specified by subclasses by implementing the {@link newReflectionMember()} method.
This class supports serialization and cloning.
@author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\Validator\Mapping\GenericMetadata implements \Symfony\Component\Validator\Mapping\MetadataInterface
- class \Symfony\Component\Validator\Mapping\MemberMetadata extends \Symfony\Component\Validator\Mapping\GenericMetadata implements \Symfony\Component\Validator\Mapping\PropertyMetadataInterface
Expanded class hierarchy of MemberMetadata
See also
1 file declares its use of MemberMetadata
- ExecutionContext.php in vendor/
symfony/ validator/ Context/ ExecutionContext.php
File
-
vendor/
symfony/ validator/ Mapping/ MemberMetadata.php, line 30
Namespace
Symfony\Component\Validator\MappingView source
abstract class MemberMetadata extends GenericMetadata implements PropertyMetadataInterface {
/**
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getClassName()} instead.
*/
public string $class;
/**
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getName()} instead.
*/
public string $name;
/**
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getPropertyName()} instead.
*/
public string $property;
/**
* @var \ReflectionMethod[]|\ReflectionProperty[]
*/
private array $reflMember = [];
/**
* @param string $class The name of the class this member is defined on
* @param string $name The name of the member
* @param string $property The property the member belongs to
*/
public function __construct(string $class, string $name, string $property) {
$this->class = $class;
$this->name = $name;
$this->property = $property;
}
public function addConstraint(Constraint $constraint) : static {
$this->checkConstraint($constraint);
parent::addConstraint($constraint);
return $this;
}
public function __sleep() : array {
return array_merge(parent::__sleep(), [
'class',
'name',
'property',
]);
}
/**
* Returns the name of the member.
*/
public function getName() : string {
return $this->name;
}
public function getClassName() : string {
return $this->class;
}
public function getPropertyName() : string {
return $this->property;
}
/**
* Returns whether this member is public.
*/
public function isPublic(object|string $objectOrClassName) : bool {
return $this->getReflectionMember($objectOrClassName)
->isPublic();
}
/**
* Returns whether this member is protected.
*/
public function isProtected(object|string $objectOrClassName) : bool {
return $this->getReflectionMember($objectOrClassName)
->isProtected();
}
/**
* Returns whether this member is private.
*/
public function isPrivate(object|string $objectOrClassName) : bool {
return $this->getReflectionMember($objectOrClassName)
->isPrivate();
}
/**
* Returns the reflection instance for accessing the member's value.
*/
public function getReflectionMember(object|string $objectOrClassName) : \ReflectionMethod|\ReflectionProperty {
$className = \is_string($objectOrClassName) ? $objectOrClassName : $objectOrClassName::class;
if (!isset($this->reflMember[$className])) {
$this->reflMember[$className] = $this->newReflectionMember($objectOrClassName);
}
return $this->reflMember[$className];
}
/**
* Creates a new reflection instance for accessing the member's value.
*/
protected abstract function newReflectionMember(object|string $objectOrClassName) : \ReflectionMethod|\ReflectionProperty;
private function checkConstraint(Constraint $constraint) : void {
if (!\in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets(), true)) {
throw new ConstraintDefinitionException(\sprintf('The constraint "%s" cannot be put on properties or getters.', get_debug_type($constraint)));
}
if ($constraint instanceof Composite) {
foreach ($constraint->getNestedConstraints() as $nestedConstraint) {
$this->checkConstraint($nestedConstraint);
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
GenericMetadata::$autoMappingStrategy | public | property | Is auto-mapping enabled? | ||
GenericMetadata::$cascadingStrategy | public | property | The strategy for cascading objects. | ||
GenericMetadata::$constraints | public | property | @internal This property is public in order to reduce the size of the class' serialized representation. Do not access it. Use {@link getConstraints()} and {@link findConstraints()} instead. |
||
GenericMetadata::$constraintsByGroup | public | property | @internal This property is public in order to reduce the size of the class' serialized representation. Do not access it. Use {@link findConstraints()} instead. |
||
GenericMetadata::$traversalStrategy | public | property | The strategy for traversing traversable objects. | 1 | |
GenericMetadata::addConstraints | public | function | Adds an list of constraints. | ||
GenericMetadata::findConstraints | public | function | Aware of the global group (* group). | Overrides MetadataInterface::findConstraints | |
GenericMetadata::getAutoMappingStrategy | public | function | |||
GenericMetadata::getCascadingStrategy | public | function | Returns the strategy for cascading objects. | Overrides MetadataInterface::getCascadingStrategy | 1 |
GenericMetadata::getConstraints | public | function | Overrides MetadataInterface::getConstraints | ||
GenericMetadata::getTraversalStrategy | public | function | Returns the strategy for traversing traversable objects. | Overrides MetadataInterface::getTraversalStrategy | |
GenericMetadata::hasConstraints | public | function | Returns whether this element has any constraints. | ||
GenericMetadata::__clone | public | function | Clones this object. | ||
MemberMetadata::$class | public | property | @internal This property is public in order to reduce the size of the class' serialized representation. Do not access it. Use {@link getClassName()} instead. |
||
MemberMetadata::$name | public | property | @internal This property is public in order to reduce the size of the class' serialized representation. Do not access it. Use {@link getName()} instead. |
||
MemberMetadata::$property | public | property | @internal This property is public in order to reduce the size of the class' serialized representation. Do not access it. Use {@link getPropertyName()} instead. |
||
MemberMetadata::$reflMember | private | property | |||
MemberMetadata::addConstraint | public | function | Adds a constraint. | Overrides GenericMetadata::addConstraint | |
MemberMetadata::checkConstraint | private | function | |||
MemberMetadata::getClassName | public | function | |||
MemberMetadata::getName | public | function | Returns the name of the member. | ||
MemberMetadata::getPropertyName | public | function | Returns the name of the property. | Overrides PropertyMetadataInterface::getPropertyName | |
MemberMetadata::getReflectionMember | public | function | Returns the reflection instance for accessing the member's value. | ||
MemberMetadata::isPrivate | public | function | Returns whether this member is private. | ||
MemberMetadata::isProtected | public | function | Returns whether this member is protected. | ||
MemberMetadata::isPublic | public | function | Returns whether this member is public. | ||
MemberMetadata::newReflectionMember | abstract protected | function | Creates a new reflection instance for accessing the member's value. | 2 | |
MemberMetadata::__construct | public | function | 2 | ||
MemberMetadata::__sleep | public | function | Returns the names of the properties that should be serialized. | Overrides GenericMetadata::__sleep | |
PropertyMetadataInterface::getPropertyValue | public | function | Extracts the value of the property from the given container. | 2 |