/** * Evaluate the given arguments. These can be passed either as a string or as an array. * If nothing is passed, the running script's command line arguments are used. * * An {@link \UnexpectedValueException} or {@link \InvalidArgumentException} is thrown * when the arguments are not well-formed or do not conform to the options passed by the user. * * @param mixed $arguments optional ARGV array or space separated string */ public function parse($arguments = null) { $this->options = array(); if (!isset($arguments)) { global $argv; $arguments = $argv; $this->scriptName = array_shift($arguments); // $argv[0] is the script's name } elseif (is_string($arguments)) { $this->scriptName = $_SERVER['PHP_SELF']; $arguments = explode(' ', $arguments); } $parser = new CommandLineParser($this->optionList); $parser->parse($arguments); $this->options = $parser->getOptions(); $this->operands = $parser->getOperands(); }
public function testSingleHyphenOperand() { $parser = new CommandLineParser(array(new Option('a', null, Getopt::REQUIRED_ARGUMENT))); $parser->parse('-a 0 -'); $options = $parser->getOptions(); $this->assertEquals('0', $options['a']); $operands = $parser->getOperands(); $this->assertCount(1, $operands); $this->assertEquals('-', $operands[0]); }