Jackalope\ImportExport\ImportExport::exportSystemViewRecursive PHP Method

exportSystemViewRecursive() private static method

Recursively output node and all its children into the file in the system view format
private static exportSystemViewRecursive ( PHPCR\NodeInterface $node, PHPCR\NamespaceRegistryInterface $ns, resource $stream, boolean $skipBinary, boolean $noRecurse, boolean $root = false )
$node PHPCR\NodeInterface the node to output
$ns PHPCR\NamespaceRegistryInterface
$stream resource The stream resource (i.e. acquired with fopen) to which the XML serialization of the subgraph will be output. Must support the fwrite method.
$skipBinary boolean A boolean governing whether binary properties are to be serialized.
$noRecurse boolean A boolean governing whether the subgraph at absPath is to be recursed.
$root boolean Whether this is the root node of the resulting document, meaning the namespace declarations have to be included in it.
    private static function exportSystemViewRecursive(NodeInterface $node, NamespaceRegistryInterface $ns, $stream, $skipBinary, $noRecurse, $root = false)
    {
        fwrite($stream, '<sv:node');
        if ($root) {
            self::exportNamespaceDeclarations($ns, $stream);
        }
        fwrite($stream, ' sv:name="' . (0 === $node->getDepth() ? 'jcr:root' : htmlspecialchars($node->getName())) . '">');
        // the order MUST be primary type, then mixins, if any, then jcr:uuid if its a referenceable node
        fwrite($stream, '<sv:property sv:name="jcr:primaryType" sv:type="Name"><sv:value>' . htmlspecialchars($node->getPropertyValue('jcr:primaryType')) . '</sv:value></sv:property>');
        if ($node->hasProperty('jcr:mixinTypes')) {
            fwrite($stream, '<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">');
            foreach ($node->getPropertyValue('jcr:mixinTypes') as $type) {
                fwrite($stream, '<sv:value>' . htmlspecialchars($type) . '</sv:value>');
            }
            fwrite($stream, '</sv:property>');
        }
        if ($node->isNodeType('mix:referenceable')) {
            fwrite($stream, '<sv:property sv:name="jcr:uuid" sv:type="String"><sv:value>' . $node->getIdentifier() . '</sv:value></sv:property>');
        }
        foreach ($node->getProperties() as $name => $property) {
            /** @var $property PropertyInterface */
            if (in_array($name, array('jcr:primaryType', 'jcr:mixinTypes', 'jcr:uuid'), true)) {
                // explicitly handled before
                continue;
            }
            if ($skipBinary && PropertyType::BINARY === $property->getType()) {
                // do not output binary data in the xml
                continue;
            }
            fwrite($stream, '<sv:property sv:name="' . htmlentities($name) . '" sv:type="' . PropertyType::nameFromValue($property->getType()) . '"' . ($property->isMultiple() ? ' sv:multiple="true"' : '') . '>');
            $values = $property->isMultiple() ? $property->getString() : array($property->getString());
            foreach ($values as $value) {
                if (PropertyType::BINARY === $property->getType()) {
                    $val = base64_encode($value);
                } else {
                    $val = htmlspecialchars($value);
                    //TODO: can we still have invalid characters after this? if so base64 and property, xsi:type="xsd:base64Binary"
                }
                fwrite($stream, "<sv:value>{$val}</sv:value>");
            }
            fwrite($stream, "</sv:property>");
        }
        if (!$noRecurse) {
            foreach ($node as $child) {
                if (!($child->getDepth() === 1 && NodeHelper::isSystemItem($child))) {
                    self::exportSystemViewRecursive($child, $ns, $stream, $skipBinary, $noRecurse);
                }
            }
        }
        fwrite($stream, '</sv:node>');
    }