Skip to content

Commit fdff486

Browse files
committed
Support config interpolation in array values
Make Configuration::parse() recursive so {{ }} placeholders inside array config values (at any depth) are interpolated, not only strings.
1 parent 6c6e886 commit fdff486

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ public function parse(mixed $value): mixed
120120
}, $normalizedValue);
121121
}
122122

123+
if (is_array($value)) {
124+
return array_map($this->parse(...), $value);
125+
}
126+
123127
return $value;
124128
}
125129

tests/src/Configuration/ConfigurationTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ public function testParse()
1717
self::assertEquals('a b', $config->parse('{{foo}} {{bar}}'));
1818
}
1919

20+
public function testParseArray()
21+
{
22+
$config = new Configuration();
23+
$config->set('foo', 'a');
24+
$config->set('bar', 'b');
25+
$config->set('list', ['{{foo}}', '{{bar}}', 'c']);
26+
$config->set('nested', [
27+
'key' => '{{foo}}',
28+
'deep' => ['{{bar}}', 42, null],
29+
]);
30+
31+
self::assertEquals(['a', 'b', 'c'], $config->get('list'));
32+
self::assertEquals([
33+
'key' => 'a',
34+
'deep' => ['b', 42, null],
35+
], $config->get('nested'));
36+
}
37+
2038
public function testUnset()
2139
{
2240
$config = new Configuration();

0 commit comments

Comments
 (0)