class GetterMetadata in Plug 7
Stores all metadata needed for validating a class property via its getter method.
A property getter is any method that is equal to the property's name, prefixed with either "get" or "is". That method will be used to access the property's value.
The getter will be invoked by reflection, so the access of private and protected getters is supported.
This class supports serialization and cloning.
@author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\Validator\Mapping\GenericMetadata implements MetadataInterface
- class \Symfony\Component\Validator\Mapping\ElementMetadata
- class \Symfony\Component\Validator\Mapping\MemberMetadata implements PropertyMetadataInterface
- class \Symfony\Component\Validator\Mapping\GetterMetadata
- class \Symfony\Component\Validator\Mapping\MemberMetadata implements PropertyMetadataInterface
- class \Symfony\Component\Validator\Mapping\ElementMetadata
Expanded class hierarchy of GetterMetadata
See also
1 file declares its use of GetterMetadata
- GetterMetadataTest.php in lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Mapping/ GetterMetadataTest.php
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Mapping/ GetterMetadata.php, line 33
Namespace
Symfony\Component\Validator\MappingView source
class GetterMetadata extends MemberMetadata {
/**
* Constructor.
*
* @param string $class The class the getter is defined on
* @param string $property The property which the getter returns
*
* @throws ValidatorException
*/
public function __construct($class, $property) {
$getMethod = 'get' . ucfirst($property);
$isMethod = 'is' . ucfirst($property);
$hasMethod = 'has' . ucfirst($property);
if (method_exists($class, $getMethod)) {
$method = $getMethod;
}
elseif (method_exists($class, $isMethod)) {
$method = $isMethod;
}
elseif (method_exists($class, $hasMethod)) {
$method = $hasMethod;
}
else {
throw new ValidatorException(sprintf('Neither of these methods exist in class %s: %s, %s, %s', $class, $getMethod, $isMethod, $hasMethod));
}
parent::__construct($class, $method, $property);
}
/**
* {@inheritdoc}
*/
public function getPropertyValue($object) {
return $this
->newReflectionMember($object)
->invoke($object);
}
/**
* {@inheritdoc}
*/
protected function newReflectionMember($objectOrClassName) {
return new \ReflectionMethod($objectOrClassName, $this
->getName());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GenericMetadata:: |
public | property | The strategy for cascading objects. | |
GenericMetadata:: |
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:: |
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:: |
public | property | The strategy for traversing traversable objects. | 1 |
GenericMetadata:: |
public | function | Adds an list of constraints. | |
GenericMetadata:: |
public | function |
Aware of the global group (* group). Overrides MetadataInterface:: |
|
GenericMetadata:: |
public | function |
Returns the strategy for cascading objects. Overrides MetadataInterface:: |
1 |
GenericMetadata:: |
public | function |
Returns all constraints of this element. Overrides MetadataInterface:: |
|
GenericMetadata:: |
public | function |
Returns the strategy for traversing traversable objects. Overrides MetadataInterface:: |
|
GenericMetadata:: |
public | function | Returns whether this element has any constraints. | |
GenericMetadata:: |
public | function | Clones this object. | |
GetterMetadata:: |
public | function |
Extracts the value of the property from the given container. Overrides PropertyMetadataInterface:: |
|
GetterMetadata:: |
protected | function |
Creates a new reflection instance for accessing the member's value. Overrides MemberMetadata:: |
|
GetterMetadata:: |
public | function |
Constructor. Overrides MemberMetadata:: |
|
MemberMetadata:: |
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:: |
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:: |
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:: |
private | property | ||
MemberMetadata:: |
public | function |
Overrides GenericMetadata:: |
|
MemberMetadata:: |
public | function |
Adds a constraint. Overrides GenericMetadata:: |
|
MemberMetadata:: |
public | function |
Returns the name of the backing PHP class. Overrides ClassBasedInterface:: |
|
MemberMetadata:: |
public | function | Returns the name of the member. | |
MemberMetadata:: |
public | function |
Returns the name of the property. Overrides PropertyMetadataInterface:: |
|
MemberMetadata:: |
public | function | Returns the reflection instance for accessing the member's value. | |
MemberMetadata:: |
public | function | Returns whether objects stored in this member should be validated. | |
MemberMetadata:: |
public | function | Returns whether arrays or traversable objects stored in this member should be traversed and validated in each entry. | |
MemberMetadata:: |
public | function | Returns whether arrays or traversable objects stored in this member should be traversed recursively for inner arrays/traversable objects. | |
MemberMetadata:: |
public | function | Returns whether this member is private. | |
MemberMetadata:: |
public | function | Returns whether this member is protected. | |
MemberMetadata:: |
public | function | Returns whether this member is public. | |
MemberMetadata:: |
public | function |
Returns the names of the properties that should be serialized. Overrides GenericMetadata:: |