public function route(Zend_Controller_Request_Abstract $dispatcher) { $getopt = new Zend_Console_Getopt(array()); $getopt->addRules(array('controller|c=s' => 'Controller Name', 'action|a=s' => 'Controller Action', 'from|f=s' => 'From yyyy-mm-dd', 'to|t=s' => 'To yyyy-mm-dd')); $arguments = $getopt->getRemainingArgs(); if ($getopt->getOption('controller') && $getopt->getOption('action')) { $dispatcher->setControllerName($getopt->getOption('controller')); $dispatcher->setActionName($getopt->getOption('action')); $dispatcher->setParams(array('from' => $getopt->getOption('from'), 'to' => $getopt->getOption('to'))); return $dispatcher; } }
/** * @group ZF-2064 */ public function testAddRulesDoesNotThrowWarnings() { // Fails if warning is thrown: Should not happen! $opts = new Zend_Console_Getopt('abp:'); $opts->addRules(array('verbose|v' => 'Print verbose output')); }
public function testAddRules() { $opts = new Zend_Console_Getopt(array('apple|a' => 'Apple option', 'banana|b' => 'Banana option'), array('--pear', 'pear_param')); try { $opts->parse(); } catch (Zend_Console_Getopt_Exception $e) { $this->assertEquals($e->getMessage(), 'Option "pear" is not recognized.'); } $opts->addRules(array('pear|p=s' => 'Pear option')); $this->assertEquals($opts->pear, 'pear_param'); }
private function _parseParams($context, $argv) { $opts = new Zend_Console_Getopt(); $aliases = array(); foreach ($context->attribute as $attribute) { // Key should be the rule string, value is the long usage $opts->addRules(array($attribute->getopt, $attribute->usage)); } $opts->addArguments($argv); return $opts->parse(); }