You are here

class GetterMetadata in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/validator/Mapping/GetterMetadata.php \Symfony\Component\Validator\Mapping\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 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

Expanded class hierarchy of GetterMetadata

See also

PropertyMetadataInterface

1 file declares its use of GetterMetadata
GetterMetadataTest.php in vendor/symfony/validator/Tests/Mapping/GetterMetadataTest.php

File

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

Namespace

Symfony\Component\Validator\Mapping
View 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

Namesort descending Modifiers Type Description Overrides
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::getCascadingStrategy public function Returns the strategy for cascading objects. Overrides MetadataInterface::getCascadingStrategy 1
GenericMetadata::getConstraints public function Returns all constraints of this element. 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's value. Overrides MemberMetadata::newReflectionMember
GetterMetadata::__construct public function Constructor. Overrides MemberMetadata::__construct
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::accept Deprecated public function Overrides GenericMetadata::accept
MemberMetadata::addConstraint public function Adds a constraint. Overrides GenericMetadata::addConstraint
MemberMetadata::getClassName public function Returns the name of the backing PHP class. Overrides ClassBasedInterface::getClassName
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::isCascaded Deprecated public function Returns whether objects stored in this member should be validated.
MemberMetadata::isCollectionCascaded Deprecated public function Returns whether arrays or traversable objects stored in this member should be traversed and validated in each entry.
MemberMetadata::isCollectionCascadedDeeply Deprecated public function Returns whether arrays or traversable objects stored in this member should be traversed recursively for inner arrays/traversable objects.
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