diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Mapping/ReflectionReadonlyProperty.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Mapping/ReflectionReadonlyProperty.php')
| -rw-r--r-- | vendor/doctrine/orm/src/Mapping/ReflectionReadonlyProperty.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Mapping/ReflectionReadonlyProperty.php b/vendor/doctrine/orm/src/Mapping/ReflectionReadonlyProperty.php new file mode 100644 index 0000000..13e9f6d --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/ReflectionReadonlyProperty.php | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Mapping; | ||
| 6 | |||
| 7 | use InvalidArgumentException; | ||
| 8 | use LogicException; | ||
| 9 | use ReflectionProperty; | ||
| 10 | |||
| 11 | use function assert; | ||
| 12 | use function func_get_args; | ||
| 13 | use function func_num_args; | ||
| 14 | use function is_object; | ||
| 15 | use function sprintf; | ||
| 16 | |||
| 17 | /** @internal */ | ||
| 18 | final class ReflectionReadonlyProperty extends ReflectionProperty | ||
| 19 | { | ||
| 20 | public function __construct( | ||
| 21 | private readonly ReflectionProperty $wrappedProperty, | ||
| 22 | ) { | ||
| 23 | if (! $wrappedProperty->isReadOnly()) { | ||
| 24 | throw new InvalidArgumentException('Given property is not readonly.'); | ||
| 25 | } | ||
| 26 | |||
| 27 | parent::__construct($wrappedProperty->class, $wrappedProperty->name); | ||
| 28 | } | ||
| 29 | |||
| 30 | public function getValue(object|null $object = null): mixed | ||
| 31 | { | ||
| 32 | return $this->wrappedProperty->getValue(...func_get_args()); | ||
| 33 | } | ||
| 34 | |||
| 35 | public function setValue(mixed $objectOrValue, mixed $value = null): void | ||
| 36 | { | ||
| 37 | if (func_num_args() < 2 || $objectOrValue === null || ! $this->isInitialized($objectOrValue)) { | ||
| 38 | $this->wrappedProperty->setValue(...func_get_args()); | ||
| 39 | |||
| 40 | return; | ||
| 41 | } | ||
| 42 | |||
| 43 | assert(is_object($objectOrValue)); | ||
| 44 | |||
| 45 | if (parent::getValue($objectOrValue) !== $value) { | ||
| 46 | throw new LogicException(sprintf('Attempting to change readonly property %s::$%s.', $this->class, $this->name)); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
