Esempio n. 1
0
 /**
  * Parses a WebDAV multistatus response body
  *
  * This method returns an array with the following structure
  *
  * array(
  *   'url/to/resource' => array(
  *     '200' => array(
  *        '{DAV:}property1' => 'value1',
  *        '{DAV:}property2' => 'value2',
  *     ),
  *     '404' => array(
  *        '{DAV:}property1' => null,
  *        '{DAV:}property2' => null,
  *     ),
  *   )
  *   'url/to/resource2' => array(
  *      .. etc ..
  *   )
  * )
  *
  *
  * @param string $body xml body
  * @return array
  */
 public function parseMultiStatus($body)
 {
     $body = XMLUtil::convertDAVNamespace($body);
     $responseXML = simplexml_load_string($body, null, LIBXML_NOBLANKS | LIBXML_NOCDATA);
     if ($responseXML === false) {
         throw new \InvalidArgumentException('The passed data is not valid XML');
     }
     $responseXML->registerXPathNamespace('d', 'urn:DAV');
     $propResult = array();
     foreach ($responseXML->xpath('d:response') as $response) {
         $response->registerXPathNamespace('d', 'urn:DAV');
         $href = $response->xpath('d:href');
         $href = (string) $href[0];
         $properties = array();
         foreach ($response->xpath('d:propstat') as $propStat) {
             $propStat->registerXPathNamespace('d', 'urn:DAV');
             $status = $propStat->xpath('d:status');
             list($httpVersion, $statusCode, $message) = explode(' ', (string) $status[0], 3);
             // Only using the propertymap for results with status 200.
             $propertyMap = $statusCode === '200' ? $this->propertyMap : array();
             $properties[$statusCode] = XMLUtil::parseProperties(dom_import_simplexml($propStat), $propertyMap);
         }
         $propResult[$href] = $properties;
     }
     return $propResult;
 }
Esempio n. 2
0
 function testConvertDAVNamespaceMixedQuotes()
 {
     $xml = '<?xml version="1.0"?><document xmlns=\'DAV:" xmlns="Another attribute\'>blablabla</document>';
     $this->assertEquals($xml, XMLUtil::convertDAVNamespace($xml));
 }