Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GetterMetadata.php

class GetterMetadata

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 "get", "is" or "has". 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 \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\GetterMetadata extends \Symfony\Component\Validator\Mapping\MemberMetadata

Expanded class hierarchy of GetterMetadata

See also

PropertyMetadataInterface

1 file declares its use of GetterMetadata
RecursiveContextualValidator.php in vendor/symfony/validator/Validator/RecursiveContextualValidator.php

File

vendor/symfony/validator/Mapping/GetterMetadata.php, line 33

Namespace

Symfony\Component\Validator\Mapping
View source
class GetterMetadata extends MemberMetadata {
    
    /**
     * @param string      $class    The class the getter is defined on
     * @param string      $property The property which the getter returns
     * @param string|null $method   The method that is called to retrieve the value being validated (null for auto-detection)
     *
     * @throws ValidatorException
     */
    public function __construct(string $class, string $property, ?string $method = null) {
        if (null === $method) {
            $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));
            }
        }
        elseif (!method_exists($class, $method)) {
            throw new ValidatorException(\sprintf('The "%s()" method does not exist in class "%s".', $method, $class));
        }
        parent::__construct($class, $method, $property);
    }
    public function getPropertyValue(mixed $object) : mixed {
        return $this->newReflectionMember($object)
            ->invoke($object);
    }
    protected function newReflectionMember(object|string $objectOrClassName) : \ReflectionMethod|\ReflectionProperty {
        return new \ReflectionMethod($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&#039; 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&#039; 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.
GetterMetadata::getPropertyValue public function Extracts the value of the property from the given container. Overrides PropertyMetadataInterface::getPropertyValue
GetterMetadata::newReflectionMember protected function Creates a new reflection instance for accessing the member&#039;s value. Overrides MemberMetadata::newReflectionMember
GetterMetadata::__construct public function Overrides MemberMetadata::__construct
MemberMetadata::$class public property @internal This property is public in order to reduce the size of the
class&#039; 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&#039; 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&#039; 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&#039;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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal