From 1021a24c98dff6ecdf4cc3d77cc3db159959b45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20K=C5=99=C3=AD=C5=BE?= Date: Wed, 2 Aug 2023 12:51:58 +0200 Subject: [PATCH] Allow name to be dynamic parameter --- src/DI/ConsoleExtension.php | 2 +- tests/cases/DI/ConsoleExtension.phpt | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/DI/ConsoleExtension.php b/src/DI/ConsoleExtension.php index 96b65b9..211adbc 100644 --- a/src/DI/ConsoleExtension.php +++ b/src/DI/ConsoleExtension.php @@ -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(), diff --git a/tests/cases/DI/ConsoleExtension.phpt b/tests/cases/DI/ConsoleExtension.phpt index f4ee053..5dc161f 100644 --- a/tests/cases/DI/ConsoleExtension.phpt +++ b/tests/cases/DI/ConsoleExtension.phpt @@ -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()); +});