|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Validator\Tests\Fixtures\NestedAttribute; |
| 13 | + |
| 14 | +use Symfony\Component\Validator\Constraints as Assert; |
| 15 | +use Symfony\Component\Validator\Context\ExecutionContextInterface; |
| 16 | +use Symfony\Component\Validator\Tests\Fixtures\Attribute\EntityParent; |
| 17 | +use Symfony\Component\Validator\Tests\Fixtures\EntityInterfaceB; |
| 18 | +use Symfony\Component\Validator\Tests\Fixtures\CallbackClass; |
| 19 | +use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; |
| 20 | + |
| 21 | +#[ |
| 22 | + ConstraintA, |
| 23 | + Assert\GroupSequence(['Foo', 'Entity']), |
| 24 | + Assert\Callback([CallbackClass::class, 'callback']), |
| 25 | +] |
| 26 | +class Entity extends EntityParent implements EntityInterfaceB |
| 27 | +{ |
| 28 | + #[ |
| 29 | + Assert\NotNull, |
| 30 | + Assert\Range(min: 3), |
| 31 | + Assert\All([ |
| 32 | + new Assert\NotNull(), |
| 33 | + new Assert\Range(min: 3), |
| 34 | + ]), |
| 35 | + Assert\All( |
| 36 | + constraints: [ |
| 37 | + new Assert\NotNull(), |
| 38 | + new Assert\Range(min: 3), |
| 39 | + ], |
| 40 | + ), |
| 41 | + Assert\Collection( |
| 42 | + fields: [ |
| 43 | + 'foo' => [ |
| 44 | + new Assert\NotNull(), |
| 45 | + new Assert\Range(min: 3), |
| 46 | + ], |
| 47 | + 'bar' => new Assert\Range(min: 5), |
| 48 | + 'baz' => new Assert\Required([new Assert\Email()]), |
| 49 | + 'qux' => new Assert\Optional([new Assert\NotBlank()]), |
| 50 | + ], |
| 51 | + allowExtraFields: true |
| 52 | + ), |
| 53 | + Assert\Choice(choices: ['A', 'B'], message: 'Must be one of %choices%'), |
| 54 | + Assert\AtLeastOneOf( |
| 55 | + constraints: [ |
| 56 | + new Assert\NotNull(), |
| 57 | + new Assert\Range(min: 3), |
| 58 | + ], |
| 59 | + message: 'foo', |
| 60 | + includeInternalMessages: false, |
| 61 | + ), |
| 62 | + Assert\Sequentially([ |
| 63 | + new Assert\NotBlank(), |
| 64 | + new Assert\Range(min: 5), |
| 65 | + ]), |
| 66 | + ] |
| 67 | + public $firstName; |
| 68 | + #[Assert\Valid] |
| 69 | + public $childA; |
| 70 | + #[Assert\Valid] |
| 71 | + public $childB; |
| 72 | + protected $lastName; |
| 73 | + public $reference; |
| 74 | + public $reference2; |
| 75 | + private $internal; |
| 76 | + public $data = 'Overridden data'; |
| 77 | + public $initialized = false; |
| 78 | + |
| 79 | + public function __construct($internal = null) |
| 80 | + { |
| 81 | + $this->internal = $internal; |
| 82 | + } |
| 83 | + |
| 84 | + public function getFirstName() |
| 85 | + { |
| 86 | + return $this->firstName; |
| 87 | + } |
| 88 | + |
| 89 | + public function getInternal() |
| 90 | + { |
| 91 | + return $this->internal.' from getter'; |
| 92 | + } |
| 93 | + |
| 94 | + public function setLastName($lastName) |
| 95 | + { |
| 96 | + $this->lastName = $lastName; |
| 97 | + } |
| 98 | + |
| 99 | + #[Assert\NotNull] |
| 100 | + public function getLastName() |
| 101 | + { |
| 102 | + return $this->lastName; |
| 103 | + } |
| 104 | + |
| 105 | + public function getValid() |
| 106 | + { |
| 107 | + } |
| 108 | + |
| 109 | + #[Assert\IsTrue] |
| 110 | + public function isValid() |
| 111 | + { |
| 112 | + return 'valid'; |
| 113 | + } |
| 114 | + |
| 115 | + #[Assert\IsTrue] |
| 116 | + public function hasPermissions() |
| 117 | + { |
| 118 | + return 'permissions'; |
| 119 | + } |
| 120 | + |
| 121 | + public function getData() |
| 122 | + { |
| 123 | + return 'Overridden data'; |
| 124 | + } |
| 125 | + |
| 126 | + #[Assert\Callback(payload: 'foo')] |
| 127 | + public function validateMe(ExecutionContextInterface $context) |
| 128 | + { |
| 129 | + } |
| 130 | + |
| 131 | + #[Assert\Callback] |
| 132 | + public static function validateMeStatic($object, ExecutionContextInterface $context) |
| 133 | + { |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @return mixed |
| 138 | + */ |
| 139 | + public function getChildA() |
| 140 | + { |
| 141 | + return $this->childA; |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * @param mixed $childA |
| 146 | + */ |
| 147 | + public function setChildA($childA) |
| 148 | + { |
| 149 | + $this->childA = $childA; |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * @return mixed |
| 154 | + */ |
| 155 | + public function getChildB() |
| 156 | + { |
| 157 | + return $this->childB; |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * @param mixed $childB |
| 162 | + */ |
| 163 | + public function setChildB($childB) |
| 164 | + { |
| 165 | + $this->childB = $childB; |
| 166 | + } |
| 167 | + |
| 168 | + public function getReference() |
| 169 | + { |
| 170 | + return $this->reference; |
| 171 | + } |
| 172 | +} |
0 commit comments