本文整理汇总了PHP中eZCLI::parseOptionString方法的典型用法代码示例。如果您正苦于以下问题:PHP eZCLI::parseOptionString方法的具体用法?PHP eZCLI::parseOptionString怎么用?PHP eZCLI::parseOptionString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZCLI
的用法示例。
在下文中一共展示了eZCLI::parseOptionString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptions
function getOptions($config, $argumentConfig, $arguments = false)
{
$program = false;
if ($arguments === false) {
$arguments = $GLOBALS['argv'];
$program = $arguments[0];
array_shift($arguments);
}
if (is_string($config)) {
$config = eZCLI::parseOptionString($config, $tmpConfig);
}
if (is_string($argumentConfig)) {
$argumentConfig = eZCLI::parseOptionString($argumentConfig, $tmpArgumentConfig);
}
$options = array();
$helpOption = false;
$helpText = false;
if (isset($config['short']['h'])) {
$helpOption = '-h';
} else {
if (isset($config['short']['help'])) {
$helpOption = '--help';
}
}
if ($helpOption) {
$helpText = "\n" . "Try `{$program} {$helpOption}' for more information.";
}
$options['arguments'] = array();
$arguments = array_values($arguments);
$argumentCount = count($arguments);
for ($i = 0; $i < $argumentCount; ++$i) {
$argument = $arguments[$i];
$argumentLen = strlen($argument);
if ($argumentLen > 1 and $argument[0] == '-') {
$argumentValue = false;
if ($argumentLen > 2 and $argument[1] == '-') {
$optionName = substr($argument, 2);
$assignPosition = strpos($optionName, '=');
if ($assignPosition !== false) {
$argumentValue = substr($optionName, $assignPosition + 1);
$optionName = substr($optionName, 0, $assignPosition);
}
$optionType = 'long';
$optionPrefix = '--';
$checkNext = false;
} else {
$optionName = $argument[1];
if ($argumentLen > 2) {
$argumentValue = substr($argument, 2);
}
$optionType = 'short';
$optionPrefix = '-';
$checkNext = true;
}
$configItem =& $config[$optionType][$optionName];
if (isset($configItem)) {
$value = true;
$hasValue = $configItem['has-value'];
$hasMultipleValues = ($configItem['quantifier']['min'] > 1 or $configItem['quantifier']['max'] === false or $configItem['quantifier']['max'] > 1);
if ($hasValue) {
$hasArgumentValue = false;
if ($argumentValue !== false) {
$value = $argumentValue;
} else {
if ($checkNext and $configItem['has-value'] !== 'optional') {
++$i;
if ($i < $argumentCount) {
$hasArgumentValue = true;
} else {
--$i;
$this->error("{$program}: option `{$optionPrefix}{$optionName}' requires an argument" . $helpText);
return false;
}
if ($hasArgumentValue) {
$value = $arguments[$i];
}
} else {
if ($configItem['has-value'] !== 'optional') {
$this->error("{$program}: option `{$optionPrefix}{$optionName}' requires an argument" . $helpText);
return false;
}
}
}
}
$optionStoreName = $configItem['store-name'];
if (!$optionStoreName) {
$optionStoreName = $optionName;
}
if ($hasMultipleValues) {
if (!isset($options[$optionStoreName])) {
$options[$optionStoreName] = array();
}
$options[$optionStoreName][] = $value;
} else {
$options[$optionStoreName] = $value;
}
} else {
$this->error("{$program}: invalid option `{$optionPrefix}{$optionName}'" . $helpText);
return false;
}
//.........这里部分代码省略.........
示例2: getOptions
function getOptions($config = '', $argumentConfig = '', $optionHelp = false, $arguments = false, $useStandardOptions = true)
{
if (is_string($config)) {
$config = eZCLI::parseOptionString($config, $tmpConfig);
}
if (is_string($argumentConfig)) {
$argumentConfig = eZCLI::parseOptionString($argumentConfig, $tmpArgumentConfig);
}
if ($useStandardOptions) {
if (!is_array($useStandardOptions)) {
$useStandardOptions = array();
}
$useStandardOptions = array_merge(array('debug' => true, 'colors' => true, 'log' => true, 'siteaccess' => true, 'verbose' => true, 'root' => true, 'user' => false), $useStandardOptions);
}
if ($useStandardOptions) {
$optionConfig = $config;
$excludeOptions = array();
$optionString = "[h|help][q|quiet]";
$excludeOptions[] = 'h';
$excludeOptions[] = 'help';
$excludeOptions[] = 'q';
$excludeOptions[] = 'quiet';
if ($useStandardOptions['debug']) {
$optionString .= "[d;*|debug;*]";
$excludeOptions[] = 'd';
$excludeOptions[] = 'debug';
}
if ($useStandardOptions['colors']) {
$optionString .= "[c|colors][no-colors]";
$excludeOptions[] = 'c';
$excludeOptions[] = 'colors';
$excludeOptions[] = 'no-colors';
}
if ($useStandardOptions['log']) {
$optionString .= "[logfiles][no-logfiles]";
$excludeOptions[] = 'logfiles';
$excludeOptions[] = 'no-logfiles';
}
if ($useStandardOptions['siteaccess']) {
$optionString .= "[s:|siteaccess:]";
$excludeOptions[] = 's';
$excludeOptions[] = 'siteaccess';
}
if ($useStandardOptions['user']) {
$optionString .= "[l:|login:][p:|password:]";
$excludeOptions[] = 'l';
$excludeOptions[] = 'login';
$excludeOptions[] = 'p';
$excludeOptions[] = 'password';
}
if ($useStandardOptions['verbose']) {
$optionString .= "[v*|verbose*]";
$excludeOptions[] = 'v';
$excludeOptions[] = 'verbose';
}
if ($useStandardOptions['root']) {
$optionString .= "[r?|allow-root-user?]";
$excludeOptions[] = 'r';
$excludeOptions[] = 'allow-root-user';
}
$config = eZCLI::parseOptionString($optionString, $optionConfig);
}
$cli = eZCLI::instance();
$options = $cli->getOptions($config, $argumentConfig, $arguments);
$this->CurrentOptionConfig = $config;
$this->CurrentOptions = $options;
$this->CurrentStandardOptions = $useStandardOptions;
$this->CurrentExcludeOptions = $excludeOptions;
$this->CurrentOptionHelp = $optionHelp;
$this->ArgumentConfig = $argumentConfig;
if (!$options) {
if (!$this->IsInitialized) {
$this->initialize();
}
$this->shutdown(1);
}
if ($useStandardOptions) {
if (function_exists('posix_getuid')) {
if (posix_getuid() === 0) {
if (!$options['allow-root-user']) {
$cli->warning("Running scripts as root may be dangerous.");
$cli->warning("If you think you know what you are doing, you can run this script with the ");
$cli->warning("root account by appending the parameter --allow-root-user.");
exit(1);
} else {
// ho no, you are not going to be quiet while
// running with root priviledges
$this->setIsQuiet(false);
$cli = eZCLI::instance();
$cli->warning('With great power comes great responsibility.');
$cli->warning("You have 10 seconds to break the script (press Ctrl-C).");
sleep(10);
}
}
}
if ($options['quiet']) {
$this->setIsQuiet(true);
}
$useColors = true;
if ($options['colors']) {
//.........这里部分代码省略.........