Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+34 -30
View File
@@ -22,19 +22,41 @@ class JsonDecode implements DecoderInterface
{
protected $serializer;
private $associative;
private $recursionDepth;
/**
* True to return the result as an associative array, false for a nested stdClass hierarchy.
*/
public const ASSOCIATIVE = 'json_decode_associative';
public const OPTIONS = 'json_decode_options';
/**
* Specifies the recursion depth.
*/
public const RECURSION_DEPTH = 'json_decode_recursion_depth';
private $defaultContext = [
self::ASSOCIATIVE => false,
self::OPTIONS => 0,
self::RECURSION_DEPTH => 512,
];
/**
* Constructs a new JsonDecode instance.
*
* @param bool $associative True to return the result associative array, false for a nested stdClass hierarchy
* @param int $depth Specifies the recursion depth
* @param array $defaultContext
*/
public function __construct($associative = false, $depth = 512)
public function __construct($defaultContext = [], int $depth = 512)
{
$this->associative = $associative;
$this->recursionDepth = (int) $depth;
if (!\is_array($defaultContext)) {
@trigger_error(sprintf('Using constructor parameters that are not a default context is deprecated since Symfony 4.2, use the "%s" and "%s" keys of the context instead.', self::ASSOCIATIVE, self::RECURSION_DEPTH), \E_USER_DEPRECATED);
$defaultContext = [
self::ASSOCIATIVE => (bool) $defaultContext,
self::RECURSION_DEPTH => $depth,
];
}
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
}
/**
@@ -47,7 +69,7 @@ class JsonDecode implements DecoderInterface
* The $context array is a simple key=>value array, with the following supported keys:
*
* json_decode_associative: boolean
* If true, returns the object as associative array.
* If true, returns the object as an associative array.
* If false, returns the object as nested stdClass
* If not specified, this method will use the default set in JsonDecode::__construct
*
@@ -56,7 +78,7 @@ class JsonDecode implements DecoderInterface
* If not specified, this method will use the default set in JsonDecode::__construct
*
* json_decode_options: integer
* Specifies additional options as per documentation for json_decode. Only supported with PHP 5.4.0 and higher
* Specifies additional options as per documentation for json_decode
*
* @return mixed
*
@@ -66,11 +88,9 @@ class JsonDecode implements DecoderInterface
*/
public function decode($data, $format, array $context = [])
{
$context = $this->resolveContext($context);
$associative = $context['json_decode_associative'];
$recursionDepth = $context['json_decode_recursion_depth'];
$options = $context['json_decode_options'];
$associative = $context[self::ASSOCIATIVE] ?? $this->defaultContext[self::ASSOCIATIVE];
$recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH];
$options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
try {
$decodedData = json_decode($data, $associative, $recursionDepth, $options);
@@ -96,20 +116,4 @@ class JsonDecode implements DecoderInterface
{
return JsonEncoder::FORMAT === $format;
}
/**
* Merges the default options of the Json Decoder with the passed context.
*
* @return array
*/
private function resolveContext(array $context)
{
$defaultOptions = [
'json_decode_associative' => $this->associative,
'json_decode_recursion_depth' => $this->recursionDepth,
'json_decode_options' => 0,
];
return array_merge($defaultOptions, $context);
}
}