Blame view

sources/3rdparty/sabre/dav/lib/Sabre/DAV/Property/Response.php 4.6 KB
03e52840d   Kload   Init
1
  <?php
6d9380f96   Cédric Dupont   Update sources OC...
2
3
4
  namespace Sabre\DAV\Property;
  
  use Sabre\DAV;
03e52840d   Kload   Init
5
6
7
8
9
10
11
  /**
   * Response property
   *
   * This class represents the {DAV:}response XML element.
   * This is used by the Server class to encode individual items within a multistatus
   * response.
   *
6d9380f96   Cédric Dupont   Update sources OC...
12
13
14
   * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/).
   * @author Evert Pot (http://evertpot.com/)
   * @license http://sabre.io/license/ Modified BSD License
03e52840d   Kload   Init
15
   */
6d9380f96   Cédric Dupont   Update sources OC...
16
  class Response extends DAV\Property implements IHref {
03e52840d   Kload   Init
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  
      /**
       * Url for the response
       *
       * @var string
       */
      private $href;
  
      /**
       * Propertylist, ordered by HTTP status code
       *
       * @var array
       */
      private $responseProperties;
  
      /**
       * The responseProperties argument is a list of properties
       * within an array with keys representing HTTP status codes
       *
       * @param string $href
       * @param array $responseProperties
       */
      public function __construct($href, array $responseProperties) {
  
          $this->href = $href;
          $this->responseProperties = $responseProperties;
  
      }
  
      /**
       * Returns the url
       *
       * @return string
       */
      public function getHref() {
  
          return $this->href;
  
      }
  
      /**
       * Returns the property list
       *
       * @return array
       */
      public function getResponseProperties() {
  
          return $this->responseProperties;
  
      }
  
      /**
       * serialize
       *
6d9380f96   Cédric Dupont   Update sources OC...
71
72
       * @param DAV\Server $server
       * @param \DOMElement $dom
03e52840d   Kload   Init
73
74
       * @return void
       */
6d9380f96   Cédric Dupont   Update sources OC...
75
      public function serialize(DAV\Server $server, \DOMElement $dom) {
03e52840d   Kload   Init
76
77
78
79
80
81
  
          $document = $dom->ownerDocument;
          $properties = $this->responseProperties;
  
          $xresponse = $document->createElement('d:response');
          $dom->appendChild($xresponse);
6d9380f96   Cédric Dupont   Update sources OC...
82
          $uri = DAV\URLUtil::encodePath($this->href);
03e52840d   Kload   Init
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  
          // Adding the baseurl to the beginning of the url
          $uri = $server->getBaseUri() . $uri;
  
          $xresponse->appendChild($document->createElement('d:href',$uri));
  
          // The properties variable is an array containing properties, grouped by
          // HTTP status
          foreach($properties as $httpStatus=>$propertyGroup) {
  
              // The 'href' is also in this array, and it's special cased.
              // We will ignore it
              if ($httpStatus=='href') continue;
  
              // If there are no properties in this group, we can also just carry on
              if (!count($propertyGroup)) continue;
  
              $xpropstat = $document->createElement('d:propstat');
              $xresponse->appendChild($xpropstat);
  
              $xprop = $document->createElement('d:prop');
              $xpropstat->appendChild($xprop);
  
              $nsList = $server->xmlNamespaces;
  
              foreach($propertyGroup as $propertyName=>$propertyValue) {
  
                  $propName = null;
                  preg_match('/^{([^}]*)}(.*)$/',$propertyName,$propName);
  
                  // special case for empty namespaces
                  if ($propName[1]=='') {
  
                      $currentProperty = $document->createElement($propName[2]);
                      $xprop->appendChild($currentProperty);
                      $currentProperty->setAttribute('xmlns','');
  
                  } else {
  
                      if (!isset($nsList[$propName[1]])) {
                          $nsList[$propName[1]] = 'x' . count($nsList);
                      }
  
                      // If the namespace was defined in the top-level xml namespaces, it means
                      // there was already a namespace declaration, and we don't have to worry about it.
                      if (isset($server->xmlNamespaces[$propName[1]])) {
                          $currentProperty = $document->createElement($nsList[$propName[1]] . ':' . $propName[2]);
                      } else {
                          $currentProperty = $document->createElementNS($propName[1],$nsList[$propName[1]].':' . $propName[2]);
                      }
                      $xprop->appendChild($currentProperty);
  
                  }
  
                  if (is_scalar($propertyValue)) {
                      $text = $document->createTextNode($propertyValue);
                      $currentProperty->appendChild($text);
6d9380f96   Cédric Dupont   Update sources OC...
140
                  } elseif ($propertyValue instanceof DAV\PropertyInterface) {
03e52840d   Kload   Init
141
142
                      $propertyValue->serialize($server,$currentProperty);
                  } elseif (!is_null($propertyValue)) {
6d9380f96   Cédric Dupont   Update sources OC...
143
                      throw new DAV\Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName);
03e52840d   Kload   Init
144
145
146
147
148
149
150
151
152
153
154
                  }
  
              }
  
              $xpropstat->appendChild($document->createElement('d:status',$server->httpResponse->getStatusMessage($httpStatus)));
  
          }
  
      }
  
  }