Skip to content

Commit 1021a24

Browse files
ipsosdavidkrizf3l1x
authored andcommitted
Allow name to be dynamic parameter
1 parent f229171 commit 1021a24

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/DI/ConsoleExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getConfigSchema(): Schema
4646
{
4747
return Expect::structure([
4848
'url' => Expect::anyOf(Expect::string(), Expect::null())->dynamic(),
49-
'name' => Expect::string(),
49+
'name' => Expect::string()->dynamic(),
5050
'version' => Expect::anyOf(Expect::string(), Expect::int(), Expect::float()),
5151
'catchExceptions' => Expect::bool(),
5252
'autoExit' => Expect::bool(),

tests/cases/DI/ConsoleExtension.phpt

+21
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,24 @@ test(function (): void {
209209
Assert::type(Application::class, $container->getByType(Application::class));
210210
Assert::equal('https://contributte.org/', (string) $container->getService('http.request')->getUrl());
211211
});
212+
213+
// Name as Dynamic parameter
214+
test(function (): void {
215+
$loader = new ContainerLoader(TEMP_DIR, true);
216+
$class = $loader->load(function (Compiler $compiler): void {
217+
$compiler->setDynamicParameterNames(['name']);
218+
$compiler->addExtension('console', new ConsoleExtension(true));
219+
$compiler->loadConfig(FileMock::create('
220+
console:
221+
name: %name%
222+
parameters:
223+
name: Hello world
224+
', 'neon'));
225+
}, [getmypid(), 10]);
226+
227+
/** @var Container $container */
228+
$container = new $class();
229+
230+
$application = $container->getByType(Application::class);
231+
Assert::equal('Hello world', $application->getName());
232+
});

0 commit comments

Comments
 (0)