DependencyInjection
1 year ago
Extractor
1 year ago
PhpStan
1 year ago
Util
1 year ago
CHANGELOG.md
1 year ago
LICENSE
1 year ago
PropertyAccessExtractorInterface.php
1 year ago
PropertyDescriptionExtractorInterface.php
1 year ago
PropertyInfoCacheExtractor.php
1 year ago
PropertyInfoExtractor.php
1 year ago
PropertyInfoExtractorInterface.php
1 year ago
PropertyInitializableExtractorInterface.php
1 year ago
PropertyListExtractorInterface.php
1 year ago
PropertyReadInfo.php
1 year ago
PropertyReadInfoExtractorInterface.php
1 year ago
PropertyTypeExtractorInterface.php
1 year ago
PropertyWriteInfo.php
1 year ago
PropertyWriteInfoExtractorInterface.php
1 year ago
README.md
1 year ago
Type.php
1 year ago
composer.json
1 year ago
PropertyWriteInfo.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 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\PropertyInfo; |
| 13 | |
| 14 | /** |
| 15 | * The write mutator defines how a property can be written. |
| 16 | * |
| 17 | * @author Joel Wurtz <jwurtz@jolicode.com> |
| 18 | * |
| 19 | * @internal |
| 20 | */ |
| 21 | final class PropertyWriteInfo |
| 22 | { |
| 23 | public const TYPE_NONE = 'none'; |
| 24 | public const TYPE_METHOD = 'method'; |
| 25 | public const TYPE_PROPERTY = 'property'; |
| 26 | public const TYPE_ADDER_AND_REMOVER = 'adder_and_remover'; |
| 27 | public const TYPE_CONSTRUCTOR = 'constructor'; |
| 28 | |
| 29 | public const VISIBILITY_PUBLIC = 'public'; |
| 30 | public const VISIBILITY_PROTECTED = 'protected'; |
| 31 | public const VISIBILITY_PRIVATE = 'private'; |
| 32 | |
| 33 | private $type; |
| 34 | private $name; |
| 35 | private $visibility; |
| 36 | private $static; |
| 37 | private $adderInfo; |
| 38 | private $removerInfo; |
| 39 | private $errors = []; |
| 40 | |
| 41 | public function __construct(string $type = self::TYPE_NONE, ?string $name = null, ?string $visibility = null, ?bool $static = null) |
| 42 | { |
| 43 | $this->type = $type; |
| 44 | $this->name = $name; |
| 45 | $this->visibility = $visibility; |
| 46 | $this->static = $static; |
| 47 | } |
| 48 | |
| 49 | public function getType(): string |
| 50 | { |
| 51 | return $this->type; |
| 52 | } |
| 53 | |
| 54 | public function getName(): string |
| 55 | { |
| 56 | if (null === $this->name) { |
| 57 | throw new \LogicException("Calling getName() when having a mutator of type {$this->type} is not tolerated."); |
| 58 | } |
| 59 | |
| 60 | return $this->name; |
| 61 | } |
| 62 | |
| 63 | public function setAdderInfo(self $adderInfo): void |
| 64 | { |
| 65 | $this->adderInfo = $adderInfo; |
| 66 | } |
| 67 | |
| 68 | public function getAdderInfo(): self |
| 69 | { |
| 70 | if (null === $this->adderInfo) { |
| 71 | throw new \LogicException("Calling getAdderInfo() when having a mutator of type {$this->type} is not tolerated."); |
| 72 | } |
| 73 | |
| 74 | return $this->adderInfo; |
| 75 | } |
| 76 | |
| 77 | public function setRemoverInfo(self $removerInfo): void |
| 78 | { |
| 79 | $this->removerInfo = $removerInfo; |
| 80 | } |
| 81 | |
| 82 | public function getRemoverInfo(): self |
| 83 | { |
| 84 | if (null === $this->removerInfo) { |
| 85 | throw new \LogicException("Calling getRemoverInfo() when having a mutator of type {$this->type} is not tolerated."); |
| 86 | } |
| 87 | |
| 88 | return $this->removerInfo; |
| 89 | } |
| 90 | |
| 91 | public function getVisibility(): string |
| 92 | { |
| 93 | if (null === $this->visibility) { |
| 94 | throw new \LogicException("Calling getVisibility() when having a mutator of type {$this->type} is not tolerated."); |
| 95 | } |
| 96 | |
| 97 | return $this->visibility; |
| 98 | } |
| 99 | |
| 100 | public function isStatic(): bool |
| 101 | { |
| 102 | if (null === $this->static) { |
| 103 | throw new \LogicException("Calling isStatic() when having a mutator of type {$this->type} is not tolerated."); |
| 104 | } |
| 105 | |
| 106 | return $this->static; |
| 107 | } |
| 108 | |
| 109 | public function setErrors(array $errors): void |
| 110 | { |
| 111 | $this->errors = $errors; |
| 112 | } |
| 113 | |
| 114 | public function getErrors(): array |
| 115 | { |
| 116 | return $this->errors; |
| 117 | } |
| 118 | |
| 119 | public function hasErrors(): bool |
| 120 | { |
| 121 | return (bool) \count($this->errors); |
| 122 | } |
| 123 | } |
| 124 |