HTMLPurifier_HTMLModule::parseContents PHP Method

parseContents() public method

Convenience function that transforms single-string contents into separate content model and content model type
public parseContents ( string $contents ) : array
$contents string Allowed children in form of: "$content_model_type: $content_model"
return array
    public function parseContents($contents)
    {
        if (!is_string($contents)) {
            return array(null, null);
        }
        // defer
        switch ($contents) {
            // check for shorthand content model forms
            case 'Empty':
                return array('empty', '');
            case 'Inline':
                return array('optional', 'Inline | #PCDATA');
            case 'Flow':
                return array('optional', 'Flow | #PCDATA');
        }
        list($content_model_type, $content_model) = explode(':', $contents);
        $content_model_type = strtolower(trim($content_model_type));
        $content_model = trim($content_model);
        return array($content_model_type, $content_model);
    }

Usage Example

示例#1
0
 public function test_parseContents()
 {
     $module = new HTMLPurifier_HTMLModule();
     // pre-defined templates
     $this->assertIdentical($module->parseContents('Inline'), array('optional', 'Inline | #PCDATA'));
     $this->assertIdentical($module->parseContents('Flow'), array('optional', 'Flow | #PCDATA'));
     $this->assertIdentical($module->parseContents('Empty'), array('empty', ''));
     // normalization procedures
     $this->assertIdentical($module->parseContents('optional: a'), array('optional', 'a'));
     $this->assertIdentical($module->parseContents('OPTIONAL :a'), array('optional', 'a'));
     $this->assertIdentical($module->parseContents('Optional: a'), array('optional', 'a'));
     // others
     $this->assertIdentical($module->parseContents('Optional: a | b | c'), array('optional', 'a | b | c'));
     // object pass-through
     generate_mock_once('HTMLPurifier_AttrDef');
     $this->assertIdentical($module->parseContents(new HTMLPurifier_AttrDefMock()), array(null, null));
 }