Jackalope\ImportExport\ImportExport::importSystemView PHP Method

importSystemView() private static method

Import document in system view
private static importSystemView ( PHPCR\NodeInterface $parentNode, PHPCR\NamespaceRegistryInterface $ns, FilteredXMLReader $xml, integer $uuidBehavior, array $namespaceMap = [] )
$parentNode PHPCR\NodeInterface
$ns PHPCR\NamespaceRegistryInterface
$xml FilteredXMLReader
$uuidBehavior integer
$namespaceMap array hashmap of prefix => uri for namespaces in the document
    private static function importSystemView(NodeInterface $parentNode, NamespaceRegistryInterface $ns, FilteredXMLReader $xml, $uuidBehavior, array $namespaceMap = array())
    {
        while ($xml->moveToNextAttribute()) {
            if ('xmlns' === $xml->prefix) {
                try {
                    $prefix = $ns->getPrefix($xml->value);
                } catch (NamespaceException $e) {
                    $prefix = $xml->localName;
                    $ns->registerNamespace($prefix, $xml->value);
                }
                // @codeCoverageIgnoreStart
                if ('jcr' === $prefix && 'jcr' !== $xml->localName) {
                    throw new RepositoryException('Can not handle a document where the {http://www.jcp.org/jcr/1.0} namespace is not mapped to jcr');
                }
                if ('nt' === $prefix && 'nt' !== $xml->localName) {
                    throw new RepositoryException('Can not handle a document where the {http://www.jcp.org/jcr/nt/1.0} namespace is not mapped to nt');
                }
                // @codeCoverageIgnoreEnd
                $namespaceMap[$xml->localName] = $prefix;
            } elseif (NamespaceRegistryInterface::NAMESPACE_SV === $xml->namespaceURI && 'name' === $xml->localName) {
                $nodename = $xml->value;
            }
        }
        if (!isset($nodename)) {
            throw new InvalidSerializedDataException('there was no sv:name attribute in an element');
        }
        // now get jcr:primaryType
        if (!$xml->read()) {
            throw new InvalidSerializedDataException('missing information to create node');
        }
        if ('property' !== $xml->localName || NamespaceRegistryInterface::NAMESPACE_SV !== $xml->namespaceURI) {
            throw new InvalidSerializedDataException('first child of node must be sv:property for jcr:primaryType. Found {' . $xml->namespaceURI . '}' . $xml->localName . '="' . $xml->value . '"' . $xml->nodeType);
        }
        if (!$xml->moveToAttributeNs('name', NamespaceRegistryInterface::NAMESPACE_SV)) {
            throw new InvalidSerializedDataException('first child of node must have a sv:name property');
        }
        if ('jcr:primaryType' !== $xml->value) {
            throw new InvalidSerializedDataException('first child of node must be the sv:property node with a jcr:primaryType. Found {' . $xml->namespaceURI . '}' . $xml->localName . '="' . $xml->value);
        }
        $xml->read();
        // value child of property jcr:primaryType
        $xml->read();
        // text content
        $nodetype = $xml->value;
        $nodename = self::cleanNamespace($nodename, $namespaceMap);
        $properties = array();
        $xml->read();
        // </value>
        $xml->read();
        // </property>
        $xml->read();
        // next thing
        // read the properties of the node. they must come first.
        while (XMLReader::END_ELEMENT !== $xml->nodeType && 'property' === $xml->localName) {
            $xml->moveToAttributeNs('name', NamespaceRegistryInterface::NAMESPACE_SV);
            $name = $xml->value;
            $xml->moveToAttributeNs('type', NamespaceRegistryInterface::NAMESPACE_SV);
            $type = PropertyType::valueFromName($xml->value);
            if ($xml->moveToAttributeNs('multiple', NamespaceRegistryInterface::NAMESPACE_SV)) {
                $multiple = strcasecmp($xml->value, 'true') === 0;
            } else {
                $multiple = false;
            }
            $values = array();
            // go to the value child. if empty property, brings us to closing
            // property tag. if self-closing, brings us to the next property or
            // node closing tag
            $xml->read();
            while ('value' === $xml->localName) {
                if ($xml->isEmptyElement) {
                    $values[] = '';
                } else {
                    $xml->read();
                    if (XMLReader::END_ELEMENT === $xml->nodeType) {
                        // this is an empty tag
                        $values[] = '';
                    } else {
                        $values[] = PropertyType::BINARY === $type ? base64_decode($xml->value) : $xml->value;
                        $xml->read();
                        // consume the content
                    }
                }
                $xml->read();
                // consume closing tag
            }
            if (!$multiple && count($values) === 1) {
                $values = reset($values);
                // unbox if it does not need to be multivalue
            }
            $name = self::cleanNamespace($name, $namespaceMap);
            $properties[$name] = array('values' => $values, 'type' => $type);
            /* only consume closing property, but not the next element if we
             * had an empty multiple property with no value children at all
             * and don't consume the closing node tag after a self-closing
             * empty property
             */
            if (XMLReader::END_ELEMENT === $xml->nodeType && 'property' === $xml->localName) {
                $xml->read();
            }
        }
        $node = self::addNode($parentNode, $nodename, $nodetype, $properties, $uuidBehavior);
        // if there are child nodes, they all come after the properties
        while (XMLReader::END_ELEMENT !== $xml->nodeType && 'node' === $xml->localName) {
            self::importSystemView($node, $ns, $xml, $uuidBehavior, $namespaceMap);
        }
        if (XMLReader::END_ELEMENT !== $xml->nodeType) {
            throw new InvalidSerializedDataException('Unexpected element "' . $xml->localName . '" type "' . $xml->nodeType . '" with content "' . $xml->value . '" after ' . $node->getPath());
        }
        $xml->read();
        // </node>
    }