You are here

class PropertyMetadata in Plug 7

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

Expanded class hierarchy of PropertyMetadata

See also

PropertyMetadataInterface

2 files declare their use of PropertyMetadata
AbstractConstraintValidatorTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php
PropertyMetadataTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php

File

lib/Symfony/validator/Symfony/Component/Validator/Mapping/PropertyMetadata.php, line 29

Namespace

Symfony\Component\Validator\Mapping
View source
class PropertyMetadata extends MemberMetadata {

  /**
   * Constructor.
   *
   * @param string $class The class this property is defined on
   * @param string $name  The name of this property
   *
   * @throws ValidatorException
   */
  public function __construct($class, $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);
  }

  /**
   * {@inheritdoc}
   */
  public function getPropertyValue($object) {
    return $this
      ->getReflectionMember($object)
      ->getValue($object);
  }

  /**
   * {@inheritdoc}
   */
  protected function newReflectionMember($objectOrClassName) {
    $class = new \ReflectionClass($objectOrClassName);
    while (!$class
      ->hasProperty($this
      ->getName())) {
      $class = $class
        ->getParentClass();
    }
    $member = new \ReflectionProperty($class
      ->getName(), $this
      ->getName());
    $member
      ->setAccessible(true);
    return $member;
  }

}

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.
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
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 Constructor. Overrides MemberMetadata::__construct