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/persistence/src/Persistence/Reflection | |
| 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/persistence/src/Persistence/Reflection')
6 files changed, 425 insertions, 0 deletions
diff --git a/vendor/doctrine/persistence/src/Persistence/Reflection/EnumReflectionProperty.php b/vendor/doctrine/persistence/src/Persistence/Reflection/EnumReflectionProperty.php new file mode 100644 index 0000000..114b9db --- /dev/null +++ b/vendor/doctrine/persistence/src/Persistence/Reflection/EnumReflectionProperty.php | |||
| @@ -0,0 +1,181 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\Persistence\Reflection; | ||
| 6 | |||
| 7 | use BackedEnum; | ||
| 8 | use ReflectionClass; | ||
| 9 | use ReflectionProperty; | ||
| 10 | use ReflectionType; | ||
| 11 | use ReturnTypeWillChange; | ||
| 12 | |||
| 13 | use function array_map; | ||
| 14 | use function is_array; | ||
| 15 | use function reset; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * PHP Enum Reflection Property - special override for backed enums. | ||
| 19 | */ | ||
| 20 | class EnumReflectionProperty extends ReflectionProperty | ||
| 21 | { | ||
| 22 | /** @var ReflectionProperty */ | ||
| 23 | private $originalReflectionProperty; | ||
| 24 | |||
| 25 | /** @var class-string<BackedEnum> */ | ||
| 26 | private $enumType; | ||
| 27 | |||
| 28 | /** @param class-string<BackedEnum> $enumType */ | ||
| 29 | public function __construct(ReflectionProperty $originalReflectionProperty, string $enumType) | ||
| 30 | { | ||
| 31 | $this->originalReflectionProperty = $originalReflectionProperty; | ||
| 32 | $this->enumType = $enumType; | ||
| 33 | } | ||
| 34 | |||
| 35 | /** | ||
| 36 | * {@inheritDoc} | ||
| 37 | * | ||
| 38 | * @psalm-external-mutation-free | ||
| 39 | */ | ||
| 40 | public function getDeclaringClass(): ReflectionClass | ||
| 41 | { | ||
| 42 | return $this->originalReflectionProperty->getDeclaringClass(); | ||
| 43 | } | ||
| 44 | |||
| 45 | /** | ||
| 46 | * {@inheritDoc} | ||
| 47 | * | ||
| 48 | * @psalm-external-mutation-free | ||
| 49 | */ | ||
| 50 | public function getName(): string | ||
| 51 | { | ||
| 52 | return $this->originalReflectionProperty->getName(); | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * {@inheritDoc} | ||
| 57 | * | ||
| 58 | * @psalm-external-mutation-free | ||
| 59 | */ | ||
| 60 | public function getType(): ?ReflectionType | ||
| 61 | { | ||
| 62 | return $this->originalReflectionProperty->getType(); | ||
| 63 | } | ||
| 64 | |||
| 65 | /** | ||
| 66 | * {@inheritDoc} | ||
| 67 | */ | ||
| 68 | public function getAttributes(?string $name = null, int $flags = 0): array | ||
| 69 | { | ||
| 70 | return $this->originalReflectionProperty->getAttributes($name, $flags); | ||
| 71 | } | ||
| 72 | |||
| 73 | /** | ||
| 74 | * {@inheritDoc} | ||
| 75 | * | ||
| 76 | * Converts enum instance to its value. | ||
| 77 | * | ||
| 78 | * @param object|null $object | ||
| 79 | * | ||
| 80 | * @return int|string|int[]|string[]|null | ||
| 81 | */ | ||
| 82 | #[ReturnTypeWillChange] | ||
| 83 | public function getValue($object = null) | ||
| 84 | { | ||
| 85 | if ($object === null) { | ||
| 86 | return null; | ||
| 87 | } | ||
| 88 | |||
| 89 | $enum = $this->originalReflectionProperty->getValue($object); | ||
| 90 | |||
| 91 | if ($enum === null) { | ||
| 92 | return null; | ||
| 93 | } | ||
| 94 | |||
| 95 | return $this->fromEnum($enum); | ||
| 96 | } | ||
| 97 | |||
| 98 | /** | ||
| 99 | * Converts enum value to enum instance. | ||
| 100 | * | ||
| 101 | * @param object $object | ||
| 102 | * @param mixed $value | ||
| 103 | */ | ||
| 104 | public function setValue($object, $value = null): void | ||
| 105 | { | ||
| 106 | if ($value !== null) { | ||
| 107 | $value = $this->toEnum($value); | ||
| 108 | } | ||
| 109 | |||
| 110 | $this->originalReflectionProperty->setValue($object, $value); | ||
| 111 | } | ||
| 112 | |||
| 113 | /** | ||
| 114 | * @param BackedEnum|BackedEnum[] $enum | ||
| 115 | * | ||
| 116 | * @return ($enum is BackedEnum ? (string|int) : (string[]|int[])) | ||
| 117 | */ | ||
| 118 | private function fromEnum($enum) | ||
| 119 | { | ||
| 120 | if (is_array($enum)) { | ||
| 121 | return array_map(static function (BackedEnum $enum) { | ||
| 122 | return $enum->value; | ||
| 123 | }, $enum); | ||
| 124 | } | ||
| 125 | |||
| 126 | return $enum->value; | ||
| 127 | } | ||
| 128 | |||
| 129 | /** | ||
| 130 | * @param int|string|int[]|string[]|BackedEnum|BackedEnum[] $value | ||
| 131 | * | ||
| 132 | * @return ($value is int|string|BackedEnum ? BackedEnum : BackedEnum[]) | ||
| 133 | */ | ||
| 134 | private function toEnum($value) | ||
| 135 | { | ||
| 136 | if ($value instanceof BackedEnum) { | ||
| 137 | return $value; | ||
| 138 | } | ||
| 139 | |||
| 140 | if (is_array($value)) { | ||
| 141 | $v = reset($value); | ||
| 142 | if ($v instanceof BackedEnum) { | ||
| 143 | return $value; | ||
| 144 | } | ||
| 145 | |||
| 146 | return array_map([$this->enumType, 'from'], $value); | ||
| 147 | } | ||
| 148 | |||
| 149 | return $this->enumType::from($value); | ||
| 150 | } | ||
| 151 | |||
| 152 | /** | ||
| 153 | * {@inheritDoc} | ||
| 154 | * | ||
| 155 | * @psalm-external-mutation-free | ||
| 156 | */ | ||
| 157 | public function getModifiers(): int | ||
| 158 | { | ||
| 159 | return $this->originalReflectionProperty->getModifiers(); | ||
| 160 | } | ||
| 161 | |||
| 162 | /** | ||
| 163 | * {@inheritDoc} | ||
| 164 | * | ||
| 165 | * @psalm-external-mutation-free | ||
| 166 | */ | ||
| 167 | public function getDocComment(): string|false | ||
| 168 | { | ||
| 169 | return $this->originalReflectionProperty->getDocComment(); | ||
| 170 | } | ||
| 171 | |||
| 172 | /** | ||
| 173 | * {@inheritDoc} | ||
| 174 | * | ||
| 175 | * @psalm-external-mutation-free | ||
| 176 | */ | ||
| 177 | public function isPrivate(): bool | ||
| 178 | { | ||
| 179 | return $this->originalReflectionProperty->isPrivate(); | ||
| 180 | } | ||
| 181 | } | ||
diff --git a/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimePublicReflectionProperty.php b/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimePublicReflectionProperty.php new file mode 100644 index 0000000..e2367ec --- /dev/null +++ b/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimePublicReflectionProperty.php | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\Persistence\Reflection; | ||
| 6 | |||
| 7 | use Doctrine\Common\Proxy\Proxy; | ||
| 8 | use ReflectionProperty; | ||
| 9 | use ReturnTypeWillChange; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * PHP Runtime Reflection Public Property - special overrides for public properties. | ||
| 13 | * | ||
| 14 | * @deprecated since version 3.1, use RuntimeReflectionProperty instead. | ||
| 15 | */ | ||
| 16 | class RuntimePublicReflectionProperty extends ReflectionProperty | ||
| 17 | { | ||
| 18 | /** | ||
| 19 | * {@inheritDoc} | ||
| 20 | * | ||
| 21 | * Returns the value of a public property without calling | ||
| 22 | * `__get` on the provided $object if it exists. | ||
| 23 | * | ||
| 24 | * @return mixed | ||
| 25 | */ | ||
| 26 | #[ReturnTypeWillChange] | ||
| 27 | public function getValue($object = null) | ||
| 28 | { | ||
| 29 | return $object !== null ? ((array) $object)[$this->getName()] ?? null : parent::getValue(); | ||
| 30 | } | ||
| 31 | |||
| 32 | /** | ||
| 33 | * {@inheritDoc} | ||
| 34 | * | ||
| 35 | * Avoids triggering lazy loading via `__set` if the provided object | ||
| 36 | * is a {@see \Doctrine\Common\Proxy\Proxy}. | ||
| 37 | * | ||
| 38 | * @link https://bugs.php.net/bug.php?id=63463 | ||
| 39 | * | ||
| 40 | * @param object|null $object | ||
| 41 | * @param mixed $value | ||
| 42 | * | ||
| 43 | * @return void | ||
| 44 | */ | ||
| 45 | #[ReturnTypeWillChange] | ||
| 46 | public function setValue($object, $value = null) | ||
| 47 | { | ||
| 48 | if (! ($object instanceof Proxy && ! $object->__isInitialized())) { | ||
| 49 | parent::setValue($object, $value); | ||
| 50 | |||
| 51 | return; | ||
| 52 | } | ||
| 53 | |||
| 54 | $originalInitializer = $object->__getInitializer(); | ||
| 55 | $object->__setInitializer(null); | ||
| 56 | |||
| 57 | parent::setValue($object, $value); | ||
| 58 | |||
| 59 | $object->__setInitializer($originalInitializer); | ||
| 60 | } | ||
| 61 | } | ||
diff --git a/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimeReflectionProperty.php b/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimeReflectionProperty.php new file mode 100644 index 0000000..5f52056 --- /dev/null +++ b/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimeReflectionProperty.php | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\Persistence\Reflection; | ||
| 6 | |||
| 7 | use Doctrine\Common\Proxy\Proxy as CommonProxy; | ||
| 8 | use Doctrine\Persistence\Proxy; | ||
| 9 | use ReflectionProperty; | ||
| 10 | use ReturnTypeWillChange; | ||
| 11 | |||
| 12 | use function ltrim; | ||
| 13 | use function method_exists; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * PHP Runtime Reflection Property. | ||
| 17 | * | ||
| 18 | * Avoids triggering lazy loading if the provided object | ||
| 19 | * is a {@see \Doctrine\Persistence\Proxy}. | ||
| 20 | */ | ||
| 21 | class RuntimeReflectionProperty extends ReflectionProperty | ||
| 22 | { | ||
| 23 | /** @var string */ | ||
| 24 | private $key; | ||
| 25 | |||
| 26 | /** @param class-string $class */ | ||
| 27 | public function __construct(string $class, string $name) | ||
| 28 | { | ||
| 29 | parent::__construct($class, $name); | ||
| 30 | |||
| 31 | $this->key = $this->isPrivate() ? "\0" . ltrim($class, '\\') . "\0" . $name : ($this->isProtected() ? "\0*\0" . $name : $name); | ||
| 32 | } | ||
| 33 | |||
| 34 | /** | ||
| 35 | * {@inheritDoc} | ||
| 36 | * | ||
| 37 | * @return mixed | ||
| 38 | */ | ||
| 39 | #[ReturnTypeWillChange] | ||
| 40 | public function getValue($object = null) | ||
| 41 | { | ||
| 42 | if ($object === null) { | ||
| 43 | return parent::getValue($object); | ||
| 44 | } | ||
| 45 | |||
| 46 | return ((array) $object)[$this->key] ?? null; | ||
| 47 | } | ||
| 48 | |||
| 49 | /** | ||
| 50 | * {@inheritDoc} | ||
| 51 | * | ||
| 52 | * @param object|null $object | ||
| 53 | * @param mixed $value | ||
| 54 | * | ||
| 55 | * @return void | ||
| 56 | */ | ||
| 57 | #[ReturnTypeWillChange] | ||
| 58 | public function setValue($object, $value = null) | ||
| 59 | { | ||
| 60 | if (! ($object instanceof Proxy && ! $object->__isInitialized())) { | ||
| 61 | parent::setValue($object, $value); | ||
| 62 | |||
| 63 | return; | ||
| 64 | } | ||
| 65 | |||
| 66 | if ($object instanceof CommonProxy) { | ||
| 67 | $originalInitializer = $object->__getInitializer(); | ||
| 68 | $object->__setInitializer(null); | ||
| 69 | |||
| 70 | parent::setValue($object, $value); | ||
| 71 | |||
| 72 | $object->__setInitializer($originalInitializer); | ||
| 73 | |||
| 74 | return; | ||
| 75 | } | ||
| 76 | |||
| 77 | if (! method_exists($object, '__setInitialized')) { | ||
| 78 | return; | ||
| 79 | } | ||
| 80 | |||
| 81 | $object->__setInitialized(true); | ||
| 82 | |||
| 83 | parent::setValue($object, $value); | ||
| 84 | |||
| 85 | $object->__setInitialized(false); | ||
| 86 | } | ||
| 87 | } | ||
diff --git a/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultReflectionProperty.php b/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultReflectionProperty.php new file mode 100644 index 0000000..5e70620 --- /dev/null +++ b/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultReflectionProperty.php | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\Persistence\Reflection; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * PHP Typed No Default Reflection Property - special override for typed properties without a default value. | ||
| 9 | */ | ||
| 10 | class TypedNoDefaultReflectionProperty extends RuntimeReflectionProperty | ||
| 11 | { | ||
| 12 | use TypedNoDefaultReflectionPropertyBase; | ||
| 13 | } | ||
diff --git a/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultReflectionPropertyBase.php b/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultReflectionPropertyBase.php new file mode 100644 index 0000000..fff68a4 --- /dev/null +++ b/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultReflectionPropertyBase.php | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\Persistence\Reflection; | ||
| 6 | |||
| 7 | use Closure; | ||
| 8 | use ReturnTypeWillChange; | ||
| 9 | |||
| 10 | use function assert; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * PHP Typed No Default Reflection Property Base - special override for typed properties without a default value. | ||
| 14 | * | ||
| 15 | * @internal since version 3.1 | ||
| 16 | */ | ||
| 17 | trait TypedNoDefaultReflectionPropertyBase | ||
| 18 | { | ||
| 19 | /** | ||
| 20 | * {@inheritDoc} | ||
| 21 | * | ||
| 22 | * Checks that a typed property is initialized before accessing its value. | ||
| 23 | * This is necessary to avoid PHP error "Error: Typed property must not be accessed before initialization". | ||
| 24 | * Should be used only for reflecting typed properties without a default value. | ||
| 25 | * | ||
| 26 | * @param object|null $object | ||
| 27 | * | ||
| 28 | * @return mixed | ||
| 29 | */ | ||
| 30 | #[ReturnTypeWillChange] | ||
| 31 | public function getValue($object = null) | ||
| 32 | { | ||
| 33 | return $object !== null && $this->isInitialized($object) ? parent::getValue($object) : null; | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * {@inheritDoc} | ||
| 38 | * | ||
| 39 | * Works around the problem with setting typed no default properties to | ||
| 40 | * NULL which is not supported, instead unset() to uninitialize. | ||
| 41 | * | ||
| 42 | * @link https://github.com/doctrine/orm/issues/7999 | ||
| 43 | * | ||
| 44 | * @param object|null $object | ||
| 45 | * | ||
| 46 | * @return void | ||
| 47 | */ | ||
| 48 | #[ReturnTypeWillChange] | ||
| 49 | public function setValue($object, $value = null) | ||
| 50 | { | ||
| 51 | if ($value === null && $this->hasType() && ! $this->getType()->allowsNull()) { | ||
| 52 | $propertyName = $this->getName(); | ||
| 53 | |||
| 54 | $unsetter = function () use ($propertyName): void { | ||
| 55 | unset($this->$propertyName); | ||
| 56 | }; | ||
| 57 | $unsetter = $unsetter->bindTo($object, $this->getDeclaringClass()->getName()); | ||
| 58 | |||
| 59 | assert($unsetter instanceof Closure); | ||
| 60 | |||
| 61 | $unsetter(); | ||
| 62 | |||
| 63 | return; | ||
| 64 | } | ||
| 65 | |||
| 66 | parent::setValue($object, $value); | ||
| 67 | } | ||
| 68 | } | ||
diff --git a/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultRuntimePublicReflectionProperty.php b/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultRuntimePublicReflectionProperty.php new file mode 100644 index 0000000..181172f --- /dev/null +++ b/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultRuntimePublicReflectionProperty.php | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\Persistence\Reflection; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * PHP Typed No Default Runtime Public Reflection Property - special override for public typed properties without a default value. | ||
| 9 | * | ||
| 10 | * @deprecated since version 3.1, use TypedNoDefaultReflectionProperty instead. | ||
| 11 | */ | ||
| 12 | class TypedNoDefaultRuntimePublicReflectionProperty extends RuntimePublicReflectionProperty | ||
| 13 | { | ||
| 14 | use TypedNoDefaultReflectionPropertyBase; | ||
| 15 | } | ||
