本文整理汇总了PHP中Option::setDefaultValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::setDefaultValue方法的具体用法?PHP Option::setDefaultValue怎么用?PHP Option::setDefaultValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option::setDefaultValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddSaveInitAddValues
function testAddSaveInitAddValues()
{
$option = new Option();
$option->setKey('key');
$option->setDefaultValue('value');
$option->setType('string');
$wpoptions = new WpOptions('test');
$options = new Options('test', $wpoptions);
$options->add($option);
$options->updateValue('key', 'value2');
$options->save();
$wpoptions = new WpOptions('test');
$options = new Options('test', $wpoptions);
$option = new Option();
$option->setKey('key');
$option->setDefaultValue('value');
$option->setType('string');
$options->init();
$options->add($option);
$this->assertEquals('value2', $options->get('key')->getValue());
$this->assertEquals('value', $options->get('key')->getDefaultValue());
}
示例2: main
function main()
{
// Check Env
CommandLineUtils::checkRequiredExtentions();
// Options
$helpOpt = new Option(null, 'help');
$helpOpt->setDescription('Print usage information.');
$zookeeper_connectOpt = new Option(null, 'zookeeper_connect', Getopt::REQUIRED_ARGUMENT);
$zookeeper_connectOpt->setDescription('REQUIRED:
The connection string for the zookeeper connection in the form
"host1:port1,host2:port2,host3:port3/chroot/path", The "/chroot/path" of connection string
*MUST* be the same as of the kafka server. Multiple URLS can be given to allow fail-over.');
$createOpt = new Option(null, 'create');
$createOpt->setDescription('Create a new config.');
$deleteOpt = new Option(null, 'delete');
$deleteOpt->setDescription('Delete a config');
$listOpt = new Option(null, 'list');
$listOpt->setDescription('List all available configs.');
$monitorOpt = new Option(null, 'monitor');
$monitorOpt->setDescription('Monitor all available configs.');
$logkafka_idOpt = new Option(null, 'logkafka_id', Getopt::REQUIRED_ARGUMENT);
$logkafka_idOpt->setDescription('The logkafka_id which holds log files');
$logkafka_idOpt->setValidation(function ($value) {
$ret = AdminUtils::isLogkafkaIdValid($value);
return $ret['valid'];
});
$log_pathOpt = new Option(null, 'log_path', Getopt::REQUIRED_ARGUMENT);
$log_pathOpt->setDescription('The log file path, like "/usr/local/apache2/logs/access_log.%Y%m%d"');
$log_pathOpt->setValidation(function ($value) {
$ret = AdminUtils::isFilePathValid($value);
return $ret['valid'];
});
$topicOpt = new Option(null, 'topic', Getopt::REQUIRED_ARGUMENT);
$topicOpt->setDescription('The topic of messages to be sent.');
$topicOpt->setValidation(function ($value) {
return AdminUtils::isTopicValid($value);
});
$partitionOpt = new Option(null, 'partition', Getopt::REQUIRED_ARGUMENT);
$partitionOpt->setDescription('The partition of messages to be sent.' . '-1 : random' . 'n(>=0): partition n');
$partitionOpt->setDefaultValue('-1');
$partitionOpt->setValidation(function ($value) {
return is_numeric($value);
});
$keyOpt = new Option(null, 'key', Getopt::REQUIRED_ARGUMENT);
$keyOpt->setDescription('The key of messages to be sent.');
$keyOpt->setDefaultValue('');
$keyOpt->setValidation(function ($value) {
return is_string($value);
});
$requiredAcksOpt = new Option(null, 'required_acks', Getopt::REQUIRED_ARGUMENT);
$requiredAcksOpt->setDescription('Required ack number');
$requiredAcksOpt->setDefaultValue('1');
$requiredAcksOpt->setValidation(function ($value) {
return is_numeric($value);
});
$compression_codecOpt = new Option(null, 'compression_codec', Getopt::REQUIRED_ARGUMENT);
$compression_codecOpt->setDescription("Optional compression method of messages: " . implode(", ", AdminUtils::$COMPRESSION_CODECS));
$compression_codecOpt->setDefaultValue('none');
$compression_codecOpt->setValidation(function ($value) {
return AdminUtils::isCompressionCodecValid($value);
});
$batchsizeOpt = new Option(null, 'batchsize', Getopt::REQUIRED_ARGUMENT);
$batchsizeOpt->setDescription('The batch size of messages to be sent');
$batchsizeOpt->setDefaultValue('1000');
$batchsizeOpt->setValidation(function ($value) {
return is_numeric($value) && (int) $value > 0;
});
$follow_lastOpt = new Option(null, 'follow_last', Getopt::REQUIRED_ARGUMENT);
$follow_lastOpt->setDescription('If set to "false", when restarting logkafka process,
the log_path formatted with current time will be collect;
If set to "true", when restarting logkafka process, the last
collecting file will be collected continually');
$follow_lastOpt->setDefaultValue('true');
$follow_lastOpt->setValidation(function ($value) {
return in_array($value, array('true', 'false'));
});
$message_timeout_msOpt = new Option(null, 'message_timeout_ms', Getopt::REQUIRED_ARGUMENT);
$message_timeout_msOpt->setDescription('Local message timeout. This value is only enforced locally
and limits the time a produced message waits for successful delivery.
A time of 0 is infinite.');
$message_timeout_msOpt->setDefaultValue('0');
$message_timeout_msOpt->setValidation(function ($value) {
return is_numeric($value) && (int) $value >= 0;
});
$regex_filter_patternOpt = new Option(null, 'regex_filter_pattern', Getopt::REQUIRED_ARGUMENT);
$regex_filter_patternOpt->setDescription("Optional regex filter pattern, the messages matching this pattern will be dropped");
$regex_filter_patternOpt->setDefaultValue('');
$regex_filter_patternOpt->setValidation(function ($value) {
return AdminUtils::isRegexFilterPatternValid($value);
});
$lagging_max_bytesOpt = new Option(null, 'lagging_max_bytes', Getopt::REQUIRED_ARGUMENT);
$lagging_max_bytesOpt->setDescription("log lagging max bytes, the monitor will alarm according to this setting");
$lagging_max_bytesOpt->setDefaultValue('');
$lagging_max_bytesOpt->setValidation(function ($value) {
return is_numeric($value) && (int) $value >= 0;
});
$rotate_lagging_max_secOpt = new Option(null, 'rotate_lagging_max_sec', Getopt::REQUIRED_ARGUMENT);
$rotate_lagging_max_secOpt->setDescription("log rotatiion lagging max seconds, the monitor will alarm according to this setting");
$rotate_lagging_max_secOpt->setDefaultValue('');
$rotate_lagging_max_secOpt->setValidation(function ($value) {
//.........这里部分代码省略.........
示例3: main
function main()
{
// Check Env
CommandLineUtils::checkRequiredExtentions();
// Options
$helpOpt = new Option(null, 'help');
$helpOpt->setDescription('Print usage information.');
$zookeeperOpt = new Option(null, 'zookeeper', Getopt::REQUIRED_ARGUMENT);
$zookeeperOpt->setDescription('REQUIRED: The connection string for the zookeeper connection in the form host:port.' . 'Multiple URLS can be given to allow fail-over.');
$createOpt = new Option(null, 'create');
$createOpt->setDescription('Create a new config.');
$deleteOpt = new Option(null, 'delete');
$deleteOpt->setDescription('Delete a config');
$listOpt = new Option(null, 'list');
$listOpt->setDescription('List all available configs.');
$hostnameOpt = new Option(null, 'hostname', Getopt::REQUIRED_ARGUMENT);
$hostnameOpt->setDescription('The hostname of machine which holds log files');
$log_pathOpt = new Option(null, 'log_path', Getopt::REQUIRED_ARGUMENT);
$log_pathOpt->setDescription('The log file path, like "/usr/local/apache2/logs/access_log.%Y%m%d"');
$log_pathOpt->setValidation(function ($value) {
$ret = AdminUtils::isFilePathValid($value);
return $ret['valid'];
});
$topicOpt = new Option(null, 'topic', Getopt::REQUIRED_ARGUMENT);
$topicOpt->setDescription('The topic of messages to be sent.');
$topicOpt->setValidation(function ($value) {
return AdminUtils::isTopicValid($value);
});
$partitionOpt = new Option(null, 'partition', Getopt::REQUIRED_ARGUMENT);
$partitionOpt->setDescription('The partition of messages to be sent.' . '-1 : random' . 'n(>=0): partition n');
$partitionOpt->setDefaultValue(-1);
$partitionOpt->setValidation(function ($value) {
return is_numeric($value);
});
$keyOpt = new Option(null, 'key', Getopt::REQUIRED_ARGUMENT);
$keyOpt->setDescription('The key of messages to be sent.');
$keyOpt->setDefaultValue('');
$keyOpt->setValidation(function ($value) {
return is_string($value);
});
$requiredAcksOpt = new Option(null, 'required_acks', Getopt::REQUIRED_ARGUMENT);
$requiredAcksOpt->setDescription('Required ack number');
$requiredAcksOpt->setDefaultValue(1);
$requiredAcksOpt->setValidation(function ($value) {
return is_numeric($value);
});
$compression_codecOpt = new Option(null, 'compression_codec', Getopt::REQUIRED_ARGUMENT);
$compression_codecOpt->setDescription("Optional compression method of messages: " . implode(", ", AdminUtils::$COMPRESSION_CODECS));
$compression_codecOpt->setDefaultValue('none');
$compression_codecOpt->setValidation(function ($value) {
return AdminUtils::isCompressionCodecValid($value);
});
$batchsizeOpt = new Option(null, 'batchsize', Getopt::REQUIRED_ARGUMENT);
$batchsizeOpt->setDescription('The batch size of messages to be sent');
$batchsizeOpt->setDefaultValue(1000);
$batchsizeOpt->setValidation(function ($value) {
return is_numeric($value) && $value > 0;
});
$follow_lastOpt = new Option(null, 'follow_last', Getopt::REQUIRED_ARGUMENT);
$follow_lastOpt->setDescription('If set to "false", when restarting logkafka process,
the log_path formatted with current time will be collect;
If set to "true", when restarting logkafka process, the last
collecting file will be collected continually');
$follow_lastOpt->setDefaultValue('true');
$follow_lastOpt->setValidation(function ($value) {
return in_array($value, array('true', 'false'));
});
$message_timeout_msOpt = new Option(null, 'message_timeout_ms', Getopt::REQUIRED_ARGUMENT);
$message_timeout_msOpt->setDescription('Local message timeout. This value is only enforced locally
and limits the time a produced message waits for successful delivery.
A time of 0 is infinite.');
$message_timeout_msOpt->setDefaultValue(0);
$message_timeout_msOpt->setValidation(function ($value) {
return is_numeric($value) && $value >= 0;
});
$validOpt = new Option(null, 'valid', Getopt::REQUIRED_ARGUMENT);
$validOpt->setDescription('Enable now or not');
$validOpt->setDefaultValue('true');
$validOpt->setValidation(function ($value) {
return in_array($value, array('true', 'false'));
});
$parser = new Getopt(array($zookeeperOpt, $createOpt, $deleteOpt, $listOpt, $hostnameOpt, $log_pathOpt, $topicOpt, $partitionOpt, $keyOpt, $requiredAcksOpt, $compression_codecOpt, $batchsizeOpt, $follow_lastOpt, $message_timeout_msOpt, $validOpt));
try {
$parser->parse();
// Error handling and --help functionality omitted for brevity
$listOptVal = 0;
$createOptVal = 0;
$deleteOptVal = 0;
if ($parser["list"]) {
$listOptVal = 1;
}
if ($parser["create"]) {
$createOptVal = 1;
}
if ($parser["delete"]) {
$deleteOptVal = 1;
}
} catch (UnexpectedValueException $e) {
echo "Error: " . $e->getMessage() . "\n";
echo $parser->getHelpText();
//.........这里部分代码省略.........