Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/ExpressionLanguage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.1
---

* Add support for php `min` and `max` functions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Add support for php `min` and `max` functions
* Add support for PHP `min` and `max` functions


7.0
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ public function registerProvider(ExpressionFunctionProviderInterface $provider):
*/
protected function registerFunctions()
{
$this->addFunction(ExpressionFunction::fromPhp('constant'));
$basicPhpFunctions = ['constant', 'min', 'max'];
foreach ($basicPhpFunctions as $function) {
$this->addFunction(ExpressionFunction::fromPhp($function));
}

$this->addFunction(new ExpressionFunction('enum',
static fn ($str): string => sprintf("(\constant(\$v = (%s))) instanceof \UnitEnum ? \constant(\$v) : throw new \TypeError(\sprintf('The string \"%%s\" is not the name of a valid enum case.', \$v))", $str),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ public function testCachedParse()
$this->assertSame($savedParsedExpression, $parsedExpression);
}

public function testConstantFunction()
/**
* @dataProvider basicPhpFunctionProvider
*/
public function testBasicPhpFunction($expression, $expected, $compiled)
{
$expressionLanguage = new ExpressionLanguage();
$this->assertEquals(\PHP_VERSION, $expressionLanguage->evaluate('constant("PHP_VERSION")'));
$this->assertEquals($expected, $expressionLanguage->evaluate($expression));
$this->assertEquals($compiled, $expressionLanguage->compile($expression));
}

$expressionLanguage = new ExpressionLanguage();
$this->assertEquals('\constant("PHP_VERSION")', $expressionLanguage->compile('constant("PHP_VERSION")'));
public static function basicPhpFunctionProvider()
{
return [
['constant("PHP_VERSION")', \PHP_VERSION, '\constant("PHP_VERSION")'],
['min(1,2,3)', 1, '\min(1, 2, 3)'],
['max(1,2,3)', 3, '\max(1, 2, 3)'],
];
}

public function testEnumFunctionWithConstantThrows()
Expand Down