本文整理汇总了PHP中Console_Getopt::getOpt2方法的典型用法代码示例。如果您正苦于以下问题:PHP Console_Getopt::getOpt2方法的具体用法?PHP Console_Getopt::getOpt2怎么用?PHP Console_Getopt::getOpt2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Console_Getopt
的用法示例。
在下文中一共展示了Console_Getopt::getOpt2方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
require_once 'Console/Getopt.php';
define('NO_ARGS', 1);
define('INVALID_OPTION', 2);
$args = Console_Getopt::readPHPArgv();
if (count($args) <= 1) {
$this->usage(true);
exit(1);
}
if (PEAR::isError($args)) {
fputs(STDERR, $args->getMessage() . "\n");
exit(NO_ARGS);
}
if ($_SERVER['argv'][0] == $_SERVER['SCRIPT_NAME']) {
$this->opts = Console_Getopt::getOpt($args, $this->short_opts, $this->long_opts);
} else {
$this->opts = Console_Getopt::getOpt2($args, $this->short_opts, $this->long_opts);
}
// Are the passed options valid?
if (PEAR::isError($this->opts)) {
fputs(STDERR, $this->opts->getMessage() . "\n");
exit(INVALID_OPTION);
}
$this->set_cache();
}
示例2: __construct
public function __construct()
{
$args = Console_Getopt::readPHPArgv();
if (PEAR::isError($args)) {
fwrite(STDERR, $args->getMessage() . "\n");
exit(1);
}
// Compatibility between "php script.php" and "./script.php"
if (realpath($_SERVER['argv'][0]) == __FILE__) {
$this->options = Console_Getopt::getOpt($args, $this->short_format_config);
} else {
$this->options = Console_Getopt::getOpt2($args, $this->short_format_config);
}
// Check for invalid options
if (PEAR::isError($this->options)) {
fwrite(STDERR, $this->options->getMessage() . "\n");
$this->help();
}
$this->command = array();
// Loop through the user provided options
foreach ($this->options[0] as $option) {
switch ($option[0]) {
case 'h':
help();
break;
case 's':
$this->command['syntax'] = $option[1];
break;
case 't':
$this->command['transform'] = $option[1];
break;
case 'c':
$this->command['config'] = $option[1];
break;
}
}
// Loop through the user provided options
foreach ($this->options[1] as $argument) {
$this->command['query'] .= ' ' . $argument;
}
}