class PropertyMetadata
Stores all metadata needed for validating a class property.
The value of the property is obtained by directly accessing the property. The property will be accessed by reflection, so the access of private and protected properties is supported.
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
- class \Symfony\Component\Validator\Mapping\PropertyMetadata extends \Symfony\Component\Validator\Mapping\MemberMetadata
- class \Symfony\Component\Validator\Mapping\MemberMetadata extends \Symfony\Component\Validator\Mapping\GenericMetadata implements \Symfony\Component\Validator\Mapping\PropertyMetadataInterface
Expanded class hierarchy of PropertyMetadata
See also
1 file declares its use of PropertyMetadata
- ConstraintValidatorTestCase.php in vendor/
symfony/ validator/ Test/ ConstraintValidatorTestCase.php
File
-
vendor/
symfony/ validator/ Mapping/ PropertyMetadata.php, line 29
Namespace
Symfony\Component\Validator\MappingView source
class PropertyMetadata extends MemberMetadata {
/**
* @param string $class The class this property is defined on
* @param string $name The name of this property
*
* @throws ValidatorException
*/
public function __construct(string $class, string $name) {
if (!property_exists($class, $name)) {
throw new ValidatorException(\sprintf('Property "%s" does not exist in class "%s".', $name, $class));
}
parent::__construct($class, $name, $name);
}
public function getPropertyValue(mixed $object) : mixed {
$reflProperty = $this->getReflectionMember($object);
if ($reflProperty->hasType() && !$reflProperty->isInitialized($object)) {
// There is no way to check if a property has been unset or if it is uninitialized.
// When trying to access an uninitialized property, __get method is triggered.
// If __get method is not present, no fallback is possible
// Otherwise we need to catch an Error in case we are trying to access an uninitialized but set property.
if (!method_exists($object, '__get')) {
return null;
}
try {
return $reflProperty->getValue($object);
} catch (\Error) {
return null;
}
}
return $reflProperty->getValue($object);
}
protected function newReflectionMember(object|string $objectOrClassName) : \ReflectionMethod|\ReflectionProperty {
$originalClass = \is_string($objectOrClassName) ? $objectOrClassName : $objectOrClassName::class;
while (!property_exists($objectOrClassName, $this->getName())) {
$objectOrClassName = get_parent_class($objectOrClassName);
if (false === $objectOrClassName) {
throw new ValidatorException(\sprintf('Property "%s" does not exist in class "%s".', $this->getName(), $originalClass));
}
}
return new \ReflectionProperty($objectOrClassName, $this->getName());
}
}
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::__sleep | public | function | Returns the names of the properties that should be serialized. | Overrides GenericMetadata::__sleep | |
PropertyMetadata::getPropertyValue | public | function | Extracts the value of the property from the given container. | Overrides PropertyMetadataInterface::getPropertyValue | |
PropertyMetadata::newReflectionMember | protected | function | Creates a new reflection instance for accessing the member's value. | Overrides MemberMetadata::newReflectionMember | |
PropertyMetadata::__construct | public | function | Overrides MemberMetadata::__construct |