当前位置: 首页>>代码示例>>PHP>>正文


PHP ApiBase::getValidNamespaces方法代码示例

本文整理汇总了PHP中ApiBase::getValidNamespaces方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiBase::getValidNamespaces方法的具体用法?PHP ApiBase::getValidNamespaces怎么用?PHP ApiBase::getValidNamespaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApiBase的用法示例。


在下文中一共展示了ApiBase::getValidNamespaces方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getParameterFromSettings

 /**
  * Using the settings determine the value for the given parameter
  *
  * @param $paramName String: parameter name
  * @param $paramSettings Mixed: default value or an array of settings
  *  using PARAM_* constants.
  * @param $parseLimit Boolean: parse limit?
  * @return mixed Parameter value
  */
 protected function getParameterFromSettings($paramName, $paramSettings, $parseLimit)
 {
     // Some classes may decide to change parameter names
     $encParamName = $this->encodeParamName($paramName);
     if (!is_array($paramSettings)) {
         $default = $paramSettings;
         $multi = false;
         $type = gettype($paramSettings);
         $dupes = false;
         $deprecated = false;
     } else {
         $default = isset($paramSettings[self::PARAM_DFLT]) ? $paramSettings[self::PARAM_DFLT] : null;
         $multi = isset($paramSettings[self::PARAM_ISMULTI]) ? $paramSettings[self::PARAM_ISMULTI] : false;
         $type = isset($paramSettings[self::PARAM_TYPE]) ? $paramSettings[self::PARAM_TYPE] : null;
         $dupes = isset($paramSettings[self::PARAM_ALLOW_DUPLICATES]) ? $paramSettings[self::PARAM_ALLOW_DUPLICATES] : false;
         $deprecated = isset($paramSettings[self::PARAM_DEPRECATED]) ? $paramSettings[self::PARAM_DEPRECATED] : false;
         // When type is not given, and no choices, the type is the same as $default
         if (!isset($type)) {
             if (isset($default)) {
                 $type = gettype($default);
             } else {
                 $type = 'NULL';
                 // allow everything
             }
         }
     }
     if ($type == 'boolean') {
         if (isset($default) && $default !== false) {
             // Having a default value of anything other than 'false' is pointless
             ApiBase::dieDebug(__METHOD__, "Boolean param {$encParamName}'s default is set to '{$default}'");
         }
         $value = $this->getMain()->getRequest()->getCheck($encParamName);
     } else {
         $value = $this->getMain()->getRequest()->getVal($encParamName, $default);
         if (isset($value) && $type == 'namespace') {
             $type = ApiBase::getValidNamespaces();
         }
     }
     if (isset($value) && ($multi || is_array($type))) {
         $value = $this->parseMultiValue($encParamName, $value, $multi, is_array($type) ? $type : null);
     }
     // More validation only when choices were not given
     // choices were validated in parseMultiValue()
     if (isset($value)) {
         if (!is_array($type)) {
             switch ($type) {
                 case 'NULL':
                     // nothing to do
                     break;
                 case 'string':
                     // nothing to do
                     break;
                 case 'integer':
                     // Force everything using intval() and optionally validate limits
                     $value = is_array($value) ? array_map('intval', $value) : intval($value);
                     $min = isset($paramSettings[self::PARAM_MIN]) ? $paramSettings[self::PARAM_MIN] : null;
                     $max = isset($paramSettings[self::PARAM_MAX]) ? $paramSettings[self::PARAM_MAX] : null;
                     if (!is_null($min) || !is_null($max)) {
                         $values = is_array($value) ? $value : array($value);
                         foreach ($values as &$v) {
                             $this->validateLimit($paramName, $v, $min, $max);
                         }
                     }
                     break;
                 case 'limit':
                     if (!$parseLimit) {
                         // Don't do any validation whatsoever
                         break;
                     }
                     if (!isset($paramSettings[self::PARAM_MAX]) || !isset($paramSettings[self::PARAM_MAX2])) {
                         ApiBase::dieDebug(__METHOD__, "MAX1 or MAX2 are not defined for the limit {$encParamName}");
                     }
                     if ($multi) {
                         ApiBase::dieDebug(__METHOD__, "Multi-values not supported for {$encParamName}");
                     }
                     $min = isset($paramSettings[self::PARAM_MIN]) ? $paramSettings[self::PARAM_MIN] : 0;
                     if ($value == 'max') {
                         $value = $this->getMain()->canApiHighLimits() ? $paramSettings[self::PARAM_MAX2] : $paramSettings[self::PARAM_MAX];
                         $this->getResult()->addValue('limits', $this->getModuleName(), $value);
                     } else {
                         $value = intval($value);
                         $this->validateLimit($paramName, $value, $min, $paramSettings[self::PARAM_MAX], $paramSettings[self::PARAM_MAX2]);
                     }
                     break;
                 case 'boolean':
                     if ($multi) {
                         ApiBase::dieDebug(__METHOD__, "Multi-values not supported for {$encParamName}");
                     }
                     break;
                 case 'timestamp':
                     if ($multi) {
//.........这里部分代码省略.........
开发者ID:rocLv,项目名称:conference,代码行数:101,代码来源:ApiBase.php

示例2: getParameterFromSettings

 /**
  * Using the settings determine the value for the given parameter
  * @param $paramName String: parameter name
  * @param $paramSettings Mixed: default value or an array of settings using PARAM_* constants.
  */
 protected function getParameterFromSettings($paramName, $paramSettings)
 {
     // Some classes may decide to change parameter names
     $paramName = $this->encodeParamName($paramName);
     if (!is_array($paramSettings)) {
         $default = $paramSettings;
         $multi = false;
         $type = gettype($paramSettings);
     } else {
         $default = isset($paramSettings[self::PARAM_DFLT]) ? $paramSettings[self::PARAM_DFLT] : null;
         $multi = isset($paramSettings[self::PARAM_ISMULTI]) ? $paramSettings[self::PARAM_ISMULTI] : false;
         $type = isset($paramSettings[self::PARAM_TYPE]) ? $paramSettings[self::PARAM_TYPE] : null;
         // When type is not given, and no choices, the type is the same as $default
         if (!isset($type)) {
             if (isset($default)) {
                 $type = gettype($default);
             } else {
                 $type = 'NULL';
             }
             // allow everything
         }
     }
     if ($type == 'boolean') {
         if (isset($default) && $default !== false) {
             // Having a default value of anything other than 'false' is pointless
             ApiBase::dieDebug(__METHOD__, "Boolean param {$paramName}'s default is set to '{$default}'");
         }
         $value = $this->getMain()->getRequest()->getCheck($paramName);
     } else {
         $value = $this->getMain()->getRequest()->getVal($paramName, $default);
         if (isset($value) && $type == 'namespace') {
             $type = ApiBase::getValidNamespaces();
         }
     }
     if (isset($value) && ($multi || is_array($type))) {
         $value = $this->parseMultiValue($paramName, $value, $multi, is_array($type) ? $type : null);
     }
     // More validation only when choices were not given
     // choices were validated in parseMultiValue()
     if (isset($value)) {
         if (!is_array($type)) {
             switch ($type) {
                 case 'NULL':
                     // nothing to do
                     break;
                 case 'string':
                     // nothing to do
                     break;
                 case 'integer':
                     // Force everything using intval()
                     $value = is_array($value) ? array_map('intval', $value) : intval($value);
                     break;
                 case 'limit':
                     if (!isset($paramSettings[self::PARAM_MAX1]) || !isset($paramSettings[self::PARAM_MAX2])) {
                         ApiBase::dieDebug(__METHOD__, "MAX1 or MAX2 are not defined for the limit {$paramName}");
                     }
                     if ($multi) {
                         ApiBase::dieDebug(__METHOD__, "Multi-values not supported for {$paramName}");
                     }
                     $min = isset($paramSettings[self::PARAM_MIN]) ? $paramSettings[self::PARAM_MIN] : 0;
                     $value = intval($value);
                     $this->validateLimit($paramName, $value, $min, $paramSettings[self::PARAM_MAX1], $paramSettings[self::PARAM_MAX2]);
                     break;
                 case 'boolean':
                     if ($multi) {
                         ApiBase::dieDebug(__METHOD__, "Multi-values not supported for {$paramName}");
                     }
                     break;
                 case 'timestamp':
                     if ($multi) {
                         ApiBase::dieDebug(__METHOD__, "Multi-values not supported for {$paramName}");
                     }
                     $value = wfTimestamp(TS_UNIX, $value);
                     if ($value === 0) {
                         $this->dieUsage("Invalid value '{$value}' for timestamp parameter {$paramName}", "badtimestamp_{$paramName}");
                     }
                     $value = wfTimestamp(TS_MW, $value);
                     break;
                 default:
                     ApiBase::dieDebug(__METHOD__, "Param {$paramName}'s type is unknown - {$type}");
             }
         }
         // There should never be any duplicate values in a list
         if (is_array($value)) {
             $value = array_unique($value);
         }
     }
     return $value;
 }
开发者ID:negabaro,项目名称:alfresco,代码行数:94,代码来源:ApiBase.php


注:本文中的ApiBase::getValidNamespaces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。