public function testIsNotMixin() { $this->assertFalse($this->versioned->isNodeType('mix:language')); }
/** * Set the mapped mixins. * * @param ClassMetadata $metadata * @param NodeInterface $node * @param object $document The document to update autogenerated fields. */ private function setMixins(Mapping\ClassMetadata $metadata, NodeInterface $node, $document) { $repository = $this->session->getRepository(); if ($metadata->versionable === 'full') { if ($repository->getDescriptor(RepositoryInterface::OPTION_VERSIONING_SUPPORTED)) { $node->addMixin('mix:versionable'); } elseif ($repository->getDescriptor(RepositoryInterface::OPTION_SIMPLE_VERSIONING_SUPPORTED)) { $node->addMixin('mix:simpleVersionable'); } } elseif ($metadata->versionable === 'simple' && $repository->getDescriptor(RepositoryInterface::OPTION_SIMPLE_VERSIONING_SUPPORTED)) { $node->addMixin('mix:simpleVersionable'); } if (!$node->isNodeType('mix:referenceable') && $metadata->referenceable) { $node->addMixin('mix:referenceable'); } // manually set the uuid if it is not present yet, so we can assign it to documents if ($node->isNodeType('mix:referenceable') && !$node->hasProperty('jcr:uuid')) { $uuid = false; $uuidFieldName = $metadata->getUuidFieldName(); if ($uuidFieldName) { $uuid = $metadata->getFieldValue($document, $uuidFieldName); } if (!$uuid) { $uuid = $this->generateUuid(); } $node->setProperty('jcr:uuid', $uuid); if ($uuidFieldName && !$metadata->getFieldValue($document, $uuidFieldName)) { $metadata->setFieldValue($document, $uuidFieldName, $uuid); } } }
/** * Check if a node is of any of the types listed in typeFilter. * * @param NodeInterface $node * @param array $typeFilter * * @return boolean */ private function matchNodeType(NodeInterface $node, array $typeFilter) { foreach ($typeFilter as $type) { if ($node->isNodeType($type)) { return true; } } return false; }
/** * Recursively output node and all its children into the file in the system * view format * * @param NodeInterface $node the node to output * @param resource $stream The stream resource (i.e. acquired with fopen) to * which the XML serialization of the subgraph will be output. Must * support the fwrite method. * @param boolean $skipBinary A boolean governing whether binary properties * are to be serialized. * @param boolean $noRecurse A boolean governing whether the subgraph at * absPath is to be recursed. * @param boolean $root 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 \PHPCR\PropertyInterface */ if ($name == 'jcr:primaryType' || $name == 'jcr:mixinTypes' || $name == 'jcr:uuid') { // explicitly handled before continue; } if (PropertyType::BINARY == $property->getType() && $skipBinary) { // 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>'); }
/** * {@inheritdoc} */ public function isNodeType($nodeTypeName) { return $this->node->isNodeType($nodeTypeName); }
private function setMixins(Mapping\ClassMetadata $metadata, NodeInterface $node) { if ($metadata->versionable === 'full') { $node->addMixin('mix:versionable'); } else { if ($metadata->versionable === 'simple') { $node->addMixin('mix:simpleVersionable'); } if ($metadata->referenceable) { $node->addMixin('mix:referenceable'); } } // we manually set the uuid to allow creating referenced and referencing document without flush in between. if ($node->isNodeType('mix:referenceable') && !$node->hasProperty('jcr:uuid')) { // TODO do we need to check with the storage backend if the generated id really is unique? $node->setProperty('jcr:uuid', UUIDHelper::generateUUID()); } }