/** * Does a PROPFIND request * * The list of requested properties must be specified as an array, in clark * notation. * * The returned array will contain a list of filenames as keys, and * properties as values. * * The properties array will contain the list of properties. Only properties * that are actually returned from the server (without error) will be * returned, anything else is discarded. * * Depth should be either 0 or 1. A depth of 1 will cause a request to be * made to the server to also return all child resources. * * @param string $url * @param array $properties * @param int $depth * @return array */ function propFind($url, array $properties, $depth = 0) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $root = $dom->createElementNS('DAV:', 'd:propfind'); $prop = $dom->createElement('d:prop'); foreach ($properties as $property) { list($namespace, $elementName) = \Sabre\Xml\Service::parseClarkNotation($property); if ($namespace === 'DAV:') { $element = $dom->createElement('d:' . $elementName); } else { $element = $dom->createElementNS($namespace, 'x:' . $elementName); } $prop->appendChild($element); } $dom->appendChild($root)->appendChild($prop); $body = $dom->saveXML(); $url = $this->getAbsoluteUrl($url); $request = new HTTP\Request('PROPFIND', $url, ['Depth' => $depth, 'Content-Type' => 'application/xml'], $body); $response = $this->send($request); if ((int) $response->getStatus() >= 400) { throw new \Sabre\HTTP\ClientHttpException($response); } $result = $this->parseMultiStatus($response->getBodyAsString()); // If depth was 0, we only return the top item if ($depth === 0) { reset($result); $result = current($result); return isset($result[200]) ? $result[200] : []; } $newResult = []; foreach ($result as $href => $statusList) { $newResult[$href] = isset($statusList[200]) ? $statusList[200] : []; } return $newResult; }
/** * Writes a new attribute. * * The name may be specified in clark-notation. * * Returns true when successful. * * @param string $name * @param string $value * @return bool */ function writeAttribute($name, $value) { if ($name[0] === '{') { list($namespace, $localName) = Service::parseClarkNotation($name); if (array_key_exists($namespace, $this->namespaceMap)) { // It's an attribute with a namespace we know $this->writeAttribute($this->namespaceMap[$namespace] . ':' . $localName, $value); } else { // We don't know the namespace, we must add it in-line if (!isset($this->adhocNamespaces[$namespace])) { $this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces) + 1); } $this->writeAttributeNS($this->adhocNamespaces[$namespace], $localName, $namespace, $value); } } else { return parent::writeAttribute($name, $value); } }
/** * Get tag name from a Clark notation. * * @param string $clarkedTagName * * @return string */ protected static function getTagName($clarkedTagName) { list(, $tagName) = SabreXml\Service::parseClarkNotation($clarkedTagName); return $tagName; }
/** * This method takes an xml element in clark-notation, and turns it into a * shortened version with a prefix, if it was a known namespace. * * @param string $element * @return string */ function xmlName($element) { list($ns, $localName) = XmlService::parseClarkNotation($element); if (isset($this->namespaceMap[$ns])) { $propName = $this->namespaceMap[$ns] . ':' . $localName; } else { $propName = $element; } return "<span title=\"" . $this->h($element) . "\">" . $this->h($propName) . "</span>"; }