Skip to content

Commit

Permalink
Allow name to be dynamic parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ipsosdavidkriz committed Aug 3, 2023
1 parent f229171 commit 21aac50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DI/ConsoleExtension.php
Expand Up @@ -46,7 +46,7 @@ public function getConfigSchema(): Schema
{
return Expect::structure([
'url' => Expect::anyOf(Expect::string(), Expect::null())->dynamic(),
'name' => Expect::string(),
'name' => Expect::string()->dynamic(),
'version' => Expect::anyOf(Expect::string(), Expect::int(), Expect::float()),
'catchExceptions' => Expect::bool(),
'autoExit' => Expect::bool(),
Expand Down
21 changes: 21 additions & 0 deletions tests/cases/DI/ConsoleExtension.phpt
Expand Up @@ -209,3 +209,24 @@ test(function (): void {
Assert::type(Application::class, $container->getByType(Application::class));
Assert::equal('https://contributte.org/', (string) $container->getService('http.request')->getUrl());
});

// Name as Dynamic parameter
test(function (): void {
$loader = new ContainerLoader(TEMP_DIR, true);
$class = $loader->load(function (Compiler $compiler): void {
$compiler->setDynamicParameterNames(['name']);
$compiler->addExtension('console', new ConsoleExtension(true));
$compiler->loadConfig(FileMock::create('
console:
name: %name%
parameters:
name: Hello world
', 'neon'));
}, [getmypid(), 10]);

/** @var Container $container */
$container = new $class();

$application = $container->getByType(Application::class);
Assert::equal('Hello world', $application->getName());
});

0 comments on commit 21aac50

Please sign in to comment.