summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Mapping/ReflectionReadonlyProperty.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Mapping/ReflectionReadonlyProperty.php
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-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.php49
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
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Mapping;
6
7use InvalidArgumentException;
8use LogicException;
9use ReflectionProperty;
10
11use function assert;
12use function func_get_args;
13use function func_num_args;
14use function is_object;
15use function sprintf;
16
17/** @internal */
18final 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}