Skip to content
✔️An advanced parameter parser for PHP
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
examples
src/Parameters
.gitignore
LICENSE
ReadMe.md
composer.json

ReadMe.md

Parameter Parser

Parameter Parser is a simple library used to parse intricate parameters from an array of strings.

Hint: Parameter Parser is available through Composer. composer require nafisc/parameterparser.

StyleCI Latest Stable Version Total Downloads Latest Unstable Version License

Documentation - Advanced Code Examples - Looking for the Python version?

Features

  • Parse command line parameters.
  • Assign aliases to parameters.
  • Custom closures for each command line parameter.
  • Variadic closure support for arguments taking more than one value.
  • Customize the way the command line is parsed.

Example Usage

// Initialize a new Cluster
$parameters = new Cluster();

// Add a Parameter to the Cluster
$parameter = parameter('-', 'name', function ($name) {
    return $name;
});

$parameter->setRequired(true)
          ->setDescription('Your name.');

$parameters->add($parameter);

// Create a new Parser using the Cluster
$parser = new Parser($argv, $parameters);

// Parse the parameters using the Parser.
$results = $parser->parse();

// Verify that the parameters were valid after parsing.
if (! $parser->isValid()) {

    // Since it was not valid, output usage.
    $parameters->printFullUsage(
        "Parameter Parser",
        "An advanced parameter parser for PHP",
        "v1.0.0"
    );

} else {

    // Retrieve the name from the results
    $name = $results['name'];

    // Output the name
    echo 'Your name is ' . $name . PHP_EOL;

}

Output

~/ php test.php -name 'Nathan Fiscaletti'

   Your name is Nathan Fiscaletti
You can’t perform that action at this time.