File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed
src/Symfony/Component/ExpressionLanguage Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ CHANGELOG
6
6
7
7
* Add support for null-coalescing unknown variables
8
8
* Add support for comments using ` /* ` & ` */ `
9
+ * Allow passing any iterable as ` $providers ` list to ` ExpressionLanguage ` constructor
9
10
10
11
7.1
11
12
---
Original file line number Diff line number Diff line change @@ -32,9 +32,9 @@ class ExpressionLanguage
32
32
protected array $ functions = [];
33
33
34
34
/**
35
- * @param ExpressionFunctionProviderInterface[] $providers
35
+ * @param iterable< ExpressionFunctionProviderInterface> $providers
36
36
*/
37
- public function __construct (?CacheItemPoolInterface $ cache = null , array $ providers = [])
37
+ public function __construct (?CacheItemPoolInterface $ cache = null , iterable $ providers = [])
38
38
{
39
39
$ this ->cache = $ cache ?? new ArrayAdapter ();
40
40
$ this ->registerFunctions ();
Original file line number Diff line number Diff line change @@ -137,9 +137,12 @@ public function testCompiledEnumFunctionWithBackedEnum()
137
137
$ this ->assertSame (FooBackedEnum::Bar, $ result );
138
138
}
139
139
140
- public function testProviders ()
140
+ /**
141
+ * @dataProvider providerTestCases
142
+ */
143
+ public function testProviders (iterable $ providers )
141
144
{
142
- $ expressionLanguage = new ExpressionLanguage (null , [ new TestProvider ()] );
145
+ $ expressionLanguage = new ExpressionLanguage (null , $ providers );
143
146
$ this ->assertEquals ('foo ' , $ expressionLanguage ->evaluate ('identity("foo") ' ));
144
147
$ this ->assertEquals ('"foo" ' , $ expressionLanguage ->compile ('identity("foo") ' ));
145
148
$ this ->assertEquals ('FOO ' , $ expressionLanguage ->evaluate ('strtoupper("foo") ' ));
@@ -150,6 +153,14 @@ public function testProviders()
150
153
$ this ->assertEquals ('\Symfony\Component\ExpressionLanguage\Tests\Fixtures\fn_namespaced() ' , $ expressionLanguage ->compile ('fn_namespaced() ' ));
151
154
}
152
155
156
+ public static function providerTestCases (): iterable
157
+ {
158
+ yield 'array ' => [[new TestProvider ()]];
159
+ yield 'Traversable ' => [(function () {
160
+ yield new TestProvider ();
161
+ })()];
162
+ }
163
+
153
164
/**
154
165
* @dataProvider shortCircuitProviderEvaluate
155
166
*/
You can’t perform that action at this time.
0 commit comments