FluentDOM\Loader\JSONx::load PHP Method

load() public method

See also: Loadable::load
public load ( string $source, string $contentType, array | Traversable | Options $options = [] ) : Document | Result | null
$source string
$contentType string
$options array | Traversable | Options
return FluentDOM\Document | Result | null
    public function load($source, $contentType, $options = [])
    {
        if ($this->supports($contentType) && !empty($source)) {
            $dom = new Document();
            $dom->preserveWhiteSpace = FALSE;
            $dom->registerNamespace('jx', self::XMLNS_JSONX);
            if ($this->startsWith($source, '<')) {
                $dom->loadXML($source);
            } else {
                $dom->load($source);
            }
            $target = new Document();
            $target->registerNamespace('json', self::XMLNS_JSONDOM);
            if (isset($dom->documentElement)) {
                $this->transferNode($dom->documentElement, $target);
            }
            return $target;
        }
        return NULL;
    }