123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace Symfony\Component\Validator\Mapping;
- use Symfony\Component\Validator\Exception\ValidatorException;
- class PropertyMetadata extends MemberMetadata
- {
-
- 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);
- }
-
- public function getPropertyValue($object)
- {
- return $this->getReflectionMember($object)->getValue($object);
- }
-
- protected function newReflectionMember($objectOrClassName)
- {
- $originalClass = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName);
- 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));
- }
- }
- $member = new \ReflectionProperty($objectOrClassName, $this->getName());
- $member->setAccessible(true);
- return $member;
- }
- }
|