/** * Starts the console application. The method checks the action to run, * parses the arguments and fires it. * * @throws Opl_Console_Exception * @param array $argv The argument list. */ public function run(array $argv) { $action = isset($argv[1]) ? $argv[1] : $this->_default; if (!Opl_Registry::exists('stdout')) { Opl_Registry::set('stdout', new Opl_Stream_Console_Output()); } if (!Opl_Registry::exists('stdin')) { Opl_Registry::set('stdin', new Opl_Stream_Console_Input()); } if (isset($this->_actions[$action])) { unset($argv[0], $argv[1]); $getopt = new Opl_Getopt(Opl_Getopt::ALLOW_LONG_ARGS | Opl_Getopt::ALLOW_SHORT_ARGS | Opl_Getopt::AUTO_HELP); foreach ($this->_actions[$action]->getParams() as $option) { $getopt->addOption($option); } if (!$getopt->parse(array_values($argv))) { // TODO: Exception goes here! return; } $this->runAction($action, $getopt->getIterator()->getArrayCopy()); } else { if ($this->_flags & self::AUTO_HELP) { $this->showHelp(); } else { throw new Opl_Console_Exception('The specified action \'' . $action . '\' does not exist.'); } } }
/** * @covers Opl_Getopt::__construct * @covers Opl_Getopt::addOption */ public function testHasOption() { $getopt = new Opl_Getopt(); $getopt->addOption(new Opl_Getopt_Option('foo')); $this->assertTrue($getopt->hasOption('foo')); $this->assertFalse($getopt->hasOption('bar')); }