protected function parsePropfindRequest(\DOMNodeList $nodes, \DOMXPath $xpath) { $propfind = new PropfindRequest(); foreach ($nodes as $node) { $nodes = $xpath->query('*', $node); if ($nodes->length < 1) { throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY); } foreach ($nodes as $prop) { $propfind->addProperty(new XmlName($prop)); } } return $propfind; }
protected function parseSyncBody(\DOMDocument $doc) { $xpath = new \DOMXPath($doc); $xpath->registerNamespace('D', WebDav::NS_DAV); $nodes = $xpath->query('/D:sync-collection/D:sync-token'); $m = NULL; if ($nodes->length < 1 || !preg_match("'^(?:urn:webdav:sync:([a-f0-9\\-]{36}))?\$'i", trim($nodes->item(0)->textContent), $m)) { throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY); } $token = empty($m[1]) ? NULL : new UUID($m[1]); $nodes = $xpath->query('/D:sync-collection/D:sync-level'); if ($nodes->length < 1) { throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY); } $level = (string) trim($nodes->item(0)->textContent); $limit = NULL; $nodes = $xpath->query('/D:sync-collection/D:limit'); if ($nodes->length > 0) { $limit = (int) trim($nodes->item(0)->textContent); if ($limit < 1) { throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY); } } $nodes = $xpath->query('/D:sync-collection/D:prop'); if ($nodes->length < 1) { throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY); } $propfind = new PropfindRequest(); foreach ($xpath->query('*', $nodes->item(0)) as $el) { $propfind->addProperty(new XmlName($el)); } try { return new SyncRequest($propfind, $level, $token, $limit); } catch (\InvalidArgumentException $e) { throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY, $e); } }