6 * This class represents the {DAV:}response XML element.
7 * This is used by the Server class to encode individual items within a multistatus
12 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
13 * @author Evert Pot (http://www.rooftopsolutions.nl/)
14 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
16 class Sabre_DAV_Property_Response extends Sabre_DAV_Property implements Sabre_DAV_Property_IHref {
19 * Url for the response
26 * Propertylist, ordered by HTTP status code
30 private $responseProperties;
33 * The responseProperties argument is a list of properties
34 * within an array with keys representing HTTP status codes
37 * @param array $responseProperties
39 public function __construct($href, array $responseProperties) {
42 $this->responseProperties = $responseProperties;
51 public function getHref() {
58 * Returns the property list
62 public function getResponseProperties() {
64 return $this->responseProperties;
71 * @param Sabre_DAV_Server $server
72 * @param DOMElement $dom
75 public function serialize(Sabre_DAV_Server $server, DOMElement $dom) {
77 $document = $dom->ownerDocument;
78 $properties = $this->responseProperties;
80 $xresponse = $document->createElement('d:response');
81 $dom->appendChild($xresponse);
83 $uri = Sabre_DAV_URLUtil::encodePath($this->href);
85 // Adding the baseurl to the beginning of the url
86 $uri = $server->getBaseUri() . $uri;
88 $xresponse->appendChild($document->createElement('d:href',$uri));
90 // The properties variable is an array containing properties, grouped by
92 foreach($properties as $httpStatus=>$propertyGroup) {
94 // The 'href' is also in this array, and it's special cased.
96 if ($httpStatus=='href') continue;
98 // If there are no properties in this group, we can also just carry on
99 if (!count($propertyGroup)) continue;
101 $xpropstat = $document->createElement('d:propstat');
102 $xresponse->appendChild($xpropstat);
104 $xprop = $document->createElement('d:prop');
105 $xpropstat->appendChild($xprop);
107 $nsList = $server->xmlNamespaces;
109 foreach($propertyGroup as $propertyName=>$propertyValue) {
112 preg_match('/^{([^}]*)}(.*)$/',$propertyName,$propName);
114 // special case for empty namespaces
115 if ($propName[1]=='') {
117 $currentProperty = $document->createElement($propName[2]);
118 $xprop->appendChild($currentProperty);
119 $currentProperty->setAttribute('xmlns','');
123 if (!isset($nsList[$propName[1]])) {
124 $nsList[$propName[1]] = 'x' . count($nsList);
127 // If the namespace was defined in the top-level xml namespaces, it means
128 // there was already a namespace declaration, and we don't have to worry about it.
129 if (isset($server->xmlNamespaces[$propName[1]])) {
130 $currentProperty = $document->createElement($nsList[$propName[1]] . ':' . $propName[2]);
132 $currentProperty = $document->createElementNS($propName[1],$nsList[$propName[1]].':' . $propName[2]);
134 $xprop->appendChild($currentProperty);
138 if (is_scalar($propertyValue)) {
139 $text = $document->createTextNode($propertyValue);
140 $currentProperty->appendChild($text);
141 } elseif ($propertyValue instanceof Sabre_DAV_Property) {
142 $propertyValue->serialize($server,$currentProperty);
143 } elseif (!is_null($propertyValue)) {
144 throw new Sabre_DAV_Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName);
149 $xpropstat->appendChild($document->createElement('d:status',$server->httpResponse->getStatusMessage($httpStatus)));