Skip to content

Commit 75cf6aa

Browse files
juniwalkf3l1x
authored andcommitted
Added dynamic parameter ability to version
1 parent 70dd8a6 commit 75cf6aa

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/DI/ConsoleExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function getConfigSchema(): Schema
3939
return Expect::structure([
4040
'url' => Expect::anyOf(Expect::string(), Expect::null())->dynamic(),
4141
'name' => Expect::string()->dynamic(),
42-
'version' => Expect::anyOf(Expect::string(), Expect::int(), Expect::float()),
42+
'version' => Expect::anyOf(Expect::string(), Expect::int(), Expect::float())->dynamic(),
4343
'catchExceptions' => Expect::bool()->dynamic(),
4444
'autoExit' => Expect::bool(),
4545
'helperSet' => Expect::anyOf(Expect::string(), Expect::type(Statement::class)),
@@ -73,7 +73,11 @@ public function loadConfiguration(): void
7373

7474
// Setup console version
7575
if ($config->version !== null) {
76-
$applicationDef->addSetup('setVersion', [(string) $config->version]);
76+
if (!$config->version instanceof Statement) {
77+
$config->version = (string) $config->version;
78+
}
79+
80+
$applicationDef->addSetup('setVersion', [$config->version]);
7781
}
7882

7983
// Catch or populate exceptions

tests/Cases/DI/ConsoleExtension.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use Tests\Fixtures\FooAliasCommand;
1616
use Tests\Fixtures\FooCommand;
1717
use Tests\Fixtures\FooHiddenCommand;
1818
use Tests\Fixtures\FooRequestFactory;
19+
use Tests\Fixtures\Version;
1920

2021
require_once __DIR__ . '/../../bootstrap.php';
2122

@@ -184,6 +185,22 @@ Toolkit::test(function (): void {
184185
Assert::equal('Hello world', $application->getName());
185186
});
186187

188+
// Version as Dynamic parameter
189+
Toolkit::test(function (): void {
190+
$container = ContainerBuilder::of()
191+
->withCompiler(function (Compiler $compiler): void {
192+
$compiler->setDynamicParameterNames(['version']);
193+
$compiler->addExtension('console', new ConsoleExtension(true));
194+
$compiler->addConfig(Neonkit::load(<<<'NEON'
195+
console:
196+
version: Tests\Fixtures\Version::get()
197+
NEON));
198+
})->build();
199+
200+
$application = $container->getByType(Application::class);
201+
Assert::equal(Version::get(), $application->getVersion());
202+
});
203+
187204
// Use custom request Factory
188205
Toolkit::test(function (): void {
189206
$container = ContainerBuilder::of()

tests/Fixtures/Version.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Tests\Fixtures;
4+
5+
class Version
6+
{
7+
8+
public static function get(): string
9+
{
10+
return '1.0-alpha.1';
11+
}
12+
13+
}

0 commit comments

Comments
 (0)