The goal of this project is to build an alternative to php's getopt, which ich really crippled.
<?php
require_once('GetOpts.php');
list($errors, $params, $args) = (new GetOpts([
'a' => [GetOpts::TOGGLE, 'a'],
'b' => [GetOpts::VALUE, 'b', 'long'],
]))->parse();
if ($errors) {
die($errors[0].PHP_EOL);
}
echo 'a = '.var_export($params['a'], true).', ';
echo 'b = '.var_export($params['b'], true).', ';
echo 'args = '.var_export($args, true).PHP_EOL;
php test.php -a file
a = true, b = false, args = array('file')
-a is given, therefore true. -b is not given. 'file' is not attached to an option and returned as args.
php test.php -a --long file -a
a = false, b = 'file', args = array()
-a is given twice, and since a is defined as toggle it's off (false). -b is given (as the long version --long). No other arguments.