diff options
author | Asmir Mustafic <[email protected]> | 2015-02-06 21:45:13 +0100 |
---|---|---|
committer | Asmir Mustafic <[email protected]> | 2015-02-06 22:07:21 +0100 |
commit | 23a692b708ed24f69480aaa59a9dfbb3e9a606d2 (patch) | |
tree | a831eafccef7d571ff4245fda08bf9b5308c7e8b | |
parent | ed7cc5f4e06eed696cdd829a3197fbe8927c0721 (diff) |
Using constant as options
-rw-r--r-- | src/HTML5/Parser/DOMTreeBuilder.php | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/HTML5/Parser/DOMTreeBuilder.php b/src/HTML5/Parser/DOMTreeBuilder.php index da3f06b..ccad229 100644 --- a/src/HTML5/Parser/DOMTreeBuilder.php +++ b/src/HTML5/Parser/DOMTreeBuilder.php @@ -38,6 +38,12 @@ class DOMTreeBuilder implements EventHandler const NAMESPACE_XMLNS = 'http://www.w3.org/2000/xmlns/'; + const OPT_DISABLE_HTML_NS = 'disable_html_ns'; + + const OPT_TARGET_DOC = 'target_document'; + + const OPT_IMPLICIT_NS = 'implicit_namespaces'; + /** * Holds the HTML5 element names that causes a namespace switch * @@ -157,8 +163,8 @@ class DOMTreeBuilder implements EventHandler { $this->options = $options; - if (isset($options['targetDocument'])) { - $this->doc = $options['targetDocument']; + if (isset($options[self::OPT_TARGET_DOC])) { + $this->doc = $options[self::OPT_TARGET_DOC]; } else { $impl = new \DOMImplementation(); // XXX: @@ -175,8 +181,15 @@ class DOMTreeBuilder implements EventHandler // Create a rules engine for tags. $this->rules = new TreeBuildingRules($this->doc); + $implicitNS = array(); + if (isset($this->options[self::OPT_IMPLICIT_NS])) { + $implicitNS = $this->options[self::OPT_IMPLICIT_NS]; + } elseif (isset($this->options["implicitNamespaces"])) { + $implicitNS = $this->options["implicitNamespaces"]; + } + // Fill $nsStack with the defalut HTML5 namespaces, plus the "implicitNamespaces" array taken form $options - array_unshift($this->nsStack, (isset($this->options["implicitNamespaces"]) ? $this->options["implicitNamespaces"] : array()) + array( + array_unshift($this->nsStack, $implicitNS + array( '' => self::NAMESPACE_HTML ) + $this->implicitNamespaces); @@ -349,7 +362,7 @@ class DOMTreeBuilder implements EventHandler $ele = $this->doc->importNode($frag->documentElement, true); } else { - if (!isset($this->nsStack[0][$prefix]) || ($prefix === "" && isset($this->options['disableHtmlNsInDom']) && $this->options['disableHtmlNsInDom'])) { + if (!isset($this->nsStack[0][$prefix]) || ($prefix === "" && isset($this->options[self::OPT_DISABLE_HTML_NS]) && $this->options[self::OPT_DISABLE_HTML_NS])) { $ele = $this->doc->createElement($lname); } else { $ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname); |