mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 01:44:26 +02:00
@@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Added support for PHP8.2
|
- Added support for PHP8.2
|
||||||
- Added a new way to extend Smarty functionality using `Smarty::addExtension()`. Please see the docs for more information.
|
- Added a new way to extend Smarty functionality using `Smarty::addExtension()`. Please see the docs for more information.
|
||||||
- Custom tags can accept positional parameters, so you can write a block compiler that support this: `{trans "Jack" "dull boy"}All work and no play makes %s a %s.{/trans}` [#164](https://github.com/smarty-php/smarty/issues/164)
|
- Custom tags can accept positional parameters, so you can write a block compiler that support this: `{trans "Jack" "dull boy"}All work and no play makes %s a %s.{/trans}` [#164](https://github.com/smarty-php/smarty/issues/164)
|
||||||
- Full support for ternary operator: `{$test ? $a : $b}` and `{$var ?: $alternative}` [#881](https://github.com/smarty-php/smarty/issues/881)
|
- Full support for ternary operator: `{$test ? $a : $b}` and `{$var ?: $value_if_falsy}` [#881](https://github.com/smarty-php/smarty/issues/881)
|
||||||
|
- Full support for null coalescing operator: `{$var ?? $value_if_null}` [#882](https://github.com/smarty-php/smarty/issues/882)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- All Smarty code is now in the \Smarty namespace. For simple use-cases, you only need to add
|
- All Smarty code is now in the \Smarty namespace. For simple use-cases, you only need to add
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -617,6 +617,11 @@ expr(res) ::= value(v). {
|
|||||||
res = v;
|
res = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nullcoalescing
|
||||||
|
expr(res) ::= nullcoalescing(v). {
|
||||||
|
res = v;
|
||||||
|
}
|
||||||
|
|
||||||
// ternary
|
// ternary
|
||||||
expr(res) ::= ternary(v). {
|
expr(res) ::= ternary(v). {
|
||||||
res = v;
|
res = v;
|
||||||
@@ -668,6 +673,10 @@ expr(res) ::= expr(e1) ISIN value(v). {
|
|||||||
res = 'in_array('.e1.',(array)'.v.')';
|
res = 'in_array('.e1.',(array)'.v.')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// null coalescing
|
||||||
|
nullcoalescing(res) ::= expr(v) QMARK QMARK expr(e2). {
|
||||||
|
res = v.' ?? '.e2;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// ternary
|
// ternary
|
||||||
|
34
tests/UnitTests/TemplateSource/NullCoalescingTest.php
Normal file
34
tests/UnitTests/TemplateSource/NullCoalescingTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class NullCoalescingTest extends PHPUnit_Smarty {
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->setUpSmarty('/tmp');
|
||||||
|
$this->cleanDirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUndefined() {
|
||||||
|
$tpl = $this->smarty->createTemplate('string:{$myvar ?? "undefined"}');
|
||||||
|
$this->assertEquals('undefined', $this->smarty->fetch($tpl));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataForOther
|
||||||
|
*/
|
||||||
|
public function testOther($value, $expected) {
|
||||||
|
$tpl = $this->smarty->createTemplate('string:{$myvar ?? "undefined"}');
|
||||||
|
$tpl->assign('myvar', $value);
|
||||||
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataForOther() {
|
||||||
|
return [
|
||||||
|
[null, 'undefined'],
|
||||||
|
['blah', ''],
|
||||||
|
['', ''],
|
||||||
|
[false, false],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user