webignition / symfony-console-typed-input
Symfony InputInterface 提供特定类型获取选项和参数的方法
0.6
2021-02-18 14:29 UTC
Requires
- php: >=7.4|^8
- symfony/console: ^4.4|^5.0
Requires (Dev)
- mockery/mockery: ^1.4
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^0.12.77
- phpstan/phpstan-mockery: ^0.12.12
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
- symplify/easy-coding-standard: ^9.1
README
为 Symfony\Component\Console\Input\InputInterface
提供一个包装器,增加了整数和布尔特定参数和选项的获取器。
适合喜欢强类型PHP的开发者,或者那些在分析Symfony控制台命令时厌倦了与 phpstan 的 --level max
级别战斗的开发者。
方法
public function getIntegerArgument(string $name): int; public function getIntegerOption(string $name): int; public function getBooleanArgument(string $name): bool; public function getBooleanOption(string $name): bool;
其他所有 InputInterface
方法调用都会代理到包装的 InputInterface
实例。
用法
use webignition\SymfonyConsole\TypedInput\TypedInput; // Assuming we're in a console command and $input is an InputInterface instance $typedInput = new TypedInput($input); // Guaranteed to return an integer $integerArgument = $typedInput->getIntegerArgument('integer-argument-name'); $integerOption = $typedInput->getIntegerOption('integer-option-name'); // Guaranteed to return a boolean $booleanArgument = $typedInput->getBooleanArgument('boolean-argument-name'); $booleanOption = $typedInput->getBooleanOption('boolean-option-name');