Factory
1 year ago
Loader
1 year ago
AutoMappingStrategy.php
4 years ago
CascadingStrategy.php
4 years ago
ClassMetadata.php
1 year ago
ClassMetadataInterface.php
4 years ago
GenericMetadata.php
4 years ago
GetterMetadata.php
1 year ago
MemberMetadata.php
4 years ago
MetadataInterface.php
4 years ago
PropertyMetadata.php
6 months ago
PropertyMetadataInterface.php
4 years ago
TraversalStrategy.php
4 years ago
index.php
3 years ago
PropertyMetadata.php
47 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator\Mapping; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Exception\ValidatorException; |
| 5 | class PropertyMetadata extends MemberMetadata |
| 6 | { |
| 7 | public function __construct(string $class, string $name) |
| 8 | { |
| 9 | if (!\property_exists($class, $name)) { |
| 10 | throw new ValidatorException(\sprintf('Property "%s" does not exist in class "%s".', $name, $class)); |
| 11 | } |
| 12 | parent::__construct($class, $name, $name); |
| 13 | } |
| 14 | public function getPropertyValue($object) |
| 15 | { |
| 16 | $reflProperty = $this->getReflectionMember($object); |
| 17 | if (\PHP_VERSION_ID >= 70400 && $reflProperty->hasType() && !$reflProperty->isInitialized($object)) { |
| 18 | // There is no way to check if a property has been unset or if it is uninitialized. |
| 19 | // When trying to access an uninitialized property, __get method is triggered. |
| 20 | // If __get method is not present, no fallback is possible |
| 21 | // Otherwise we need to catch an Error in case we are trying to access an uninitialized but set property. |
| 22 | if (!\method_exists($object, '__get')) { |
| 23 | return null; |
| 24 | } |
| 25 | try { |
| 26 | return $reflProperty->getValue($object); |
| 27 | } catch (\Error $e) { |
| 28 | return null; |
| 29 | } |
| 30 | } |
| 31 | return $reflProperty->getValue($object); |
| 32 | } |
| 33 | protected function newReflectionMember($objectOrClassName) |
| 34 | { |
| 35 | $originalClass = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName); |
| 36 | while (!\property_exists($objectOrClassName, $this->getName())) { |
| 37 | $objectOrClassName = \get_parent_class($objectOrClassName); |
| 38 | if (\false === $objectOrClassName) { |
| 39 | throw new ValidatorException(\sprintf('Property "%s" does not exist in class "%s".', $this->getName(), $originalClass)); |
| 40 | } |
| 41 | } |
| 42 | $member = new \ReflectionProperty($objectOrClassName, $this->getName()); |
| 43 | if (PHP_VERSION_ID < 80100) { $member->setAccessible( \true ); } |
| 44 | return $member; |
| 45 | } |
| 46 | } |
| 47 |