Skip to content

Commit

Permalink
Allow URL to be dynamic parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMikes authored and f3l1x committed May 24, 2023
1 parent 3807724 commit f229171
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DI/ConsoleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(bool $cliMode = false)
public function getConfigSchema(): Schema
{
return Expect::structure([
'url' => Expect::anyOf(Expect::string(), Expect::null()),
'url' => Expect::anyOf(Expect::string(), Expect::null())->dynamic(),
'name' => Expect::string(),
'version' => Expect::anyOf(Expect::string(), Expect::int(), Expect::float()),
'catchExceptions' => Expect::bool(),
Expand Down
22 changes: 22 additions & 0 deletions tests/cases/DI/ConsoleExtension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,25 @@ test(function (): void {
$application = $container->getByType(Application::class);
Assert::type(Application::class, $application);
});

// URL as Dynamic parameter
test(function (): void {
$loader = new ContainerLoader(TEMP_DIR, true);
$class = $loader->load(function (Compiler $compiler): void {
$compiler->setDynamicParameterNames(['url']);
$compiler->addExtension('console', new ConsoleExtension(true));
$compiler->addExtension('http', new HttpExtension(true));
$compiler->loadConfig(FileMock::create('
console:
url: %url%
parameters:
url: https://contributte.org/
', 'neon'));
}, [getmypid(), 9]);

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

Assert::type(Application::class, $container->getByType(Application::class));
Assert::equal('https://contributte.org/', (string) $container->getService('http.request')->getUrl());
});

0 comments on commit f229171

Please sign in to comment.