use Phalcon\Cop\Parser;$parser = new Parser();// Parse params from the $argv$params = $parser->parse($argv);// Parse params from the $_SERVER['argv']$params = $parser->parse();// After parsing input, Parser provides a way to get booleans:$parser->getBoolean('foo');// Get param `foo` or return TRUE as a default value$parser->getBoolean('foo', true);// Get param `out` as a string. A missing option, or an option with no// value (`--out`), returns the default value$parser->getString('out', 'output.txt');
Methods
get(int|string $key, mixed $default = null): mixed: the value of $key in the result of the last parse(), or $default when the result has no $key.
getBoolean(string $key, bool $default = false): bool: the value of $key as a boolean. An option with no value gives true; y, yes, true, 1 and on give true; n, no, false, 0 and off give false. A missing key or another value gives $default.
getParsedCommands(): array: the result of the last parse().
getString(int|string $key, string $default = ''): string: the value of $key as a string. A missing key, or an option with no value, gives $default.
has(int|string $key): bool: true when the result of the last parse() has $key.
parse(array $argv = [], array $flags = []): array: parses $argv ($_SERVER['argv'] when $argv is empty) without its first item, the script name, and returns the options and the arguments. $flags are the names of the options that take no value, for this call only (see Flags).