You are here

public function DOMTreeBuilder::__construct in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php \Masterminds\HTML5\Parser\DOMTreeBuilder::__construct()

File

vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php, line 162

Class

DOMTreeBuilder
Create an HTML5 DOM tree from events.

Namespace

Masterminds\HTML5\Parser

Code

public function __construct($isFragment = false, array $options = array()) {
  $this->options = $options;
  if (isset($options[self::OPT_TARGET_DOC])) {
    $this->doc = $options[self::OPT_TARGET_DOC];
  }
  else {
    $impl = new \DOMImplementation();

    // XXX:
    // Create the doctype. For now, we are always creating HTML5
    // documents, and attempting to up-convert any older DTDs to HTML5.
    $dt = $impl
      ->createDocumentType('html');

    // $this->doc = \DOMImplementation::createDocument(NULL, 'html', $dt);
    $this->doc = $impl
      ->createDocument(null, null, $dt);
  }
  $this->errors = array();
  $this->current = $this->doc;

  // ->documentElement;
  // 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, $implicitNS + array(
    '' => self::NAMESPACE_HTML,
  ) + $this->implicitNamespaces);
  if ($isFragment) {
    $this->insertMode = static::IM_IN_BODY;
    $this->frag = $this->doc
      ->createDocumentFragment();
    $this->current = $this->frag;
  }
}