Beispiel #1
0
 /**
  * @see Loadable::loadFragment
  *
  * @param string $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return DocumentFragment|NULL
  */
 public function loadFragment($source, $contentType, $options = [])
 {
     if (FALSE !== ($json = $this->getJson($source, $contentType))) {
         $document = new Document('1.0', 'UTF-8');
         $fragment = $document->createDocumentFragment();
         $this->transferTo($fragment, $json);
         return $fragment;
     }
     return NULL;
 }
Beispiel #2
0
 /**
  * @see LoadableFragment::loadFragment
  * @param string $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return DocumentFragment|NULL
  */
 public function loadFragment($source, $contentType, $options = [])
 {
     if ($this->supports($contentType)) {
         $dom = new Document();
         $fragment = $dom->createDocumentFragment();
         $fragment->appendXml($source);
         return $fragment;
     }
     return NULL;
 }
Beispiel #3
0
 /**
  * @see Loadable::loadFragment
  *
  * @param string $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return DocumentFragment|NULL
  */
 public function loadFragment($source, $contentType, $options = [])
 {
     $hasHeaderLine = isset($options['FIELDS']) ? FALSE : isset($options['HEADER']) && $options['HEADER'];
     $this->configure($options);
     if ($this->supports($contentType) && ($lines = $this->getLines($source))) {
         $document = new Document('1.0', 'UTF-8');
         $fragment = $document->createDocumentFragment();
         $this->appendLines($fragment, $lines, $hasHeaderLine, isset($options['FIELDS']) ? $options['FIELDS'] : NULL);
         return $fragment;
     }
     return NULL;
 }
Beispiel #4
0
 /**
  * @see Loadable::loadFragment
  *
  * @param string $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return DocumentFragment|NULL
  */
 public function loadFragment($source, $contentType, $options = [])
 {
     if ($this->supports($contentType) && !empty($source)) {
         $document = new Document();
         $document->preserveWhiteSpace = FALSE;
         $document->registerNamespace('jx', self::XMLNS_JSONX);
         $sourceFragment = $document->createDocumentFragment();
         $sourceFragment->appendXml($source);
         $target = new Document();
         $target->registerNamespace('json', self::XMLNS_JSONDOM);
         $targetFragment = $target->createDocumentFragment();
         foreach ($sourceFragment->childNodes as $node) {
             $this->transferNode($node, $targetFragment);
         }
         return $targetFragment;
     }
     return NULL;
 }
Beispiel #5
0
 /**
  * @see LoadableFragment::loadFragment
  * @param string $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return DocumentFragment|NULL
  */
 public function loadFragment($source, $contentType, $options = [])
 {
     if ($this->supports($contentType)) {
         $options = $this->getOptions($options);
         $loadOptions = (int) $options[self::LIBXML_OPTIONS];
         return $this->captureLibxmlErrors(function () use($source, $loadOptions) {
             $document = new Document();
             $fragment = $document->createDocumentFragment();
             $document->loadHTML('<html-fragment>' . $source . '</html-fragment>', $loadOptions);
             $nodes = $document->evaluate('//html-fragment[1]/node()');
             foreach ($nodes as $node) {
                 $fragment->append($node);
             }
             return $fragment;
         });
     }
     return NULL;
 }
Beispiel #6
0
 /**
  * @param string $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return \FluentDOM\DocumentFragment|null
  */
 public function loadFragment($source, $contentType, $options = [])
 {
     if ($this->supports($contentType)) {
         $dom = new Document('1.0', 'UTF-8');
         $fragment = $dom->createDocumentFragment();
         $onMapKey = $this->_onMapKey;
         if (isset($options[self::ON_MAP_KEY]) && is_callable($options[self::ON_MAP_KEY])) {
             $this->onMapKey($options[self::ON_MAP_KEY]);
         }
         $this->transferTo($fragment, json_decode($source), $this->_recursions);
         $this->_onMapKey = $onMapKey;
         return $fragment;
     }
     return NULL;
 }