Option
in package
FinalYes
Represents a console command <option> definition.
Can be used in the parameters of the invoke method.
#[AsCommand(name: 'app:user:created')
class CreateUserCommand {
public function __invoke(
#[Option(description: "The username of the user")] string $userId,
IOutput $output,
): ExitCode {
// ...
return ExitCode::Success;
}
}
Or on methods parameters:
class UserCommands {
#[AsCommand('app:user:create')]
public function create(
#[Option(description: "The username of the user")] string $userId,
IOutput $output,
): ExitCode {
// ...
return ExitCode::Success;
}
#[AsCommand('app:user:delete')]
public function delete(
#[Option(description: "The username of the user")] string $userId,
IOutput $output,
): ExitCode {
// ...
return ExitCode::Success;
}
}
Tags
Attributes
- #[Attribute]
- \Attribute::TARGET_PARAMETER
- #[Consumable]
- $since: '35.0.0'
Table of Contents
Properties
- $description : string
- $name : string
- $shortcut : array<string|int, mixed>|string|null
- $suggestedValues : array<string|int, mixed>|Closure
Methods
- __construct() : mixed
- If unset, the `name` value will be inferred from the parameter definition.
Properties
$description
public
string
$description
= ''
$name
public
string
$name
= ''
$shortcut
public
array<string|int, mixed>|string|null
$shortcut
= null
$suggestedValues
public
array<string|int, mixed>|Closure
$suggestedValues
= []
Methods
__construct()
If unset, the `name` value will be inferred from the parameter definition.
public
__construct([string $description = '' ][, string $name = '' ][, array<string|int, mixed>|string|null $shortcut = null ][, array<string|int, mixed>|Closure $suggestedValues = [] ]) : mixed
To declare an option whose value is itself optional (e.g. "--foo" alone returns
true, "--foo=bar" returns 'bar', and omitting the option returns false),
type the parameter as a union of bool with string, int or float
(e.g. string|bool $foo = false).
Parameters
- $description : string = ''
-
The description of the option, displayed with the help page
- $name : string = ''
-
The name of the option
- $shortcut : array<string|int, mixed>|string|null = null
-
The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
- $suggestedValues : array<string|int, mixed>|Closure = []
-
An array or a closure that provides suggested values for the option.