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
MemberMetadata.php
74 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator\Mapping; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Constraint; |
| 5 | use MailPoetVendor\Symfony\Component\Validator\Constraints\Composite; |
| 6 | use MailPoetVendor\Symfony\Component\Validator\Exception\ConstraintDefinitionException; |
| 7 | abstract class MemberMetadata extends GenericMetadata implements PropertyMetadataInterface |
| 8 | { |
| 9 | public $class; |
| 10 | public $name; |
| 11 | public $property; |
| 12 | private $reflMember = []; |
| 13 | public function __construct(string $class, string $name, string $property) |
| 14 | { |
| 15 | $this->class = $class; |
| 16 | $this->name = $name; |
| 17 | $this->property = $property; |
| 18 | } |
| 19 | public function addConstraint(Constraint $constraint) |
| 20 | { |
| 21 | $this->checkConstraint($constraint); |
| 22 | parent::addConstraint($constraint); |
| 23 | return $this; |
| 24 | } |
| 25 | public function __sleep() |
| 26 | { |
| 27 | return \array_merge(parent::__sleep(), ['class', 'name', 'property']); |
| 28 | } |
| 29 | public function getName() |
| 30 | { |
| 31 | return $this->name; |
| 32 | } |
| 33 | public function getClassName() |
| 34 | { |
| 35 | return $this->class; |
| 36 | } |
| 37 | public function getPropertyName() |
| 38 | { |
| 39 | return $this->property; |
| 40 | } |
| 41 | public function isPublic($objectOrClassName) |
| 42 | { |
| 43 | return $this->getReflectionMember($objectOrClassName)->isPublic(); |
| 44 | } |
| 45 | public function isProtected($objectOrClassName) |
| 46 | { |
| 47 | return $this->getReflectionMember($objectOrClassName)->isProtected(); |
| 48 | } |
| 49 | public function isPrivate($objectOrClassName) |
| 50 | { |
| 51 | return $this->getReflectionMember($objectOrClassName)->isPrivate(); |
| 52 | } |
| 53 | public function getReflectionMember($objectOrClassName) |
| 54 | { |
| 55 | $className = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName); |
| 56 | if (!isset($this->reflMember[$className])) { |
| 57 | $this->reflMember[$className] = $this->newReflectionMember($objectOrClassName); |
| 58 | } |
| 59 | return $this->reflMember[$className]; |
| 60 | } |
| 61 | protected abstract function newReflectionMember($objectOrClassName); |
| 62 | private function checkConstraint(Constraint $constraint) |
| 63 | { |
| 64 | if (!\in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets(), \true)) { |
| 65 | throw new ConstraintDefinitionException(\sprintf('The constraint "%s" cannot be put on properties or getters.', \get_debug_type($constraint))); |
| 66 | } |
| 67 | if ($constraint instanceof Composite) { |
| 68 | foreach ($constraint->getNestedConstraints() as $nestedConstraint) { |
| 69 | $this->checkConstraint($nestedConstraint); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 |