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/symfony/var-exporter/Internal/Registry.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/symfony/var-exporter/Internal/Registry.php')
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/Registry.php | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/vendor/symfony/var-exporter/Internal/Registry.php b/vendor/symfony/var-exporter/Internal/Registry.php new file mode 100644 index 0000000..9c41684 --- /dev/null +++ b/vendor/symfony/var-exporter/Internal/Registry.php | |||
| @@ -0,0 +1,142 @@ | |||
| 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\VarExporter\Internal; | ||
| 13 | |||
| 14 | use Symfony\Component\VarExporter\Exception\ClassNotFoundException; | ||
| 15 | use Symfony\Component\VarExporter\Exception\NotInstantiableTypeException; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * @author Nicolas Grekas <p@tchwork.com> | ||
| 19 | * | ||
| 20 | * @internal | ||
| 21 | */ | ||
| 22 | class Registry | ||
| 23 | { | ||
| 24 | public static array $reflectors = []; | ||
| 25 | public static array $prototypes = []; | ||
| 26 | public static array $factories = []; | ||
| 27 | public static array $cloneable = []; | ||
| 28 | public static array $instantiableWithoutConstructor = []; | ||
| 29 | |||
| 30 | public function __construct( | ||
| 31 | public readonly array $classes, | ||
| 32 | ) { | ||
| 33 | } | ||
| 34 | |||
| 35 | public static function unserialize($objects, $serializables) | ||
| 36 | { | ||
| 37 | $unserializeCallback = ini_set('unserialize_callback_func', __CLASS__.'::getClassReflector'); | ||
| 38 | |||
| 39 | try { | ||
| 40 | foreach ($serializables as $k => $v) { | ||
| 41 | $objects[$k] = unserialize($v); | ||
| 42 | } | ||
| 43 | } finally { | ||
| 44 | ini_set('unserialize_callback_func', $unserializeCallback); | ||
| 45 | } | ||
| 46 | |||
| 47 | return $objects; | ||
| 48 | } | ||
| 49 | |||
| 50 | public static function p($class) | ||
| 51 | { | ||
| 52 | self::getClassReflector($class, true, true); | ||
| 53 | |||
| 54 | return self::$prototypes[$class]; | ||
| 55 | } | ||
| 56 | |||
| 57 | public static function f($class) | ||
| 58 | { | ||
| 59 | $reflector = self::$reflectors[$class] ??= self::getClassReflector($class, true, false); | ||
| 60 | |||
| 61 | return self::$factories[$class] = [$reflector, 'newInstanceWithoutConstructor'](...); | ||
| 62 | } | ||
| 63 | |||
| 64 | public static function getClassReflector($class, $instantiableWithoutConstructor = false, $cloneable = null) | ||
| 65 | { | ||
| 66 | if (!($isClass = class_exists($class)) && !interface_exists($class, false) && !trait_exists($class, false)) { | ||
| 67 | throw new ClassNotFoundException($class); | ||
| 68 | } | ||
| 69 | $reflector = new \ReflectionClass($class); | ||
| 70 | |||
| 71 | if ($instantiableWithoutConstructor) { | ||
| 72 | $proto = $reflector->newInstanceWithoutConstructor(); | ||
| 73 | } elseif (!$isClass || $reflector->isAbstract()) { | ||
| 74 | throw new NotInstantiableTypeException($class); | ||
| 75 | } elseif ($reflector->name !== $class) { | ||
| 76 | $reflector = self::$reflectors[$name = $reflector->name] ??= self::getClassReflector($name, false, $cloneable); | ||
| 77 | self::$cloneable[$class] = self::$cloneable[$name]; | ||
| 78 | self::$instantiableWithoutConstructor[$class] = self::$instantiableWithoutConstructor[$name]; | ||
| 79 | self::$prototypes[$class] = self::$prototypes[$name]; | ||
| 80 | |||
| 81 | return $reflector; | ||
| 82 | } else { | ||
| 83 | try { | ||
| 84 | $proto = $reflector->newInstanceWithoutConstructor(); | ||
| 85 | $instantiableWithoutConstructor = true; | ||
| 86 | } catch (\ReflectionException) { | ||
| 87 | $proto = $reflector->implementsInterface('Serializable') && !method_exists($class, '__unserialize') ? 'C:' : 'O:'; | ||
| 88 | if ('C:' === $proto && !$reflector->getMethod('unserialize')->isInternal()) { | ||
| 89 | $proto = null; | ||
| 90 | } else { | ||
| 91 | try { | ||
| 92 | $proto = @unserialize($proto.\strlen($class).':"'.$class.'":0:{}'); | ||
| 93 | } catch (\Exception $e) { | ||
| 94 | if (__FILE__ !== $e->getFile()) { | ||
| 95 | throw $e; | ||
| 96 | } | ||
| 97 | throw new NotInstantiableTypeException($class, $e); | ||
| 98 | } | ||
| 99 | if (false === $proto) { | ||
| 100 | throw new NotInstantiableTypeException($class); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
| 104 | if (null !== $proto && !$proto instanceof \Throwable && !$proto instanceof \Serializable && !method_exists($class, '__sleep') && !method_exists($class, '__serialize')) { | ||
| 105 | try { | ||
| 106 | serialize($proto); | ||
| 107 | } catch (\Exception $e) { | ||
| 108 | throw new NotInstantiableTypeException($class, $e); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | if (null === $cloneable) { | ||
| 114 | if (($proto instanceof \Reflector || $proto instanceof \ReflectionGenerator || $proto instanceof \ReflectionType || $proto instanceof \IteratorIterator || $proto instanceof \RecursiveIteratorIterator) && (!$proto instanceof \Serializable && !method_exists($proto, '__wakeup') && !method_exists($class, '__unserialize'))) { | ||
| 115 | throw new NotInstantiableTypeException($class); | ||
| 116 | } | ||
| 117 | |||
| 118 | $cloneable = $reflector->isCloneable() && !$reflector->hasMethod('__clone'); | ||
| 119 | } | ||
| 120 | |||
| 121 | self::$cloneable[$class] = $cloneable; | ||
| 122 | self::$instantiableWithoutConstructor[$class] = $instantiableWithoutConstructor; | ||
| 123 | self::$prototypes[$class] = $proto; | ||
| 124 | |||
| 125 | if ($proto instanceof \Throwable) { | ||
| 126 | static $setTrace; | ||
| 127 | |||
| 128 | if (null === $setTrace) { | ||
| 129 | $setTrace = [ | ||
| 130 | new \ReflectionProperty(\Error::class, 'trace'), | ||
| 131 | new \ReflectionProperty(\Exception::class, 'trace'), | ||
| 132 | ]; | ||
| 133 | $setTrace[0] = $setTrace[0]->setValue(...); | ||
| 134 | $setTrace[1] = $setTrace[1]->setValue(...); | ||
| 135 | } | ||
| 136 | |||
| 137 | $setTrace[$proto instanceof \Exception]($proto, []); | ||
| 138 | } | ||
| 139 | |||
| 140 | return $reflector; | ||
| 141 | } | ||
| 142 | } | ||
