Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf28f610

Browse files
committed
[ExpressionLanguage] Addmin andmax php functions
1 parent0102e1e commitf28f610

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

‎src/Symfony/Component/ExpressionLanguage/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add support for php`min` and`max` functions
8+
49
7.0
510
---
611

‎src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ public function registerProvider(ExpressionFunctionProviderInterface $provider):
140140
*/
141141
protectedfunctionregisterFunctions()
142142
{
143-
$this->addFunction(ExpressionFunction::fromPhp('constant'));
143+
$basicPhpFunctions = ['constant','min','max'];
144+
foreach ($basicPhpFunctionsas$function) {
145+
$this->addFunction(ExpressionFunction::fromPhp($function));
146+
}
144147

145148
$this->addFunction(newExpressionFunction('enum',
146149
staticfn ($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),

‎src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,23 @@ public function testCachedParse()
7171
$this->assertSame($savedParsedExpression,$parsedExpression);
7272
}
7373

74-
publicfunctiontestConstantFunction()
74+
/**
75+
* @dataProvider basicPhpFunctionProvider
76+
*/
77+
publicfunctiontestBasicPhpFunction($expression,$expected,$compiled)
7578
{
7679
$expressionLanguage =newExpressionLanguage();
77-
$this->assertEquals(\PHP_VERSION,$expressionLanguage->evaluate('constant("PHP_VERSION")'));
80+
$this->assertEquals($expected,$expressionLanguage->evaluate($expression));
81+
$this->assertEquals($compiled,$expressionLanguage->compile($expression));
82+
}
7883

79-
$expressionLanguage =newExpressionLanguage();
80-
$this->assertEquals('\constant("PHP_VERSION")',$expressionLanguage->compile('constant("PHP_VERSION")'));
84+
publicstaticfunctionbasicPhpFunctionProvider()
85+
{
86+
return [
87+
['constant("PHP_VERSION")', \PHP_VERSION,'\constant("PHP_VERSION")'],
88+
['min(1,2,3)',1,'\min(1, 2, 3)'],
89+
['max(1,2,3)',3,'\max(1, 2, 3)'],
90+
];
8191
}
8292

8393
publicfunctiontestEnumFunctionWithConstantThrows()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp