本文整理汇总了PHP中ResourceLoader::isValidModuleName方法的典型用法代码示例。如果您正苦于以下问题:PHP ResourceLoader::isValidModuleName方法的具体用法?PHP ResourceLoader::isValidModuleName怎么用?PHP ResourceLoader::isValidModuleName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourceLoader
的用法示例。
在下文中一共展示了ResourceLoader::isValidModuleName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newFromDefinition
/**
* Creates an instance of this class from definition in MediaWiki:Gadgets-definition
* @param $definition String: Gadget definition
* @return Gadget|bool Instance of Gadget class or false if $definition is invalid
*/
public static function newFromDefinition($definition)
{
$m = array();
if (!preg_match('/^\\*+ *([a-zA-Z](?:[-_:.\\w\\d ]*[a-zA-Z0-9])?)(\\s*\\[.*?\\])?\\s*((\\|[^|]*)+)\\s*$/', $definition, $m)) {
return false;
}
// NOTE: the gadget name is used as part of the name of a form field,
// and must follow the rules defined in http://www.w3.org/TR/html4/types.html#type-cdata
// Also, title-normalization applies.
$gadget = new Gadget();
$gadget->name = trim(str_replace(' ', '_', $m[1]));
// If the name is too long, then RL will throw an MWException when
// we try to register the module
if (!ResourceLoader::isValidModuleName($gadget->getModuleName())) {
return false;
}
$gadget->definition = $definition;
$options = trim($m[2], ' []');
foreach (preg_split('/\\s*\\|\\s*/', $options, -1, PREG_SPLIT_NO_EMPTY) as $option) {
$arr = preg_split('/\\s*=\\s*/', $option, 2);
$option = $arr[0];
if (isset($arr[1])) {
$params = explode(',', $arr[1]);
$params = array_map('trim', $params);
} else {
$params = array();
}
switch ($option) {
case 'ResourceLoader':
$gadget->resourceLoaded = true;
break;
case 'dependencies':
$gadget->dependencies = $params;
break;
case 'rights':
$gadget->requiredRights = $params;
break;
case 'skins':
$gadget->requiredSkins = $params;
break;
case 'default':
$gadget->onByDefault = true;
break;
case 'targets':
$gadget->targets = $params;
break;
case 'top':
$gadget->position = 'top';
break;
}
}
foreach (preg_split('/\\s*\\|\\s*/', $m[3], -1, PREG_SPLIT_NO_EMPTY) as $page) {
$page = "Gadget-{$page}";
if (preg_match('/\\.js/', $page)) {
$gadget->scripts[] = $page;
} elseif (preg_match('/\\.css/', $page)) {
$gadget->styles[] = $page;
}
}
return $gadget;
}
示例2: isValidGadgetID
/**
* Whether the provided gadget id is valid
*
* @param string $id
* @return bool
*/
public static function isValidGadgetID($id)
{
return strlen($id) > 0 && ResourceLoader::isValidModuleName("ext.gadget.{$id}");
}