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 | |
| 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')
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/Exporter.php | 418 | ||||
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/Hydrator.php | 299 | ||||
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/LazyObjectRegistry.php | 138 | ||||
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/LazyObjectState.php | 97 | ||||
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/LazyObjectTrait.php | 34 | ||||
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/Reference.php | 28 | ||||
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/Registry.php | 142 | ||||
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/Values.php | 25 |
8 files changed, 1181 insertions, 0 deletions
diff --git a/vendor/symfony/var-exporter/Internal/Exporter.php b/vendor/symfony/var-exporter/Internal/Exporter.php new file mode 100644 index 0000000..9f4f593 --- /dev/null +++ b/vendor/symfony/var-exporter/Internal/Exporter.php | |||
| @@ -0,0 +1,418 @@ | |||
| 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\NotInstantiableTypeException; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * @author Nicolas Grekas <p@tchwork.com> | ||
| 18 | * | ||
| 19 | * @internal | ||
| 20 | */ | ||
| 21 | class Exporter | ||
| 22 | { | ||
| 23 | /** | ||
| 24 | * Prepares an array of values for VarExporter. | ||
| 25 | * | ||
| 26 | * For performance this method is public and has no type-hints. | ||
| 27 | * | ||
| 28 | * @param array &$values | ||
| 29 | * @param \SplObjectStorage $objectsPool | ||
| 30 | * @param array &$refsPool | ||
| 31 | * @param int &$objectsCount | ||
| 32 | * @param bool &$valuesAreStatic | ||
| 33 | * | ||
| 34 | * @return array | ||
| 35 | * | ||
| 36 | * @throws NotInstantiableTypeException When a value cannot be serialized | ||
| 37 | */ | ||
| 38 | public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount, &$valuesAreStatic) | ||
| 39 | { | ||
| 40 | $refs = $values; | ||
| 41 | foreach ($values as $k => $value) { | ||
| 42 | if (\is_resource($value)) { | ||
| 43 | throw new NotInstantiableTypeException(get_resource_type($value).' resource'); | ||
| 44 | } | ||
| 45 | $refs[$k] = $objectsPool; | ||
| 46 | |||
| 47 | if ($isRef = !$valueIsStatic = $values[$k] !== $objectsPool) { | ||
| 48 | $values[$k] = &$value; // Break hard references to make $values completely | ||
| 49 | unset($value); // independent from the original structure | ||
| 50 | $refs[$k] = $value = $values[$k]; | ||
| 51 | if ($value instanceof Reference && 0 > $value->id) { | ||
| 52 | $valuesAreStatic = false; | ||
| 53 | ++$value->count; | ||
| 54 | continue; | ||
| 55 | } | ||
| 56 | $refsPool[] = [&$refs[$k], $value, &$value]; | ||
| 57 | $refs[$k] = $values[$k] = new Reference(-\count($refsPool), $value); | ||
| 58 | } | ||
| 59 | |||
| 60 | if (\is_array($value)) { | ||
| 61 | if ($value) { | ||
| 62 | $value = self::prepare($value, $objectsPool, $refsPool, $objectsCount, $valueIsStatic); | ||
| 63 | } | ||
| 64 | goto handle_value; | ||
| 65 | } elseif (!\is_object($value) || $value instanceof \UnitEnum) { | ||
| 66 | goto handle_value; | ||
| 67 | } | ||
| 68 | |||
| 69 | $valueIsStatic = false; | ||
| 70 | if (isset($objectsPool[$value])) { | ||
| 71 | ++$objectsCount; | ||
| 72 | $value = new Reference($objectsPool[$value][0]); | ||
| 73 | goto handle_value; | ||
| 74 | } | ||
| 75 | |||
| 76 | $class = $value::class; | ||
| 77 | $reflector = Registry::$reflectors[$class] ??= Registry::getClassReflector($class); | ||
| 78 | $properties = []; | ||
| 79 | |||
| 80 | if ($reflector->hasMethod('__serialize')) { | ||
| 81 | if (!$reflector->getMethod('__serialize')->isPublic()) { | ||
| 82 | throw new \Error(sprintf('Call to %s method "%s::__serialize()".', $reflector->getMethod('__serialize')->isProtected() ? 'protected' : 'private', $class)); | ||
| 83 | } | ||
| 84 | |||
| 85 | if (!\is_array($serializeProperties = $value->__serialize())) { | ||
| 86 | throw new \TypeError($class.'::__serialize() must return an array'); | ||
| 87 | } | ||
| 88 | |||
| 89 | if ($reflector->hasMethod('__unserialize')) { | ||
| 90 | $properties = $serializeProperties; | ||
| 91 | } else { | ||
| 92 | foreach ($serializeProperties as $n => $v) { | ||
| 93 | $c = $reflector->hasProperty($n) && ($p = $reflector->getProperty($n))->isReadOnly() ? $p->class : 'stdClass'; | ||
| 94 | $properties[$c][$n] = $v; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | goto prepare_value; | ||
| 99 | } | ||
| 100 | |||
| 101 | $sleep = null; | ||
| 102 | $proto = Registry::$prototypes[$class]; | ||
| 103 | |||
| 104 | if (($value instanceof \ArrayIterator || $value instanceof \ArrayObject) && null !== $proto) { | ||
| 105 | // ArrayIterator and ArrayObject need special care because their "flags" | ||
| 106 | // option changes the behavior of the (array) casting operator. | ||
| 107 | [$arrayValue, $properties] = self::getArrayObjectProperties($value, $proto); | ||
| 108 | |||
| 109 | // populates Registry::$prototypes[$class] with a new instance | ||
| 110 | Registry::getClassReflector($class, Registry::$instantiableWithoutConstructor[$class], Registry::$cloneable[$class]); | ||
| 111 | } elseif ($value instanceof \SplObjectStorage && Registry::$cloneable[$class] && null !== $proto) { | ||
| 112 | // By implementing Serializable, SplObjectStorage breaks | ||
| 113 | // internal references; let's deal with it on our own. | ||
| 114 | foreach (clone $value as $v) { | ||
| 115 | $properties[] = $v; | ||
| 116 | $properties[] = $value[$v]; | ||
| 117 | } | ||
| 118 | $properties = ['SplObjectStorage' => ["\0" => $properties]]; | ||
| 119 | $arrayValue = (array) $value; | ||
| 120 | } elseif ($value instanceof \Serializable | ||
| 121 | || $value instanceof \__PHP_Incomplete_Class | ||
| 122 | ) { | ||
| 123 | ++$objectsCount; | ||
| 124 | $objectsPool[$value] = [$id = \count($objectsPool), serialize($value), [], 0]; | ||
| 125 | $value = new Reference($id); | ||
| 126 | goto handle_value; | ||
| 127 | } else { | ||
| 128 | if (method_exists($class, '__sleep')) { | ||
| 129 | if (!\is_array($sleep = $value->__sleep())) { | ||
| 130 | trigger_error('serialize(): __sleep should return an array only containing the names of instance-variables to serialize', \E_USER_NOTICE); | ||
| 131 | $value = null; | ||
| 132 | goto handle_value; | ||
| 133 | } | ||
| 134 | $sleep = array_flip($sleep); | ||
| 135 | } | ||
| 136 | |||
| 137 | $arrayValue = (array) $value; | ||
| 138 | } | ||
| 139 | |||
| 140 | $proto = (array) $proto; | ||
| 141 | |||
| 142 | foreach ($arrayValue as $name => $v) { | ||
| 143 | $i = 0; | ||
| 144 | $n = (string) $name; | ||
| 145 | if ('' === $n || "\0" !== $n[0]) { | ||
| 146 | $c = $reflector->hasProperty($n) && ($p = $reflector->getProperty($n))->isReadOnly() ? $p->class : 'stdClass'; | ||
| 147 | } elseif ('*' === $n[1]) { | ||
| 148 | $n = substr($n, 3); | ||
| 149 | $c = $reflector->getProperty($n)->class; | ||
| 150 | if ('Error' === $c) { | ||
| 151 | $c = 'TypeError'; | ||
| 152 | } elseif ('Exception' === $c) { | ||
| 153 | $c = 'ErrorException'; | ||
| 154 | } | ||
| 155 | } else { | ||
| 156 | $i = strpos($n, "\0", 2); | ||
| 157 | $c = substr($n, 1, $i - 1); | ||
| 158 | $n = substr($n, 1 + $i); | ||
| 159 | } | ||
| 160 | if (null !== $sleep) { | ||
| 161 | if (!isset($sleep[$name]) && (!isset($sleep[$n]) || ($i && $c !== $class))) { | ||
| 162 | unset($arrayValue[$name]); | ||
| 163 | continue; | ||
| 164 | } | ||
| 165 | unset($sleep[$name], $sleep[$n]); | ||
| 166 | } | ||
| 167 | if (!\array_key_exists($name, $proto) || $proto[$name] !== $v || "\x00Error\x00trace" === $name || "\x00Exception\x00trace" === $name) { | ||
| 168 | $properties[$c][$n] = $v; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | if ($sleep) { | ||
| 172 | foreach ($sleep as $n => $v) { | ||
| 173 | trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE); | ||
| 174 | } | ||
| 175 | } | ||
| 176 | if (method_exists($class, '__unserialize')) { | ||
| 177 | $properties = $arrayValue; | ||
| 178 | } | ||
| 179 | |||
| 180 | prepare_value: | ||
| 181 | $objectsPool[$value] = [$id = \count($objectsPool)]; | ||
| 182 | $properties = self::prepare($properties, $objectsPool, $refsPool, $objectsCount, $valueIsStatic); | ||
| 183 | ++$objectsCount; | ||
| 184 | $objectsPool[$value] = [$id, $class, $properties, method_exists($class, '__unserialize') ? -$objectsCount : (method_exists($class, '__wakeup') ? $objectsCount : 0)]; | ||
| 185 | |||
| 186 | $value = new Reference($id); | ||
| 187 | |||
| 188 | handle_value: | ||
| 189 | if ($isRef) { | ||
| 190 | unset($value); // Break the hard reference created above | ||
| 191 | } elseif (!$valueIsStatic) { | ||
| 192 | $values[$k] = $value; | ||
| 193 | } | ||
| 194 | $valuesAreStatic = $valueIsStatic && $valuesAreStatic; | ||
| 195 | } | ||
| 196 | |||
| 197 | return $values; | ||
| 198 | } | ||
| 199 | |||
| 200 | public static function export($value, $indent = '') | ||
| 201 | { | ||
| 202 | switch (true) { | ||
| 203 | case \is_int($value) || \is_float($value): return var_export($value, true); | ||
| 204 | case [] === $value: return '[]'; | ||
| 205 | case false === $value: return 'false'; | ||
| 206 | case true === $value: return 'true'; | ||
| 207 | case null === $value: return 'null'; | ||
| 208 | case '' === $value: return "''"; | ||
| 209 | case $value instanceof \UnitEnum: return '\\'.ltrim(var_export($value, true), '\\'); | ||
| 210 | } | ||
| 211 | |||
| 212 | if ($value instanceof Reference) { | ||
| 213 | if (0 <= $value->id) { | ||
| 214 | return '$o['.$value->id.']'; | ||
| 215 | } | ||
| 216 | if (!$value->count) { | ||
| 217 | return self::export($value->value, $indent); | ||
| 218 | } | ||
| 219 | $value = -$value->id; | ||
| 220 | |||
| 221 | return '&$r['.$value.']'; | ||
| 222 | } | ||
| 223 | $subIndent = $indent.' '; | ||
| 224 | |||
| 225 | if (\is_string($value)) { | ||
| 226 | $code = sprintf("'%s'", addcslashes($value, "'\\")); | ||
| 227 | |||
| 228 | $code = preg_replace_callback("/((?:[\\0\\r\\n]|\u{202A}|\u{202B}|\u{202D}|\u{202E}|\u{2066}|\u{2067}|\u{2068}|\u{202C}|\u{2069})++)(.)/", function ($m) use ($subIndent) { | ||
| 229 | $m[1] = sprintf('\'."%s".\'', str_replace( | ||
| 230 | ["\0", "\r", "\n", "\u{202A}", "\u{202B}", "\u{202D}", "\u{202E}", "\u{2066}", "\u{2067}", "\u{2068}", "\u{202C}", "\u{2069}", '\n\\'], | ||
| 231 | ['\0', '\r', '\n', '\u{202A}', '\u{202B}', '\u{202D}', '\u{202E}', '\u{2066}', '\u{2067}', '\u{2068}', '\u{202C}', '\u{2069}', '\n"'."\n".$subIndent.'."\\'], | ||
| 232 | $m[1] | ||
| 233 | )); | ||
| 234 | |||
| 235 | if ("'" === $m[2]) { | ||
| 236 | return substr($m[1], 0, -2); | ||
| 237 | } | ||
| 238 | |||
| 239 | if (str_ends_with($m[1], 'n".\'')) { | ||
| 240 | return substr_replace($m[1], "\n".$subIndent.".'".$m[2], -2); | ||
| 241 | } | ||
| 242 | |||
| 243 | return $m[1].$m[2]; | ||
| 244 | }, $code, -1, $count); | ||
| 245 | |||
| 246 | if ($count && str_starts_with($code, "''.")) { | ||
| 247 | $code = substr($code, 3); | ||
| 248 | } | ||
| 249 | |||
| 250 | return $code; | ||
| 251 | } | ||
| 252 | |||
| 253 | if (\is_array($value)) { | ||
| 254 | $j = -1; | ||
| 255 | $code = ''; | ||
| 256 | foreach ($value as $k => $v) { | ||
| 257 | $code .= $subIndent; | ||
| 258 | if (!\is_int($k) || 1 !== $k - $j) { | ||
| 259 | $code .= self::export($k, $subIndent).' => '; | ||
| 260 | } | ||
| 261 | if (\is_int($k) && $k > $j) { | ||
| 262 | $j = $k; | ||
| 263 | } | ||
| 264 | $code .= self::export($v, $subIndent).",\n"; | ||
| 265 | } | ||
| 266 | |||
| 267 | return "[\n".$code.$indent.']'; | ||
| 268 | } | ||
| 269 | |||
| 270 | if ($value instanceof Values) { | ||
| 271 | $code = $subIndent."\$r = [],\n"; | ||
| 272 | foreach ($value->values as $k => $v) { | ||
| 273 | $code .= $subIndent.'$r['.$k.'] = '.self::export($v, $subIndent).",\n"; | ||
| 274 | } | ||
| 275 | |||
| 276 | return "[\n".$code.$indent.']'; | ||
| 277 | } | ||
| 278 | |||
| 279 | if ($value instanceof Registry) { | ||
| 280 | return self::exportRegistry($value, $indent, $subIndent); | ||
| 281 | } | ||
| 282 | |||
| 283 | if ($value instanceof Hydrator) { | ||
| 284 | return self::exportHydrator($value, $indent, $subIndent); | ||
| 285 | } | ||
| 286 | |||
| 287 | throw new \UnexpectedValueException(sprintf('Cannot export value of type "%s".', get_debug_type($value))); | ||
| 288 | } | ||
| 289 | |||
| 290 | private static function exportRegistry(Registry $value, string $indent, string $subIndent): string | ||
| 291 | { | ||
| 292 | $code = ''; | ||
| 293 | $serializables = []; | ||
| 294 | $seen = []; | ||
| 295 | $prototypesAccess = 0; | ||
| 296 | $factoriesAccess = 0; | ||
| 297 | $r = '\\'.Registry::class; | ||
| 298 | $j = -1; | ||
| 299 | |||
| 300 | foreach ($value->classes as $k => $class) { | ||
| 301 | if (':' === ($class[1] ?? null)) { | ||
| 302 | $serializables[$k] = $class; | ||
| 303 | continue; | ||
| 304 | } | ||
| 305 | if (!Registry::$instantiableWithoutConstructor[$class]) { | ||
| 306 | if (is_subclass_of($class, 'Serializable') && !method_exists($class, '__unserialize')) { | ||
| 307 | $serializables[$k] = 'C:'.\strlen($class).':"'.$class.'":0:{}'; | ||
| 308 | } else { | ||
| 309 | $serializables[$k] = 'O:'.\strlen($class).':"'.$class.'":0:{}'; | ||
| 310 | } | ||
| 311 | if (is_subclass_of($class, 'Throwable')) { | ||
| 312 | $eol = is_subclass_of($class, 'Error') ? "\0Error\0" : "\0Exception\0"; | ||
| 313 | $serializables[$k] = substr_replace($serializables[$k], '1:{s:'.(5 + \strlen($eol)).':"'.$eol.'trace";a:0:{}}', -4); | ||
| 314 | } | ||
| 315 | continue; | ||
| 316 | } | ||
| 317 | $code .= $subIndent.(1 !== $k - $j ? $k.' => ' : ''); | ||
| 318 | $j = $k; | ||
| 319 | $eol = ",\n"; | ||
| 320 | $c = '['.self::export($class).']'; | ||
| 321 | |||
| 322 | if ($seen[$class] ?? false) { | ||
| 323 | if (Registry::$cloneable[$class]) { | ||
| 324 | ++$prototypesAccess; | ||
| 325 | $code .= 'clone $p'.$c; | ||
| 326 | } else { | ||
| 327 | ++$factoriesAccess; | ||
| 328 | $code .= '$f'.$c.'()'; | ||
| 329 | } | ||
| 330 | } else { | ||
| 331 | $seen[$class] = true; | ||
| 332 | if (Registry::$cloneable[$class]) { | ||
| 333 | $code .= 'clone ('.($prototypesAccess++ ? '$p' : '($p = &'.$r.'::$prototypes)').$c.' ?? '.$r.'::p'; | ||
| 334 | } else { | ||
| 335 | $code .= '('.($factoriesAccess++ ? '$f' : '($f = &'.$r.'::$factories)').$c.' ?? '.$r.'::f'; | ||
| 336 | $eol = '()'.$eol; | ||
| 337 | } | ||
| 338 | $code .= '('.substr($c, 1, -1).'))'; | ||
| 339 | } | ||
| 340 | $code .= $eol; | ||
| 341 | } | ||
| 342 | |||
| 343 | if (1 === $prototypesAccess) { | ||
| 344 | $code = str_replace('($p = &'.$r.'::$prototypes)', $r.'::$prototypes', $code); | ||
| 345 | } | ||
| 346 | if (1 === $factoriesAccess) { | ||
| 347 | $code = str_replace('($f = &'.$r.'::$factories)', $r.'::$factories', $code); | ||
| 348 | } | ||
| 349 | if ('' !== $code) { | ||
| 350 | $code = "\n".$code.$indent; | ||
| 351 | } | ||
| 352 | |||
| 353 | if ($serializables) { | ||
| 354 | $code = $r.'::unserialize(['.$code.'], '.self::export($serializables, $indent).')'; | ||
| 355 | } else { | ||
| 356 | $code = '['.$code.']'; | ||
| 357 | } | ||
| 358 | |||
| 359 | return '$o = '.$code; | ||
| 360 | } | ||
| 361 | |||
| 362 | private static function exportHydrator(Hydrator $value, string $indent, string $subIndent): string | ||
| 363 | { | ||
| 364 | $code = ''; | ||
| 365 | foreach ($value->properties as $class => $properties) { | ||
| 366 | $code .= $subIndent.' '.self::export($class).' => '.self::export($properties, $subIndent.' ').",\n"; | ||
| 367 | } | ||
| 368 | |||
| 369 | $code = [ | ||
| 370 | self::export($value->registry, $subIndent), | ||
| 371 | self::export($value->values, $subIndent), | ||
| 372 | '' !== $code ? "[\n".$code.$subIndent.']' : '[]', | ||
| 373 | self::export($value->value, $subIndent), | ||
| 374 | self::export($value->wakeups, $subIndent), | ||
| 375 | ]; | ||
| 376 | |||
| 377 | return '\\'.$value::class."::hydrate(\n".$subIndent.implode(",\n".$subIndent, $code)."\n".$indent.')'; | ||
| 378 | } | ||
| 379 | |||
| 380 | /** | ||
| 381 | * @param \ArrayIterator|\ArrayObject $value | ||
| 382 | * @param \ArrayIterator|\ArrayObject $proto | ||
| 383 | */ | ||
| 384 | private static function getArrayObjectProperties($value, $proto): array | ||
| 385 | { | ||
| 386 | $reflector = $value instanceof \ArrayIterator ? 'ArrayIterator' : 'ArrayObject'; | ||
| 387 | $reflector = Registry::$reflectors[$reflector] ??= Registry::getClassReflector($reflector); | ||
| 388 | |||
| 389 | $properties = [ | ||
| 390 | $arrayValue = (array) $value, | ||
| 391 | $reflector->getMethod('getFlags')->invoke($value), | ||
| 392 | $value instanceof \ArrayObject ? $reflector->getMethod('getIteratorClass')->invoke($value) : 'ArrayIterator', | ||
| 393 | ]; | ||
| 394 | |||
| 395 | $reflector = $reflector->getMethod('setFlags'); | ||
| 396 | $reflector->invoke($proto, \ArrayObject::STD_PROP_LIST); | ||
| 397 | |||
| 398 | if ($properties[1] & \ArrayObject::STD_PROP_LIST) { | ||
| 399 | $reflector->invoke($value, 0); | ||
| 400 | $properties[0] = (array) $value; | ||
| 401 | } else { | ||
| 402 | $reflector->invoke($value, \ArrayObject::STD_PROP_LIST); | ||
| 403 | $arrayValue = (array) $value; | ||
| 404 | } | ||
| 405 | $reflector->invoke($value, $properties[1]); | ||
| 406 | |||
| 407 | if ([[], 0, 'ArrayIterator'] === $properties) { | ||
| 408 | $properties = []; | ||
| 409 | } else { | ||
| 410 | if ('ArrayIterator' === $properties[2]) { | ||
| 411 | unset($properties[2]); | ||
| 412 | } | ||
| 413 | $properties = [$reflector->class => ["\0" => $properties]]; | ||
| 414 | } | ||
| 415 | |||
| 416 | return [$arrayValue, $properties]; | ||
| 417 | } | ||
| 418 | } | ||
diff --git a/vendor/symfony/var-exporter/Internal/Hydrator.php b/vendor/symfony/var-exporter/Internal/Hydrator.php new file mode 100644 index 0000000..65fdcd1 --- /dev/null +++ b/vendor/symfony/var-exporter/Internal/Hydrator.php | |||
| @@ -0,0 +1,299 @@ | |||
| 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 | |||
| 16 | /** | ||
| 17 | * @author Nicolas Grekas <p@tchwork.com> | ||
| 18 | * | ||
| 19 | * @internal | ||
| 20 | */ | ||
| 21 | class Hydrator | ||
| 22 | { | ||
| 23 | public static array $hydrators = []; | ||
| 24 | public static array $simpleHydrators = []; | ||
| 25 | public static array $propertyScopes = []; | ||
| 26 | |||
| 27 | public function __construct( | ||
| 28 | public readonly Registry $registry, | ||
| 29 | public readonly ?Values $values, | ||
| 30 | public readonly array $properties, | ||
| 31 | public readonly mixed $value, | ||
| 32 | public readonly array $wakeups, | ||
| 33 | ) { | ||
| 34 | } | ||
| 35 | |||
| 36 | public static function hydrate($objects, $values, $properties, $value, $wakeups) | ||
| 37 | { | ||
| 38 | foreach ($properties as $class => $vars) { | ||
| 39 | (self::$hydrators[$class] ??= self::getHydrator($class))($vars, $objects); | ||
| 40 | } | ||
| 41 | foreach ($wakeups as $k => $v) { | ||
| 42 | if (\is_array($v)) { | ||
| 43 | $objects[-$k]->__unserialize($v); | ||
| 44 | } else { | ||
| 45 | $objects[$v]->__wakeup(); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | return $value; | ||
| 50 | } | ||
| 51 | |||
| 52 | public static function getHydrator($class) | ||
| 53 | { | ||
| 54 | $baseHydrator = self::$hydrators['stdClass'] ??= static function ($properties, $objects) { | ||
| 55 | foreach ($properties as $name => $values) { | ||
| 56 | foreach ($values as $i => $v) { | ||
| 57 | $objects[$i]->$name = $v; | ||
| 58 | } | ||
| 59 | } | ||
| 60 | }; | ||
| 61 | |||
| 62 | switch ($class) { | ||
| 63 | case 'stdClass': | ||
| 64 | return $baseHydrator; | ||
| 65 | |||
| 66 | case 'ErrorException': | ||
| 67 | return $baseHydrator->bindTo(null, new class() extends \ErrorException { | ||
| 68 | }); | ||
| 69 | |||
| 70 | case 'TypeError': | ||
| 71 | return $baseHydrator->bindTo(null, new class() extends \Error { | ||
| 72 | }); | ||
| 73 | |||
| 74 | case 'SplObjectStorage': | ||
| 75 | return static function ($properties, $objects) { | ||
| 76 | foreach ($properties as $name => $values) { | ||
| 77 | if ("\0" === $name) { | ||
| 78 | foreach ($values as $i => $v) { | ||
| 79 | for ($j = 0; $j < \count($v); ++$j) { | ||
| 80 | $objects[$i]->attach($v[$j], $v[++$j]); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | continue; | ||
| 84 | } | ||
| 85 | foreach ($values as $i => $v) { | ||
| 86 | $objects[$i]->$name = $v; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | }; | ||
| 90 | } | ||
| 91 | |||
| 92 | if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) { | ||
| 93 | throw new ClassNotFoundException($class); | ||
| 94 | } | ||
| 95 | $classReflector = new \ReflectionClass($class); | ||
| 96 | |||
| 97 | switch ($class) { | ||
| 98 | case 'ArrayIterator': | ||
| 99 | case 'ArrayObject': | ||
| 100 | $constructor = $classReflector->getConstructor()->invokeArgs(...); | ||
| 101 | |||
| 102 | return static function ($properties, $objects) use ($constructor) { | ||
| 103 | foreach ($properties as $name => $values) { | ||
| 104 | if ("\0" !== $name) { | ||
| 105 | foreach ($values as $i => $v) { | ||
| 106 | $objects[$i]->$name = $v; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | } | ||
| 110 | foreach ($properties["\0"] ?? [] as $i => $v) { | ||
| 111 | $constructor($objects[$i], $v); | ||
| 112 | } | ||
| 113 | }; | ||
| 114 | } | ||
| 115 | |||
| 116 | if (!$classReflector->isInternal()) { | ||
| 117 | return $baseHydrator->bindTo(null, $class); | ||
| 118 | } | ||
| 119 | |||
| 120 | if ($classReflector->name !== $class) { | ||
| 121 | return self::$hydrators[$classReflector->name] ??= self::getHydrator($classReflector->name); | ||
| 122 | } | ||
| 123 | |||
| 124 | $propertySetters = []; | ||
| 125 | foreach ($classReflector->getProperties() as $propertyReflector) { | ||
| 126 | if (!$propertyReflector->isStatic()) { | ||
| 127 | $propertySetters[$propertyReflector->name] = $propertyReflector->setValue(...); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | if (!$propertySetters) { | ||
| 132 | return $baseHydrator; | ||
| 133 | } | ||
| 134 | |||
| 135 | return static function ($properties, $objects) use ($propertySetters) { | ||
| 136 | foreach ($properties as $name => $values) { | ||
| 137 | if ($setValue = $propertySetters[$name] ?? null) { | ||
| 138 | foreach ($values as $i => $v) { | ||
| 139 | $setValue($objects[$i], $v); | ||
| 140 | } | ||
| 141 | continue; | ||
| 142 | } | ||
| 143 | foreach ($values as $i => $v) { | ||
| 144 | $objects[$i]->$name = $v; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | public static function getSimpleHydrator($class) | ||
| 151 | { | ||
| 152 | $baseHydrator = self::$simpleHydrators['stdClass'] ??= (function ($properties, $object) { | ||
| 153 | $readonly = (array) $this; | ||
| 154 | |||
| 155 | foreach ($properties as $name => &$value) { | ||
| 156 | $object->$name = $value; | ||
| 157 | |||
| 158 | if (!($readonly[$name] ?? false)) { | ||
| 159 | $object->$name = &$value; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | })->bindTo(new \stdClass()); | ||
| 163 | |||
| 164 | switch ($class) { | ||
| 165 | case 'stdClass': | ||
| 166 | return $baseHydrator; | ||
| 167 | |||
| 168 | case 'ErrorException': | ||
| 169 | return $baseHydrator->bindTo(new \stdClass(), new class() extends \ErrorException { | ||
| 170 | }); | ||
| 171 | |||
| 172 | case 'TypeError': | ||
| 173 | return $baseHydrator->bindTo(new \stdClass(), new class() extends \Error { | ||
| 174 | }); | ||
| 175 | |||
| 176 | case 'SplObjectStorage': | ||
| 177 | return static function ($properties, $object) { | ||
| 178 | foreach ($properties as $name => &$value) { | ||
| 179 | if ("\0" !== $name) { | ||
| 180 | $object->$name = $value; | ||
| 181 | $object->$name = &$value; | ||
| 182 | continue; | ||
| 183 | } | ||
| 184 | for ($i = 0; $i < \count($value); ++$i) { | ||
| 185 | $object->attach($value[$i], $value[++$i]); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | }; | ||
| 189 | } | ||
| 190 | |||
| 191 | if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) { | ||
| 192 | throw new ClassNotFoundException($class); | ||
| 193 | } | ||
| 194 | $classReflector = new \ReflectionClass($class); | ||
| 195 | |||
| 196 | switch ($class) { | ||
| 197 | case 'ArrayIterator': | ||
| 198 | case 'ArrayObject': | ||
| 199 | $constructor = $classReflector->getConstructor()->invokeArgs(...); | ||
| 200 | |||
| 201 | return static function ($properties, $object) use ($constructor) { | ||
| 202 | foreach ($properties as $name => &$value) { | ||
| 203 | if ("\0" === $name) { | ||
| 204 | $constructor($object, $value); | ||
| 205 | } else { | ||
| 206 | $object->$name = $value; | ||
| 207 | $object->$name = &$value; | ||
| 208 | } | ||
| 209 | } | ||
| 210 | }; | ||
| 211 | } | ||
| 212 | |||
| 213 | if (!$classReflector->isInternal()) { | ||
| 214 | $readonly = new \stdClass(); | ||
| 215 | foreach ($classReflector->getProperties(\ReflectionProperty::IS_READONLY) as $propertyReflector) { | ||
| 216 | if ($class === $propertyReflector->class) { | ||
| 217 | $readonly->{$propertyReflector->name} = true; | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | return $baseHydrator->bindTo($readonly, $class); | ||
| 222 | } | ||
| 223 | |||
| 224 | if ($classReflector->name !== $class) { | ||
| 225 | return self::$simpleHydrators[$classReflector->name] ??= self::getSimpleHydrator($classReflector->name); | ||
| 226 | } | ||
| 227 | |||
| 228 | $propertySetters = []; | ||
| 229 | foreach ($classReflector->getProperties() as $propertyReflector) { | ||
| 230 | if (!$propertyReflector->isStatic()) { | ||
| 231 | $propertySetters[$propertyReflector->name] = $propertyReflector->setValue(...); | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | if (!$propertySetters) { | ||
| 236 | return $baseHydrator; | ||
| 237 | } | ||
| 238 | |||
| 239 | return static function ($properties, $object) use ($propertySetters) { | ||
| 240 | foreach ($properties as $name => &$value) { | ||
| 241 | if ($setValue = $propertySetters[$name] ?? null) { | ||
| 242 | $setValue($object, $value); | ||
| 243 | } else { | ||
| 244 | $object->$name = $value; | ||
| 245 | $object->$name = &$value; | ||
| 246 | } | ||
| 247 | } | ||
| 248 | }; | ||
| 249 | } | ||
| 250 | |||
| 251 | public static function getPropertyScopes($class): array | ||
| 252 | { | ||
| 253 | $propertyScopes = []; | ||
| 254 | $r = new \ReflectionClass($class); | ||
| 255 | |||
| 256 | foreach ($r->getProperties() as $property) { | ||
| 257 | $flags = $property->getModifiers(); | ||
| 258 | |||
| 259 | if (\ReflectionProperty::IS_STATIC & $flags) { | ||
| 260 | continue; | ||
| 261 | } | ||
| 262 | $name = $property->name; | ||
| 263 | |||
| 264 | if (\ReflectionProperty::IS_PRIVATE & $flags) { | ||
| 265 | $readonlyScope = null; | ||
| 266 | if ($flags & \ReflectionProperty::IS_READONLY) { | ||
| 267 | $readonlyScope = $class; | ||
| 268 | } | ||
| 269 | $propertyScopes["\0$class\0$name"] = $propertyScopes[$name] = [$class, $name, $readonlyScope, $property]; | ||
| 270 | |||
| 271 | continue; | ||
| 272 | } | ||
| 273 | $readonlyScope = null; | ||
| 274 | if ($flags & \ReflectionProperty::IS_READONLY) { | ||
| 275 | $readonlyScope = $property->class; | ||
| 276 | } | ||
| 277 | $propertyScopes[$name] = [$class, $name, $readonlyScope, $property]; | ||
| 278 | |||
| 279 | if (\ReflectionProperty::IS_PROTECTED & $flags) { | ||
| 280 | $propertyScopes["\0*\0$name"] = $propertyScopes[$name]; | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | while ($r = $r->getParentClass()) { | ||
| 285 | $class = $r->name; | ||
| 286 | |||
| 287 | foreach ($r->getProperties(\ReflectionProperty::IS_PRIVATE) as $property) { | ||
| 288 | if (!$property->isStatic()) { | ||
| 289 | $name = $property->name; | ||
| 290 | $readonlyScope = $property->isReadOnly() ? $class : null; | ||
| 291 | $propertyScopes["\0$class\0$name"] = [$class, $name, $readonlyScope, $property]; | ||
| 292 | $propertyScopes[$name] ??= [$class, $name, $readonlyScope, $property]; | ||
| 293 | } | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | return $propertyScopes; | ||
| 298 | } | ||
| 299 | } | ||
diff --git a/vendor/symfony/var-exporter/Internal/LazyObjectRegistry.php b/vendor/symfony/var-exporter/Internal/LazyObjectRegistry.php new file mode 100644 index 0000000..f6450ce --- /dev/null +++ b/vendor/symfony/var-exporter/Internal/LazyObjectRegistry.php | |||
| @@ -0,0 +1,138 @@ | |||
| 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 | /** | ||
| 15 | * Stores the state of lazy objects and caches related reflection information. | ||
| 16 | * | ||
| 17 | * As a micro-optimization, this class uses no type declarations. | ||
| 18 | * | ||
| 19 | * @internal | ||
| 20 | */ | ||
| 21 | class LazyObjectRegistry | ||
| 22 | { | ||
| 23 | /** | ||
| 24 | * @var array<class-string, \ReflectionClass> | ||
| 25 | */ | ||
| 26 | public static array $classReflectors = []; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * @var array<class-string, array<string, mixed>> | ||
| 30 | */ | ||
| 31 | public static array $defaultProperties = []; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * @var array<class-string, list<\Closure>> | ||
| 35 | */ | ||
| 36 | public static array $classResetters = []; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * @var array<class-string, array{get: \Closure, set: \Closure, isset: \Closure, unset: \Closure}> | ||
| 40 | */ | ||
| 41 | public static array $classAccessors = []; | ||
| 42 | |||
| 43 | /** | ||
| 44 | * @var array<class-string, array{set: bool, isset: bool, unset: bool, clone: bool, serialize: bool, unserialize: bool, sleep: bool, wakeup: bool, destruct: bool, get: int}> | ||
| 45 | */ | ||
| 46 | public static array $parentMethods = []; | ||
| 47 | |||
| 48 | public static ?\Closure $noInitializerState = null; | ||
| 49 | |||
| 50 | public static function getClassResetters($class) | ||
| 51 | { | ||
| 52 | $classProperties = []; | ||
| 53 | |||
| 54 | if ((self::$classReflectors[$class] ??= new \ReflectionClass($class))->isInternal()) { | ||
| 55 | $propertyScopes = []; | ||
| 56 | } else { | ||
| 57 | $propertyScopes = Hydrator::$propertyScopes[$class] ??= Hydrator::getPropertyScopes($class); | ||
| 58 | } | ||
| 59 | |||
| 60 | foreach ($propertyScopes as $key => [$scope, $name, $readonlyScope]) { | ||
| 61 | $propertyScopes[$k = "\0$scope\0$name"] ?? $propertyScopes[$k = "\0*\0$name"] ?? $k = $name; | ||
| 62 | |||
| 63 | if ($k === $key && "\0$class\0lazyObjectState" !== $k) { | ||
| 64 | $classProperties[$readonlyScope ?? $scope][$name] = $key; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | $resetters = []; | ||
| 69 | foreach ($classProperties as $scope => $properties) { | ||
| 70 | $resetters[] = \Closure::bind(static function ($instance, $skippedProperties) use ($properties) { | ||
| 71 | foreach ($properties as $name => $key) { | ||
| 72 | if (!\array_key_exists($key, $skippedProperties)) { | ||
| 73 | unset($instance->$name); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | }, null, $scope); | ||
| 77 | } | ||
| 78 | |||
| 79 | return $resetters; | ||
| 80 | } | ||
| 81 | |||
| 82 | public static function getClassAccessors($class) | ||
| 83 | { | ||
| 84 | return \Closure::bind(static fn () => [ | ||
| 85 | 'get' => static function &($instance, $name, $readonly) { | ||
| 86 | if (!$readonly) { | ||
| 87 | return $instance->$name; | ||
| 88 | } | ||
| 89 | $value = $instance->$name; | ||
| 90 | |||
| 91 | return $value; | ||
| 92 | }, | ||
| 93 | 'set' => static function ($instance, $name, $value) { | ||
| 94 | $instance->$name = $value; | ||
| 95 | }, | ||
| 96 | 'isset' => static fn ($instance, $name) => isset($instance->$name), | ||
| 97 | 'unset' => static function ($instance, $name) { | ||
| 98 | unset($instance->$name); | ||
| 99 | }, | ||
| 100 | ], null, \Closure::class === $class ? null : $class)(); | ||
| 101 | } | ||
| 102 | |||
| 103 | public static function getParentMethods($class) | ||
| 104 | { | ||
| 105 | $parent = get_parent_class($class); | ||
| 106 | $methods = []; | ||
| 107 | |||
| 108 | foreach (['set', 'isset', 'unset', 'clone', 'serialize', 'unserialize', 'sleep', 'wakeup', 'destruct', 'get'] as $method) { | ||
| 109 | if (!$parent || !method_exists($parent, '__'.$method)) { | ||
| 110 | $methods[$method] = false; | ||
| 111 | } else { | ||
| 112 | $m = new \ReflectionMethod($parent, '__'.$method); | ||
| 113 | $methods[$method] = !$m->isAbstract() && !$m->isPrivate(); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | $methods['get'] = $methods['get'] ? ($m->returnsReference() ? 2 : 1) : 0; | ||
| 118 | |||
| 119 | return $methods; | ||
| 120 | } | ||
| 121 | |||
| 122 | public static function getScope($propertyScopes, $class, $property, $readonlyScope = null) | ||
| 123 | { | ||
| 124 | if (null === $readonlyScope && !isset($propertyScopes[$k = "\0$class\0$property"]) && !isset($propertyScopes[$k = "\0*\0$property"])) { | ||
| 125 | return null; | ||
| 126 | } | ||
| 127 | $frame = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]; | ||
| 128 | |||
| 129 | if (\ReflectionProperty::class === $scope = $frame['class'] ?? \Closure::class) { | ||
| 130 | $scope = $frame['object']->class; | ||
| 131 | } | ||
| 132 | if (null === $readonlyScope && '*' === $k[1] && ($class === $scope || (is_subclass_of($class, $scope) && !isset($propertyScopes["\0$scope\0$property"])))) { | ||
| 133 | return null; | ||
| 134 | } | ||
| 135 | |||
| 136 | return $scope; | ||
| 137 | } | ||
| 138 | } | ||
diff --git a/vendor/symfony/var-exporter/Internal/LazyObjectState.php b/vendor/symfony/var-exporter/Internal/LazyObjectState.php new file mode 100644 index 0000000..5fc398e --- /dev/null +++ b/vendor/symfony/var-exporter/Internal/LazyObjectState.php | |||
| @@ -0,0 +1,97 @@ | |||
| 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\Hydrator as PublicHydrator; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * Keeps the state of lazy objects. | ||
| 18 | * | ||
| 19 | * As a micro-optimization, this class uses no type declarations. | ||
| 20 | * | ||
| 21 | * @internal | ||
| 22 | */ | ||
| 23 | class LazyObjectState | ||
| 24 | { | ||
| 25 | public const STATUS_UNINITIALIZED_FULL = 1; | ||
| 26 | public const STATUS_UNINITIALIZED_PARTIAL = 2; | ||
| 27 | public const STATUS_INITIALIZED_FULL = 3; | ||
| 28 | public const STATUS_INITIALIZED_PARTIAL = 4; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * @var self::STATUS_* | ||
| 32 | */ | ||
| 33 | public int $status = self::STATUS_UNINITIALIZED_FULL; | ||
| 34 | |||
| 35 | public object $realInstance; | ||
| 36 | |||
| 37 | /** | ||
| 38 | * @param array<string, true> $skippedProperties | ||
| 39 | */ | ||
| 40 | public function __construct( | ||
| 41 | public readonly \Closure $initializer, | ||
| 42 | public readonly array $skippedProperties = [], | ||
| 43 | ) { | ||
| 44 | } | ||
| 45 | |||
| 46 | public function initialize($instance, $propertyName, $propertyScope) | ||
| 47 | { | ||
| 48 | if (self::STATUS_UNINITIALIZED_FULL !== $this->status) { | ||
| 49 | return $this->status; | ||
| 50 | } | ||
| 51 | |||
| 52 | $this->status = self::STATUS_INITIALIZED_PARTIAL; | ||
| 53 | |||
| 54 | try { | ||
| 55 | if ($defaultProperties = array_diff_key(LazyObjectRegistry::$defaultProperties[$instance::class], $this->skippedProperties)) { | ||
| 56 | PublicHydrator::hydrate($instance, $defaultProperties); | ||
| 57 | } | ||
| 58 | |||
| 59 | ($this->initializer)($instance); | ||
| 60 | } catch (\Throwable $e) { | ||
| 61 | $this->status = self::STATUS_UNINITIALIZED_FULL; | ||
| 62 | $this->reset($instance); | ||
| 63 | |||
| 64 | throw $e; | ||
| 65 | } | ||
| 66 | |||
| 67 | return $this->status = self::STATUS_INITIALIZED_FULL; | ||
| 68 | } | ||
| 69 | |||
| 70 | public function reset($instance): void | ||
| 71 | { | ||
| 72 | $class = $instance::class; | ||
| 73 | $propertyScopes = Hydrator::$propertyScopes[$class] ??= Hydrator::getPropertyScopes($class); | ||
| 74 | $skippedProperties = $this->skippedProperties; | ||
| 75 | $properties = (array) $instance; | ||
| 76 | |||
| 77 | foreach ($propertyScopes as $key => [$scope, $name, $readonlyScope]) { | ||
| 78 | $propertyScopes[$k = "\0$scope\0$name"] ?? $propertyScopes[$k = "\0*\0$name"] ?? $k = $name; | ||
| 79 | |||
| 80 | if ($k === $key && (null !== $readonlyScope || !\array_key_exists($k, $properties))) { | ||
| 81 | $skippedProperties[$k] = true; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | foreach (LazyObjectRegistry::$classResetters[$class] as $reset) { | ||
| 86 | $reset($instance, $skippedProperties); | ||
| 87 | } | ||
| 88 | |||
| 89 | foreach ((array) $instance as $name => $value) { | ||
| 90 | if ("\0" !== ($name[0] ?? '') && !\array_key_exists($name, $skippedProperties)) { | ||
| 91 | unset($instance->$name); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | $this->status = self::STATUS_UNINITIALIZED_FULL; | ||
| 96 | } | ||
| 97 | } | ||
diff --git a/vendor/symfony/var-exporter/Internal/LazyObjectTrait.php b/vendor/symfony/var-exporter/Internal/LazyObjectTrait.php new file mode 100644 index 0000000..4a6f232 --- /dev/null +++ b/vendor/symfony/var-exporter/Internal/LazyObjectTrait.php | |||
| @@ -0,0 +1,34 @@ | |||
| 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\Serializer\Attribute\Ignore; | ||
| 15 | |||
| 16 | if (\PHP_VERSION_ID >= 80300) { | ||
| 17 | /** | ||
| 18 | * @internal | ||
| 19 | */ | ||
| 20 | trait LazyObjectTrait | ||
| 21 | { | ||
| 22 | #[Ignore] | ||
| 23 | private readonly LazyObjectState $lazyObjectState; | ||
| 24 | } | ||
| 25 | } else { | ||
| 26 | /** | ||
| 27 | * @internal | ||
| 28 | */ | ||
| 29 | trait LazyObjectTrait | ||
| 30 | { | ||
| 31 | #[Ignore] | ||
| 32 | private LazyObjectState $lazyObjectState; | ||
| 33 | } | ||
| 34 | } | ||
diff --git a/vendor/symfony/var-exporter/Internal/Reference.php b/vendor/symfony/var-exporter/Internal/Reference.php new file mode 100644 index 0000000..2c7bd7b --- /dev/null +++ b/vendor/symfony/var-exporter/Internal/Reference.php | |||
| @@ -0,0 +1,28 @@ | |||
| 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 | /** | ||
| 15 | * @author Nicolas Grekas <p@tchwork.com> | ||
| 16 | * | ||
| 17 | * @internal | ||
| 18 | */ | ||
| 19 | class Reference | ||
| 20 | { | ||
| 21 | public int $count = 0; | ||
| 22 | |||
| 23 | public function __construct( | ||
| 24 | public readonly int $id, | ||
| 25 | public readonly mixed $value = null, | ||
| 26 | ) { | ||
| 27 | } | ||
| 28 | } | ||
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 | } | ||
diff --git a/vendor/symfony/var-exporter/Internal/Values.php b/vendor/symfony/var-exporter/Internal/Values.php new file mode 100644 index 0000000..4f20a82 --- /dev/null +++ b/vendor/symfony/var-exporter/Internal/Values.php | |||
| @@ -0,0 +1,25 @@ | |||
| 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 | /** | ||
| 15 | * @author Nicolas Grekas <p@tchwork.com> | ||
| 16 | * | ||
| 17 | * @internal | ||
| 18 | */ | ||
| 19 | class Values | ||
| 20 | { | ||
| 21 | public function __construct( | ||
| 22 | public readonly array $values, | ||
| 23 | ) { | ||
| 24 | } | ||
| 25 | } | ||
