mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
N°8910 - Upgrade Symfony packages
This commit is contained in:
@@ -76,32 +76,23 @@ class Exporter
|
||||
$class = $value::class;
|
||||
$reflector = Registry::$reflectors[$class] ??= Registry::getClassReflector($class);
|
||||
$properties = [];
|
||||
$sleep = null;
|
||||
$proto = Registry::$prototypes[$class];
|
||||
|
||||
if ($reflector->hasMethod('__serialize')) {
|
||||
if (!$reflector->getMethod('__serialize')->isPublic()) {
|
||||
throw new \Error(sprintf('Call to %s method "%s::__serialize()".', $reflector->getMethod('__serialize')->isProtected() ? 'protected' : 'private', $class));
|
||||
throw new \Error(\sprintf('Call to %s method "%s::__serialize()".', $reflector->getMethod('__serialize')->isProtected() ? 'protected' : 'private', $class));
|
||||
}
|
||||
|
||||
if (!\is_array($serializeProperties = $value->__serialize())) {
|
||||
if (!\is_array($arrayValue = $value->__serialize())) {
|
||||
throw new \TypeError($class.'::__serialize() must return an array');
|
||||
}
|
||||
|
||||
if ($reflector->hasMethod('__unserialize')) {
|
||||
$properties = $serializeProperties;
|
||||
} else {
|
||||
foreach ($serializeProperties as $n => $v) {
|
||||
$c = $reflector->hasProperty($n) && ($p = $reflector->getProperty($n))->isReadOnly() ? $p->class : 'stdClass';
|
||||
$properties[$c][$n] = $v;
|
||||
}
|
||||
$properties = $arrayValue;
|
||||
goto prepare_value;
|
||||
}
|
||||
|
||||
goto prepare_value;
|
||||
}
|
||||
|
||||
$sleep = null;
|
||||
$proto = Registry::$prototypes[$class];
|
||||
|
||||
if (($value instanceof \ArrayIterator || $value instanceof \ArrayObject) && null !== $proto) {
|
||||
} elseif (($value instanceof \ArrayIterator || $value instanceof \ArrayObject) && null !== $proto) {
|
||||
// ArrayIterator and ArrayObject need special care because their "flags"
|
||||
// option changes the behavior of the (array) casting operator.
|
||||
[$arrayValue, $properties] = self::getArrayObjectProperties($value, $proto);
|
||||
@@ -117,10 +108,7 @@ class Exporter
|
||||
}
|
||||
$properties = ['SplObjectStorage' => ["\0" => $properties]];
|
||||
$arrayValue = (array) $value;
|
||||
} elseif ($value instanceof \Serializable
|
||||
|| $value instanceof \__PHP_Incomplete_Class
|
||||
|| \PHP_VERSION_ID < 80200 && $value instanceof \DatePeriod
|
||||
) {
|
||||
} elseif ($value instanceof \Serializable || $value instanceof \__PHP_Incomplete_Class || \PHP_VERSION_ID < 80200 && $value instanceof \DatePeriod) {
|
||||
++$objectsCount;
|
||||
$objectsPool[$value] = [$id = \count($objectsPool), serialize($value), [], 0];
|
||||
$value = new Reference($id);
|
||||
@@ -144,15 +132,15 @@ class Exporter
|
||||
$i = 0;
|
||||
$n = (string) $name;
|
||||
if ('' === $n || "\0" !== $n[0]) {
|
||||
$c = $reflector->hasProperty($n) && ($p = $reflector->getProperty($n))->isReadOnly() ? $p->class : 'stdClass';
|
||||
$parent = $reflector;
|
||||
do {
|
||||
$p = $parent->hasProperty($n) ? $parent->getProperty($n) : null;
|
||||
} while (!$p && $parent = $parent->getParentClass());
|
||||
|
||||
$c = $p && (!$p->isPublic() || (\PHP_VERSION_ID >= 80400 ? $p->isProtectedSet() || $p->isPrivateSet() : $p->isReadOnly())) ? $p->class : 'stdClass';
|
||||
} elseif ('*' === $n[1]) {
|
||||
$n = substr($n, 3);
|
||||
$c = $reflector->getProperty($n)->class;
|
||||
if ('Error' === $c) {
|
||||
$c = 'TypeError';
|
||||
} elseif ('Exception' === $c) {
|
||||
$c = 'ErrorException';
|
||||
}
|
||||
} else {
|
||||
$i = strpos($n, "\0", 2);
|
||||
$c = substr($n, 1, $i - 1);
|
||||
@@ -165,13 +153,19 @@ class Exporter
|
||||
}
|
||||
unset($sleep[$name], $sleep[$n]);
|
||||
}
|
||||
if (!\array_key_exists($name, $proto) || $proto[$name] !== $v || "\x00Error\x00trace" === $name || "\x00Exception\x00trace" === $name) {
|
||||
if ("\x00Error\x00trace" === $name || "\x00Exception\x00trace" === $name) {
|
||||
$properties[$c][$n] = $v;
|
||||
} elseif (!\array_key_exists($name, $proto) || $proto[$name] !== $v) {
|
||||
$properties[match ($c) {
|
||||
'Error' => 'TypeError',
|
||||
'Exception' => 'ErrorException',
|
||||
default => $c,
|
||||
}][$n] = $v;
|
||||
}
|
||||
}
|
||||
if ($sleep) {
|
||||
foreach ($sleep as $n => $v) {
|
||||
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE);
|
||||
trigger_error(\sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
if (method_exists($class, '__unserialize')) {
|
||||
@@ -224,10 +218,10 @@ class Exporter
|
||||
$subIndent = $indent.' ';
|
||||
|
||||
if (\is_string($value)) {
|
||||
$code = sprintf("'%s'", addcslashes($value, "'\\"));
|
||||
$code = \sprintf("'%s'", addcslashes($value, "'\\"));
|
||||
|
||||
$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) {
|
||||
$m[1] = sprintf('\'."%s".\'', str_replace(
|
||||
$m[1] = \sprintf('\'."%s".\'', str_replace(
|
||||
["\0", "\r", "\n", "\u{202A}", "\u{202B}", "\u{202D}", "\u{202E}", "\u{2066}", "\u{2067}", "\u{2068}", "\u{202C}", "\u{2069}", '\n\\'],
|
||||
['\0', '\r', '\n', '\u{202A}', '\u{202B}', '\u{202D}', '\u{202E}', '\u{2066}', '\u{2067}', '\u{2068}', '\u{202C}', '\u{2069}', '\n"'."\n".$subIndent.'."\\'],
|
||||
$m[1]
|
||||
@@ -285,7 +279,7 @@ class Exporter
|
||||
return self::exportHydrator($value, $indent, $subIndent);
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException(sprintf('Cannot export value of type "%s".', get_debug_type($value)));
|
||||
throw new \UnexpectedValueException(\sprintf('Cannot export value of type "%s".', get_debug_type($value)));
|
||||
}
|
||||
|
||||
private static function exportRegistry(Registry $value, string $indent, string $subIndent): string
|
||||
|
||||
Reference in New Issue
Block a user