Exemplo n.º 1
0
 /**
  * Stores a property to the given absolute path
  *
  * @param string $path Absolute path to identify a specific property.
  * @param \PHPCR\PropertyInterface
  * @return bool true on success
  *
  * @throws \PHPCR\RepositoryException if not logged in
  */
 public function storeProperty($path, \PHPCR\PropertyInterface $property)
 {
     $this->ensureAbsolutePath($path);
     $type = \PHPCR\PropertyType::nameFromValue($property->getType());
     $request = $this->getRequest(Request::PUT, $path);
     $nativeValue = $property->getNativeValue();
     if ($property->getName() === 'jcr:mixinTypes') {
         $uri = $this->normalizeUri(dirname($path) === '\\' ? '/' : dirname($path));
         $request->setUri($uri);
         $request->setMethod(Request::PROPPATCH);
         $body = '<?xml version="1.0" encoding="UTF-8"?>' . '<D:propertyupdate xmlns:D="DAV:">' . '<D:set>' . '<D:prop>' . '<dcr:mixinnodetypes xmlns:dcr="http://www.day.com/jcr/webdav/1.0">';
         foreach ($nativeValue as $value) {
             $body .= '<dcr:nodetype><dcr:nodetypename>' . $value . '</dcr:nodetypename></dcr:nodetype>';
         }
         $body .= '</dcr:mixinnodetypes>' . '</D:prop>' . '</D:set>' . '</D:propertyupdate>';
     } elseif (is_array($nativeValue)) {
         $body = '<?xml version="1.0" encoding="UTF-8"?>' . '<jcr:values xmlns:jcr="http://www.day.com/jcr/webdav/1.0">';
         foreach ($nativeValue as $value) {
             $body .= '<jcr:value jcr:type="' . $type . '">' . $this->propertyToXmlString($value, $type) . '</jcr:value>';
         }
         $body .= '</jcr:values>';
     } else {
         $body = $this->propertyToRawString($nativeValue, $type);
         $request->setContentType('jcr-value/' . strtolower($type));
     }
     $request->setBody($body);
     $request->execute();
     return true;
 }