webignition/symfony-console-typed-input

Symfony InputInterface 提供特定类型获取选项和参数的方法

0.6 2021-02-18 14:29 UTC

This package is auto-updated.

Last update: 2024-09-18 22:36:23 UTC


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');