Class Arguments
Provides an interface for interacting with a command's options and arguments.
Property Summary
Method Summary
-
__construct() public
Constructor
-
assertArgumentExists() protected
-
getArgument() public
Returns positional argument value by name or null if doesn't exist
-
getArgumentAt() public
Get positional arguments by index.
-
getArguments() public
Get all positional arguments.
-
getBooleanOption() public
Get a boolean option's value or null if not set.
-
getMultipleOption() public
Gets a multiple option's value or null if not set.
-
getOption() public
Get a non-multiple option's value or null if not set.
-
getOptions() public
Get an array of all the options
-
hasArgument() public
Check if a positional argument exists by name
-
hasArgumentAt() public
Check if a positional argument exists by index
-
hasOption() public
Check if an option is defined and not null.
Method Detail
__construct() ¶ public
__construct(array<int, string> $args, array<string, list<string>|string|bool|null> $options, array<int, string> $argNames)
Constructor
Parameters
-
array<int, string>
$args Positional arguments
-
array<string, list<string>|string|bool|null>
$options Named arguments
-
array<int, string>
$argNames List of argument names. Order is expected to be the same as $args.
assertArgumentExists() ¶ protected
assertArgumentExists(string $name): void
Parameters
-
string
$name
Returns
void
getArgument() ¶ public
getArgument(string $name): string|null
Returns positional argument value by name or null if doesn't exist
Parameters
-
string
$name The argument name to check.
Returns
string|null
getArgumentAt() ¶ public
getArgumentAt(int $index): string|null
Get positional arguments by index.
Parameters
-
int
$index The argument index to access.
Returns
string|null
getArguments() ¶ public
getArguments(): array<int, string>
Get all positional arguments.
Returns
array<int, string>
getBooleanOption() ¶ public
getBooleanOption(string $name): bool|null
Get a boolean option's value or null if not set.
Parameters
-
string
$name
Returns
bool|null
getMultipleOption() ¶ public
getMultipleOption(string $name): list<string>|null
Gets a multiple option's value or null if not set.
Parameters
-
string
$name
Returns
list<string>|null
getOption() ¶ public
getOption(string $name): string|bool|null
Get a non-multiple option's value or null if not set.
Parameters
-
string
$name The name of the option to check.
Returns
string|bool|null
getOptions() ¶ public
getOptions(): array<string, list<string>|string|bool|null>
Get an array of all the options
Returns
array<string, list<string>|string|bool|null>
hasArgument() ¶ public
hasArgument(string $name): bool
Check if a positional argument exists by name
Parameters
-
string
$name The argument name to check.
Returns
bool
hasArgumentAt() ¶ public
hasArgumentAt(int $index): bool
Check if a positional argument exists by index
Parameters
-
int
$index The argument index to check.
Returns
bool
hasOption() ¶ public
hasOption(string $name): bool
Check if an option is defined and not null.
Parameters
-
string
$name The name of the option to check.
Returns
bool