本文整理汇总了PHP中ApiMain::canApiHighLimits方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiMain::canApiHighLimits方法的具体用法?PHP ApiMain::canApiHighLimits怎么用?PHP ApiMain::canApiHighLimits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiMain
的用法示例。
在下文中一共展示了ApiMain::canApiHighLimits方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseMultiValue
/**
* Return an array of values that were given in a 'a|b|c' notation,
* after it optionally validates them against the list allowed values.
*
* @param string $valueName The name of the parameter (for error
* reporting)
* @param mixed $value The value being parsed
* @param bool $allowMultiple Can $value contain more than one value
* separated by '|'?
* @param string[]|null $allowedValues An array of values to check against. If
* null, all values are accepted.
* @return string|string[] (allowMultiple ? an_array_of_values : a_single_value)
*/
protected function parseMultiValue($valueName, $value, $allowMultiple, $allowedValues)
{
if (trim($value) === '' && $allowMultiple) {
return array();
}
// This is a bit awkward, but we want to avoid calling canApiHighLimits()
// because it unstubs $wgUser
$valuesList = explode('|', $value, self::LIMIT_SML2 + 1);
$sizeLimit = count($valuesList) > self::LIMIT_SML1 && $this->mMainModule->canApiHighLimits() ? self::LIMIT_SML2 : self::LIMIT_SML1;
if (self::truncateArray($valuesList, $sizeLimit)) {
$this->setWarning("Too many values supplied for parameter '{$valueName}': " . "the limit is {$sizeLimit}");
}
if (!$allowMultiple && count($valuesList) != 1) {
// Bug 33482 - Allow entries with | in them for non-multiple values
if (in_array($value, $allowedValues, true)) {
return $value;
}
$possibleValues = is_array($allowedValues) ? "of '" . implode("', '", $allowedValues) . "'" : '';
$this->dieUsage("Only one {$possibleValues} is allowed for parameter '{$valueName}'", "multival_{$valueName}");
}
if (is_array($allowedValues)) {
// Check for unknown values
$unknown = array_diff($valuesList, $allowedValues);
if (count($unknown)) {
if ($allowMultiple) {
$s = count($unknown) > 1 ? 's' : '';
$vals = implode(", ", $unknown);
$this->setWarning("Unrecognized value{$s} for parameter '{$valueName}': {$vals}");
} else {
$this->dieUsage("Unrecognized value for parameter '{$valueName}': {$valuesList[0]}", "unknown_{$valueName}");
}
}
// Now throw them out
$valuesList = array_intersect($valuesList, $allowedValues);
}
return $allowMultiple ? $valuesList : $valuesList[0];
}