public function create($config, $context, $code = false)
    {
        // validate language code
        if ($code === false) {
            $code = $this->validator->validate(
                $config->get('Core.Language'),
                $config,
                $context
            );
        } else {
            $code = $this->validator->validate($code, $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') {
            $lang = new HTMLPurifier_Language($config, $context);
        } else {
            $class = 'HTMLPurifier_Language_' . $pcode;
            $file  = $this->dir . '/Language/classes/' . $code . '.php';
            if (file_exists($file) || class_exists($class, false)) {
                $lang = new $class($config, $context);
            } else {
                // Go fallback
                $raw_fallback = $this->getFallbackFor($code);
                $fallback = $raw_fallback ? $raw_fallback : 'en';
                $depth++;
                $lang = $this->create($config, $context, $fallback);
                if (!$raw_fallback) {
                    $lang->error = true;
                }
                $depth--;
            }
        }
        $lang->code = $code;
        return $lang;
    }
public function create($config, $context, $code = false)
    {
        // validate language code
        if ($code === false) {
            $code = $this->validator->validate(
                $config->get('Core.Language'),
                $config,
                $context
            );
        } else {
            $code = $this->validator->validate($code, $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') {
            $lang = new HTMLPurifier_Language($config, $context);
        } else {
            $class = 'HTMLPurifier_Language_' . $pcode;
            $file  = $this->dir . '/Language/classes/' . $code . '.php';
            if (file_exists($file) || class_exists($class, false)) {
                $lang = new $class($config, $context);
            } else {
                // Go fallback
                $raw_fallback = $this->getFallbackFor($code);
                $fallback = $raw_fallback ? $raw_fallback : 'en';
                $depth++;
                $lang = $this->create($config, $context, $fallback);
                if (!$raw_fallback) {
                    $lang->error = true;
                }
                $depth--;
            }
        }
        $lang->code = $code;
        return $lang;
    }
public function create ( $ config , $ context , $ code = false ) { // validate language code if ( $ code === false ) { $ code = $ this -> validator -> validate ( $ config -> get ( 'Core.Language' ) , $ config , $ context ) ; } else { $ code = $ this -> validator -> validate ( $ code , $ 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' ) { $ lang = new HTMLPurifier_Language ( $ config , $ context ) ; } else { $ class = 'HTMLPurifier_Language_' . $ pcode ; $ file = $ this -> dir . '/Language/classes/' . $ code . '.php' ; if ( file_exists ( $ file ) || class_exists ( $ class , false ) ) { $ lang = new $ class ( $ config , $ context ) ; } else { // Go fallback $ raw_fallback = $ this -> getFallbackFor ( $ code ) ; $ fallback = $ raw_fallback ? $ raw_fallback : 'en' ; $ depth ++ ; $ lang = $ this -> create ( $ config , $ context , $ fallback ) ; if ( ! $ raw_fallback ) { $ lang -> error = true ; } $ depth -- ; } } $ lang -> code = $ code ; return $ lang ; }
Creates a language object, handles class fallbacks
@param HTMLPurifier_Config $config
@param HTMLPurifier_Context $context
@param bool|string $code Code to override configuration with. Private parameter.
@return HTMLPurifier_Language
Creates a language object handles class fallbacks