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
GetterMetadata.php
36 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 GetterMetadata extends MemberMetadata |
| 6 | { |
| 7 | public function __construct(string $class, string $property, ?string $method = null) |
| 8 | { |
| 9 | if (null === $method) { |
| 10 | $getMethod = 'get' . \ucfirst($property); |
| 11 | $isMethod = 'is' . \ucfirst($property); |
| 12 | $hasMethod = 'has' . \ucfirst($property); |
| 13 | if (\method_exists($class, $getMethod)) { |
| 14 | $method = $getMethod; |
| 15 | } elseif (\method_exists($class, $isMethod)) { |
| 16 | $method = $isMethod; |
| 17 | } elseif (\method_exists($class, $hasMethod)) { |
| 18 | $method = $hasMethod; |
| 19 | } else { |
| 20 | throw new ValidatorException(\sprintf('Neither of these methods exist in class "%s": "%s", "%s", "%s".', $class, $getMethod, $isMethod, $hasMethod)); |
| 21 | } |
| 22 | } elseif (!\method_exists($class, $method)) { |
| 23 | throw new ValidatorException(\sprintf('The "%s()" method does not exist in class "%s".', $method, $class)); |
| 24 | } |
| 25 | parent::__construct($class, $method, $property); |
| 26 | } |
| 27 | public function getPropertyValue($object) |
| 28 | { |
| 29 | return $this->newReflectionMember($object)->invoke($object); |
| 30 | } |
| 31 | protected function newReflectionMember($objectOrClassName) |
| 32 | { |
| 33 | return new \ReflectionMethod($objectOrClassName, $this->getName()); |
| 34 | } |
| 35 | } |
| 36 |