Allow providing manual signature hint to commands
This commit is contained in:
parent
0bca797e8d
commit
6671ec3eac
@ -19,10 +19,13 @@ class Command
|
|||||||
/** @var callable $handler The handler */
|
/** @var callable $handler The handler */
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
public function __construct(string $name, callable $handler)
|
private ?array $signature;
|
||||||
|
|
||||||
|
public function __construct(string $name, callable $handler, ?array $signature = null)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->handler = $handler;
|
$this->handler = $handler;
|
||||||
|
$this->signature = $signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
@ -66,5 +69,10 @@ class Command
|
|||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSignature(): array
|
||||||
|
{
|
||||||
|
return $this->signature ?? $this->parameters();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ class CommandTest extends \PHPUnit\Framework\TestCase
|
|||||||
$command = new Command("test", function (string $a, ?int $b, bool $c = false) { });
|
$command = new Command("test", function (string $a, ?int $b, bool $c = false) { });
|
||||||
$expect = [
|
$expect = [
|
||||||
'a' => 'string',
|
'a' => 'string',
|
||||||
'b' => 'int',
|
'b' => '?int',
|
||||||
'c' => '?bool'
|
'c' => 'bool=false'
|
||||||
];
|
];
|
||||||
$this->assertEquals($expect, $command->parameters());
|
$this->assertEquals($expect, $command->parameters());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user