/** * {@inheritDoc} */ public function deserialize($yamlData) { $res = Yaml::parse($yamlData); $node = new Node(); foreach ($res as $key => $property) { $values = $property['value']; $type = $property['type']; $newValues = array(); foreach ((array) $values as $value) { switch ($property['type']) { case 'Boolean': if ($value === 'false') { $value = false; } $value = (bool) $value; break; } $newValues[] = $value; } if (false === is_array($values)) { $newValues = reset($newValues); } if ($type === 'Binary') { $this->binaryHashMap[$key] = $property['value']; $newValues = $property['length']; } $node->setProperty($key, $newValues, $type); } return $node; }
private function processNode(Node $node) { if (false === $node->hasProperty(Storage::JCR_UUID)) { return; } $jcrUuid = UUIDHelper::generateUUID(); $node->setProperty(Storage::JCR_UUID, $jcrUuid, 'String'); }
/** * Write the given node data. * * @return array Node data */ public function writeNode($workspace, $path, Node $node) { $internalUuid = $this->getOrCreateInternalUuid($path); $node->setProperty(Storage::INTERNAL_UUID, $internalUuid, 'String'); $jcrUuid = null; if ($node->hasProperty('jcr:mixinTypes')) { $mixinTypes = $node->getPropertyValue('jcr:mixinTypes'); if (in_array('mix:referenceable', $mixinTypes)) { if (false === $node->hasProperty('jcr:uuid')) { $jcrUuid = UUIDHelper::generateUUID(); $node->setProperty('jcr:uuid', $jcrUuid); } else { $jcrUuid = $node->getPropertyValue('jcr:uuid'); } } } $serialized = $this->serializer->serialize($node); $absPath = $this->helper->getNodePath($workspace, $path); $this->filesystem->write($absPath, $serialized); foreach ($this->serializer->getSerializedBinaries() as $binaryHash => $binaryData) { // TODO: use Helper to get path ..., $binaryPath = sprintf('%s/%s.bin', dirname($absPath), $binaryHash); $this->filesystem->write($binaryPath, $binaryData); } $this->index->indexUuid($internalUuid, $workspace, $path, true); if ($jcrUuid) { $this->index->indexUuid($jcrUuid, $workspace, $path, false); } foreach ($node->getProperties() as $propertyName => $property) { foreach ((array) $property['value'] as $propertyValue) { if ($property['type'] === 'Reference') { $this->index->indexReferrer($internalUuid, $propertyName, $propertyValue, false); } if ($property['type'] === 'WeakReference') { $this->index->indexReferrer($internalUuid, $propertyName, $propertyValue, true); } } } return $node; }
public function testSetPropertyTypeInteger() { $node = new Node(); $node->setProperty('foobar', 'Foobar', 2); $this->assertEquals('Binary', $node->getPropertyType('foobar')); }
public function workspaceInit($name) { $node = new Node(); $node->setProperty('jcr:primaryType', 'nt:unstructured', 'Name'); $this->writeNode($name, '/', $node); $node = new Node(); $node->setProperty('jcr:primaryType', 'rep:system', 'Name'); $this->writeNode($name, '/jcr:system', $node); $node = new Node(); $node->setProperty('jcr:primaryType', 'rep:nodeTypes', 'Name'); $this->writeNode($name, '/jcr:system/jcr:nodeTypes', $node); }