Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
adding support for the ?? operator
- Loading branch information
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
class Twig_Node_Expression_NullCoalesce extends Twig_Node_Expression_Conditional | ||
{ | ||
public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno) | ||
{ | ||
$test = new Twig_Node_Expression_Binary_And( | ||
new Twig_Node_Expression_Test_Defined(clone $left, 'defined', new Twig_Node(), $left->getLine()), | ||
new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getLine()), $left->getLine()), | ||
$left->getLine() | ||
); | ||
|
||
parent::__construct($test, $left, $right, $lineno); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
Twig supports the ?? operator | ||
--TEMPLATE-- | ||
{{ 'OK' ?? 'KO' }} | ||
{{ null ?? 'OK' }} | ||
{{ bar ?? 'KO' }} | ||
{{ baz ?? 'OK' }} | ||
{{ foo.bar ?? 'KO' }} | ||
{{ foo.missing ?? 'OK' }} | ||
{{ foo.bar.baz.missing ?? 'OK' }} | ||
{{ foo['bar'] ?? 'KO' }} | ||
{{ foo['missing'] ?? 'OK' }} | ||
{{ nope ?? nada ?? 'OK' }} | ||
{{ 1 + nope ?? nada ?? 2 }} | ||
{{ 1 + nope ?? 3 + nada ?? 2 }} | ||
--DATA-- | ||
return array('bar' => 'OK', 'foo' => array('bar' => 'OK')) | ||
--EXPECT-- | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
3 | ||
6 |