當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ApiMain::canApiHighLimits方法代碼示例

本文整理匯總了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];
 }
開發者ID:whysasse,項目名稱:kmwiki,代碼行數:50,代碼來源:ApiBase.php


注:本文中的ApiMain::canApiHighLimits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。