Skip to content

Commit ac02d33

Browse files
committed
[ExpressionLanguage] Allow passing any iterable as $providers list
1 parent 74df71a commit ac02d33

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/Symfony/Component/ExpressionLanguage/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add support for null-coalescing unknown variables
88
* Add support for comments using `/*` & `*/`
9+
* Allow passing any iterable as `$providers` list to `ExpressionLanguage` constructor
910

1011
7.1
1112
---

src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class ExpressionLanguage
3232
protected array $functions = [];
3333

3434
/**
35-
* @param ExpressionFunctionProviderInterface[] $providers
35+
* @param iterable<ExpressionFunctionProviderInterface> $providers
3636
*/
37-
public function __construct(?CacheItemPoolInterface $cache = null, array $providers = [])
37+
public function __construct(?CacheItemPoolInterface $cache = null, iterable $providers = [])
3838
{
3939
$this->cache = $cache ?? new ArrayAdapter();
4040
$this->registerFunctions();

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,12 @@ public function testCompiledEnumFunctionWithBackedEnum()
137137
$this->assertSame(FooBackedEnum::Bar, $result);
138138
}
139139

140-
public function testProviders()
140+
/**
141+
* @dataProvider providerTestCases
142+
*/
143+
public function testProviders(iterable $providers)
141144
{
142-
$expressionLanguage = new ExpressionLanguage(null, [new TestProvider()]);
145+
$expressionLanguage = new ExpressionLanguage(null, $providers);
143146
$this->assertEquals('foo', $expressionLanguage->evaluate('identity("foo")'));
144147
$this->assertEquals('"foo"', $expressionLanguage->compile('identity("foo")'));
145148
$this->assertEquals('FOO', $expressionLanguage->evaluate('strtoupper("foo")'));
@@ -150,6 +153,14 @@ public function testProviders()
150153
$this->assertEquals('\Symfony\Component\ExpressionLanguage\Tests\Fixtures\fn_namespaced()', $expressionLanguage->compile('fn_namespaced()'));
151154
}
152155

156+
public static function providerTestCases(): iterable
157+
{
158+
yield 'array' => [[new TestProvider()]];
159+
yield 'Traversable' => [(function () {
160+
yield new TestProvider();
161+
})()];
162+
}
163+
153164
/**
154165
* @dataProvider shortCircuitProviderEvaluate
155166
*/

0 commit comments

Comments
 (0)