Released version 1.9.0
Requirements
- PHP 8.2 or higher is now required
New Features
Fluent API for Parser
New methods for defining options programmatically:
addSwitch()- adds a flag without value (e.g.--verbose)addOption()- adds an option with value (e.g.--format json)addArgument()- adds a positional argumentaddFromHelp()- extracts options from formatted help text
$parser = (new Parser)
->addSwitch('--verbose', '-v', description: 'Enable verbose mode')
->addOption('--format', '-f', optionalValue: true, fallback: 'json')
->addArgument('file');Early-Exit Parsing with parseOnly()
New method for parsing only specific options without validation:
// Check --help before full validation
if ($parser->parseOnly(['--help'])['--help']) {
$parser->help();
exit;
}
$args = $parser->parse(); // full parsing with validationUseful for --help and --version options that should work without providing required arguments.
Internal Changes
- Parser refactored to use
Optionobjects internally instead of arrays - Enum validation now runs before normalizer (BC break)
- Used
#[Deprecated]attribute for deprecated constants