Skip to content

Usage

How to parse a command line, and the public methods of the parser.

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

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().
  • has(int|string $key): bool: true when the result of the last parse() has $key.
  • parse(array $argv = []): array: parses $argv ($_SERVER['argv'] when $argv is empty) without its first item, the script name, and returns the options and the arguments.
Navigation

Type to search…

↑↓ navigate↵ selectEsc close