コード例 #1
0
 /**
  * Parse the request body
  */
 protected function __construct()
 {
     parent::__construct();
     $input = $this->inputString();
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !@$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING | LIBXML_NOERROR)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     $nodelist = $xpath->query('/D:propertyupdate/*/D:prop/*');
     for ($i = 0; $i < $nodelist->length; $i++) {
         $element = $nodelist->item($i);
         if ('DAV:' !== $element->parentNode->parentNode->namespaceURI) {
             continue;
         }
         if ('remove' === $element->parentNode->parentNode->localName) {
             $this->props["{$element->namespaceURI} {$element->localName}"] = null;
         } else {
             $xml = '';
             for ($j = 0; $child = $element->childNodes->item($j); $j++) {
                 $xml .= DAV::recursiveSerialize($child);
             }
             $this->props["{$element->namespaceURI} {$element->localName}"] = $xml;
         }
     }
     //  $nodelist = $xpath->query('/D:propertyupdate/D:remove/D:prop/*');
     //  for ($i = 0; $i < $nodelist->length; $i++) {
     //    $element = $nodelist->item($i);
     //        $xml = '';
     //    for ($j = 0; $child = $element->childNodes->item($j); $j++)
     //      $xml .= DAV::recursiveSerialize($child);
     //    $this->props["{$element->namespaceURI} {$element->localName}"] = null;
     //  }
     // DEBUG
 }
コード例 #2
0
ファイル: DAVTest.php プロジェクト: pieterb/webdav-php
 public function testRecursiveSerialize()
 {
     $ns1 = 'tests://test/';
     $ns2 = 'tests://test_more/';
     $xmlDoc = new DOMDocument('1.0', 'UTF-8');
     $root = $xmlDoc->createElementNS($ns1, 'root');
     $sub1 = $xmlDoc->createElementNS($ns1, 'sub1');
     $sub1_1 = $xmlDoc->createElementNS($ns1, 'sub1_1');
     $cdata1_1 = $xmlDoc->createCDATASection('test text');
     $sub2 = $xmlDoc->createElementNS($ns2, 'sub2');
     $sub2_1 = $xmlDoc->createElementNS($ns1, 'sub2_1');
     $comment2_1 = $xmlDoc->createComment('test comment');
     $xmlDoc->appendChild($root);
     $root->appendChild($sub1);
     $sub1->appendChild($sub1_1);
     $sub1_1->appendChild($cdata1_1);
     $root->appendChild($sub2);
     $sub2->appendChild($sub2_1);
     $sub2_1->appendChild($comment2_1);
     // Because recursiveSerialize is not forced to use ns1 and ns2 as namespace prefixes, this test is a bit awkward. But it works for now, so let's just ignore it :)
     $this->assertSame('<ns1:root xmlns:ns1="tests://test/" xmlns:ns2="tests://test_more/"><ns1:sub1><ns1:sub1_1>test text</ns1:sub1_1></ns1:sub1><ns2:sub2><ns1:sub2_1><!--test comment--></ns1:sub2_1></ns2:sub2></ns1:root>', DAV::recursiveSerialize($root), 'DAV::recursiveSerialize() should return correct XML');
 }
コード例 #3
0
 /**
  * Enter description here...
  *
  * @throws DAV_Status
  */
 protected function __construct()
 {
     parent::__construct();
     $this->init_timeout();
     $input = $this->inputstring();
     if (empty($input)) {
         return;
     }
     // New lock!
     $this->newlock = true;
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !@$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING | LIBXML_NOERROR)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     if ((int) $xpath->evaluate('count(/D:lockinfo/D:lockscope/D:shared)') > 0) {
         throw new DAV_Status(DAV::HTTP_NOT_IMPLEMENTED, 'Shared locks are not supported.');
     } elseif ((int) $xpath->evaluate('count(/D:lockinfo/D:lockscope/D:exclusive)') !== 1) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'No &lt;lockscope/&gt; element in LOCK request, hmm.');
     }
     if ((int) $xpath->evaluate('count(/D:lockinfo/D:locktype/D:write)') !== 1) {
         throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'Unknown lock type in request body');
     }
     $ownerlist = $xpath->query('/D:lockinfo/D:owner');
     if ($ownerlist->length) {
         $ownerxml = '';
         $ownerchildnodes = $ownerlist->item(0)->childNodes;
         for ($i = 0; $child = $ownerchildnodes->item($i); $i++) {
             $ownerxml .= DAV::recursiveSerialize($child);
         }
         $this->owner = trim($ownerxml);
     }
 }