Skip to content

Commit 03d4736

Browse files
Merge branch '7.3' into 7.4
* 7.3: [Serializer] Fix unknown type in denormalization errors when union type used in constructor [JsonPath] Add `Nothing` enum to support special nothing value [HttpKernel] Handle an array vary header in the http cache store for write [Console] Fix handling of `\E` in Bash completion
2 parents f24609f + 8d9c001 commit 03d4736

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

JsonCrawler.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -720,12 +720,12 @@ private function evaluateScalar(string $expr, mixed $context): mixed
720720
$bracketContent = substr($path, 1, -1);
721721
$result = $this->evaluateBracket($bracketContent, $context);
722722

723-
return $result ? $result[0] : self::nothing();
723+
return $result ? $result[0] : Nothing::Nothing;
724724
}
725725

726726
$results = $this->evaluateTokensOnDecodedData(JsonPathTokenizer::tokenize(new JsonPath('$'.$path)), $context);
727727

728-
return $results ? $results[0] : self::nothing();
728+
return $results ? $results[0] : Nothing::Nothing;
729729
}
730730

731731
// function calls
@@ -783,7 +783,7 @@ private function evaluateFunction(string $name, string $args, mixed $context): m
783783
\is_string($value) => mb_strlen($value),
784784
\is_array($value) => \count($value),
785785
$value instanceof \stdClass => \count(get_object_vars($value)),
786-
default => self::nothing(),
786+
default => Nothing::Nothing,
787787
},
788788
'count' => $nodelistSize,
789789
'match' => match (true) {
@@ -794,7 +794,7 @@ private function evaluateFunction(string $name, string $args, mixed $context): m
794794
\is_string($value) && \is_string($argList[1] ?? null) => (bool) @preg_match("/{$this->transformJsonPathRegex($argList[1])}/u", $value),
795795
default => false,
796796
},
797-
'value' => 1 < $nodelistSize ? self::nothing() : (1 === $nodelistSize ? (\is_array($value) ? ($value[0] ?? null) : $value) : $value),
797+
'value' => 1 < $nodelistSize ? Nothing::Nothing : (1 === $nodelistSize ? (\is_array($value) ? ($value[0] ?? null) : $value) : $value),
798798
default => null,
799799
};
800800
}
@@ -831,8 +831,8 @@ private function compare(mixed $left, mixed $right, string $operator): bool
831831

832832
private function compareEquality(mixed $left, mixed $right): bool
833833
{
834-
$leftIsNothing = $left === self::nothing();
835-
$rightIsNothing = $right === self::nothing();
834+
$leftIsNothing = $left === Nothing::Nothing;
835+
$rightIsNothing = $right === Nothing::Nothing;
836836

837837
if (
838838
$leftIsNothing && $rightIsNothing
@@ -1101,11 +1101,6 @@ private function isValidMixedBracketExpression(string $expr): bool
11011101
return $hasFilter && $validMixed && 1 < \count($parts);
11021102
}
11031103

1104-
private static function nothing(): \stdClass
1105-
{
1106-
return self::$nothing ??= new \stdClass();
1107-
}
1108-
11091104
private function getValueIfKeyExists(mixed $value, string $key): array
11101105
{
11111106
return $this->isArrayOrObject($value) && \array_key_exists($key, $arrayValue = (array) $value) ? [$arrayValue[$key]] : [];

Nothing.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\JsonPath;
13+
14+
enum Nothing
15+
{
16+
case Nothing;
17+
}

0 commit comments

Comments
 (0)