本文整理汇总了PHP中Zend_Console_Getopt::addRules方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Console_Getopt::addRules方法的具体用法?PHP Zend_Console_Getopt::addRules怎么用?PHP Zend_Console_Getopt::addRules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Console_Getopt
的用法示例。
在下文中一共展示了Zend_Console_Getopt::addRules方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: route
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;
}
}
示例2: testAddRulesDoesNotThrowWarnings
/**
* @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'));
}
示例3: testAddRules
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');
}
示例4: _parseParams
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();
}