Skip to content

Commit

Permalink
Merge branch '6.3' into 6.4
Browse files Browse the repository at this point in the history
* 6.3:
  fix merge
  [VarDumper] Test intl formatter broken since dumper does not replace the nnbsp character by standard space
  [WebProfilerBundle] Fix intercept external redirects
  [Webhook] Added missing XML attribute in config XSD
  [String] Skip a test when an issue is detected in PCRE2
  [ExpressionLanguage] Fix null coalescing propagation
  [Mailer] Stop using the (local) AWS shared configuration in the PHPUnit tests.
  detect colors on not windows
  fix xterm detection
  refactor: hyper check
  Missing translations for Slovak (sk) #51954
  Remove redundant PHPdoc line
  properly handle SYMFONY_DOTENV_VARS being the empty string
  Avoid incompatibility with symfony/console 7
  bug #45057 [Messenger] Avoid reconnecting active Redis connections.
  [HttpKernel] Catch `TypeError` if the wrong type is used in `BackedEnumValueResolver`
  [Serializer] fix regression where nullable int cannot be serialized
  do not overwrite an application's default serialization context
  • Loading branch information
xabbuh committed Dec 10, 2023
2 parents 6c8b12f + 1bea7c1 commit 7d63ccd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Node/NullCoalesceNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function compile(Compiler $compiler): void
public function evaluate(array $functions, array $values): mixed
{
if ($this->nodes['expr1'] instanceof GetAttrNode) {
$this->nodes['expr1']->attributes['is_null_coalesce'] = true;
$this->addNullCoalesceAttributeToGetAttrNodes($this->nodes['expr1']);
}

return $this->nodes['expr1']->evaluate($functions, $values) ?? $this->nodes['expr2']->evaluate($functions, $values);
Expand All @@ -49,4 +49,17 @@ public function toArray(): array
{
return ['(', $this->nodes['expr1'], ') ?? (', $this->nodes['expr2'], ')'];
}

private function addNullCoalesceAttributeToGetAttrNodes(Node $node): void
{
if (!$node instanceof GetAttrNode) {
return;
}

$node->attributes['is_null_coalesce'] = true;

foreach ($node->nodes as $node) {
$this->addNullCoalesceAttributeToGetAttrNodes($node);
}
}
}
3 changes: 3 additions & 0 deletions Tests/ExpressionLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ public function bar()
yield ['foo["bar"]["baz"] ?? "default"', ['bar' => null]];
yield ['foo["bar"].baz ?? "default"', ['bar' => null]];
yield ['foo.bar().baz ?? "default"', $foo];
yield ['foo.bar.baz.bam ?? "default"', (object) ['bar' => null]];
yield ['foo?.bar?.baz?.qux ?? "default"', (object) ['bar' => null]];
yield ['foo[123][456][789] ?? "default"', [123 => []]];
}

/**
Expand Down

0 comments on commit 7d63ccd

Please sign in to comment.