本文整理汇总了PHP中HTMLPurifier_LanguageFactory::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP HTMLPurifier_LanguageFactory::factory方法的具体用法?PHP HTMLPurifier_LanguageFactory::factory怎么用?PHP HTMLPurifier_LanguageFactory::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLPurifier_LanguageFactory
的用法示例。
在下文中一共展示了HTMLPurifier_LanguageFactory::factory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Creates a language object, handles class fallbacks
* @param $config Instance of HTMLPurifier_Config
* @param $context Instance of HTMLPurifier_Context
*/
function create($config, &$context)
{
// validate language code
$code = $this->validator->validate($config->get('Core', 'Language'), $config, $context);
if ($code === false) {
$code = 'en';
}
// malformed code becomes English
$pcode = str_replace('-', '_', $code);
// make valid PHP classname
static $depth = 0;
// recursion protection
if ($code == 'en') {
$class = 'HTMLPurifier_Language';
$file = $this->dir . '/Language.php';
} else {
$class = 'HTMLPurifier_Language_' . $pcode;
$file = $this->dir . '/Language/classes/' . $code . '.php';
// PHP5/APC deps bug workaround can go here
// you can bypass the conditional include by loading the
// file yourself
if (file_exists($file) && !class_exists($class)) {
include_once $file;
}
}
if (!class_exists($class)) {
// go fallback
$fallback = HTMLPurifier_LanguageFactory::getFallbackFor($code);
$depth++;
$lang = HTMLPurifier_LanguageFactory::factory($fallback);
$depth--;
} else {
$lang = new $class($config, $context);
}
$lang->code = $code;
return $lang;
}