Skip to content

Commit f229171

Browse files
JanMikesf3l1x
authored andcommitted
Allow URL to be dynamic parameter
1 parent 3807724 commit f229171

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/DI/ConsoleExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(bool $cliMode = false)
4545
public function getConfigSchema(): Schema
4646
{
4747
return Expect::structure([
48-
'url' => Expect::anyOf(Expect::string(), Expect::null()),
48+
'url' => Expect::anyOf(Expect::string(), Expect::null())->dynamic(),
4949
'name' => Expect::string(),
5050
'version' => Expect::anyOf(Expect::string(), Expect::int(), Expect::float()),
5151
'catchExceptions' => Expect::bool(),

tests/cases/DI/ConsoleExtension.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,25 @@ test(function (): void {
187187
$application = $container->getByType(Application::class);
188188
Assert::type(Application::class, $application);
189189
});
190+
191+
// URL as Dynamic parameter
192+
test(function (): void {
193+
$loader = new ContainerLoader(TEMP_DIR, true);
194+
$class = $loader->load(function (Compiler $compiler): void {
195+
$compiler->setDynamicParameterNames(['url']);
196+
$compiler->addExtension('console', new ConsoleExtension(true));
197+
$compiler->addExtension('http', new HttpExtension(true));
198+
$compiler->loadConfig(FileMock::create('
199+
console:
200+
url: %url%
201+
parameters:
202+
url: https://contributte.org/
203+
', 'neon'));
204+
}, [getmypid(), 9]);
205+
206+
/** @var Container $container */
207+
$container = new $class();
208+
209+
Assert::type(Application::class, $container->getByType(Application::class));
210+
Assert::equal('https://contributte.org/', (string) $container->getService('http.request')->getUrl());
211+
});

0 commit comments

Comments
 (0)