HTMLPurifier_Config::create PHP Method

create() public static method

Convenience constructor that creates a config object based on a mixed var
public static create ( mixed $config, HTMLPurifier_ConfigSchema $schema = null ) : HTMLPurifier_Config
$config mixed Variable that defines the state of the config object. Can be: a HTMLPurifier_Config() object, an array of directives based on loadArray(), or a string filename of an ini file.
$schema HTMLPurifier_ConfigSchema Schema object
return HTMLPurifier_Config Configured object
    public static function create($config, $schema = null)
    {
        if ($config instanceof HTMLPurifier_Config) {
            // pass-through
            return $config;
        }
        if (!$schema) {
            $ret = HTMLPurifier_Config::createDefault();
        } else {
            $ret = new HTMLPurifier_Config($schema);
        }
        if (is_string($config)) {
            $ret->loadIni($config);
        } elseif (is_array($config)) {
            $ret->loadArray($config);
        }
        return $ret;
    }

Usage Example

 function testLineNumbers()
 {
     //       .  .     .     .  .     .     .           .      .             .
     //       01234567890123 01234567890123 0123456789012345 0123456789012   012345
     $html = "<b>Line 1</b>\n<i>Line 2</i>\nStill Line 2<br\n/>Now Line 4\n\n<br />";
     $expect = array(0 => new HTMLPurifier_Token_Start('b'), 1 => new HTMLPurifier_Token_Text('Line 1'), 2 => new HTMLPurifier_Token_End('b'), 3 => new HTMLPurifier_Token_Text("\n"), 4 => new HTMLPurifier_Token_Start('i'), 5 => new HTMLPurifier_Token_Text('Line 2'), 6 => new HTMLPurifier_Token_End('i'), 7 => new HTMLPurifier_Token_Text("\nStill Line 2"), 8 => new HTMLPurifier_Token_Empty('br'), 9 => new HTMLPurifier_Token_Text("Now Line 4\n\n"), 10 => new HTMLPurifier_Token_Empty('br'));
     $context = new HTMLPurifier_Context();
     $config = HTMLPurifier_Config::createDefault();
     $output = $this->DirectLex->tokenizeHTML($html, $config, $context);
     $this->assertIdentical($output, $expect);
     $context = new HTMLPurifier_Context();
     $config = HTMLPurifier_Config::create(array('Core.MaintainLineNumbers' => true));
     $expect[0]->position(1, 0);
     $expect[1]->position(1, 3);
     $expect[2]->position(1, 9);
     $expect[3]->position(2, -1);
     $expect[4]->position(2, 0);
     $expect[5]->position(2, 3);
     $expect[6]->position(2, 9);
     $expect[7]->position(3, -1);
     $expect[8]->position(3, 12);
     $expect[9]->position(4, 2);
     $expect[10]->position(6, 0);
     $output = $this->DirectLex->tokenizeHTML($html, $config, $context);
     $this->assertIdentical($output, $expect);
 }
All Usage Examples Of HTMLPurifier_Config::create