示例#1
0
 /**
  * Load a HTML5 file and copy it into a FluentDOM\Document
  *
  * @codeCoverageIgnore
  *
  * @see Loadable::load
  * @param string $source
  * @param string $contentType
  * @param array $options
  * @return Document|NULL
  */
 public function load($source, $contentType, array $options = [])
 {
     if ($this->supports($contentType)) {
         $html5 = new HTML5Support();
         if ($this->startsWith($source, '<')) {
             $dom = $html5->loadHTML($source);
         } else {
             $dom = $html5->loadHTMLFile($source);
         }
         if (!$dom instanceof Document) {
             $fd = new Document();
             if ($dom->documentElement instanceof \DOMElement) {
                 $fd->appendChild($fd->importNode($dom->documentElement, TRUE));
             }
             $dom = $fd;
         }
         $dom->registerNamespace('html', 'http://www.w3.org/1999/xhtml');
         return $dom;
     }
     return NULL;
 }