Exemplo n.º 1
0
 public function testValidateHeadersFailure()
 {
     $req = new ezcWebdavLockRequest('/foo', '/bar');
     $req->setHeader('Depth', null);
     try {
         $req->validateHeaders();
         $this->fail('Exception not thrown on missing Depth header.');
     } catch (ezcWebdavMissingHeaderException $e) {
     }
     $req->setHeader('Depth', 'A');
     try {
         $req->validateHeaders();
         $this->fail('Exception not thrown on invalid Depth header.');
     } catch (ezcWebdavInvalidHeaderException $e) {
     }
     $req->setHeader('Depth', ezcWebdavRequest::DEPTH_ONE);
     try {
         $req->validateHeaders();
         $this->fail('Exception not thrown on invalid Depth header.');
     } catch (ezcWebdavInvalidHeaderException $e) {
     }
 }
Exemplo n.º 2
0
 /**
  * Parses the LOCK request and returns a request object.
  *
  * This method is responsible for parsing the LOCK request. It retrieves
  * the current request URI in $path and the request body as $body.  The
  * return value, if no exception is thrown, is a valid {@link
  * ezcWebdavLockRequest} object.
  *
  * This method may be overwritten to adjust it to special client behaviour.
  * 
  * @param string $path 
  * @param string $body 
  * @return ezcWebdavLockRequest
  */
 protected function parseLockRequest($path, $body)
 {
     $request = new ezcWebdavLockRequest($path);
     $request->setHeaders(ezcWebdavServer::getInstance()->headerHandler->parseHeaders(array('Depth')));
     if (trim($body) === '') {
         return $request;
     }
     try {
         $dom = ezcWebdavServer::getInstance()->xmlTool->createDom($body);
     } catch (ezcWebdavInvalidXmlException $e) {
         throw new ezcWebdavInvalidRequestBodyException('LOCK', $e->getMessage());
     }
     if ($dom->documentElement->localName !== 'lockinfo') {
         throw new ezcWebdavInvalidRequestBodyException('LOCK', "Expected XML element <lockinfo />, received <{$dom->documentElement->localName} />.");
     }
     $lockTypeElements = $dom->documentElement->getElementsByTagnameNS(ezcWebdavXmlTool::XML_DEFAULT_NAMESPACE, 'locktype');
     $lockScopeElements = $dom->documentElement->getElementsByTagnameNS(ezcWebdavXmlTool::XML_DEFAULT_NAMESPACE, 'lockscope');
     $ownerElements = $dom->documentElement->getElementsByTagnameNS(ezcWebdavXmlTool::XML_DEFAULT_NAMESPACE, 'owner');
     if ($lockTypeElements->length === 0) {
         throw new ezcWebdavInvalidRequestBodyException('LOCK', "Expected XML element <locktype /> as child of <lockinfo /> in namespace DAV: which was not found.");
     }
     if ($lockScopeElements->length === 0) {
         throw new ezcWebdavInvalidRequestBodyException('LOCK', "Expected XML element <lockscope /> as child of <lockinfo /> in namespace DAV: which was not found.");
     }
     // @todo is the following not restrictive enough?
     $request->lockInfo = new ezcWebdavRequestLockInfoContent($lockScopeElements->item(0)->firstChild->localName === 'exclusive' ? ezcWebdavLockRequest::SCOPE_EXCLUSIVE : ezcWebdavLockRequest::SCOPE_SHARED, $lockTypeElements->item(0)->firstChild->localName === 'read' ? ezcWebdavLockRequest::TYPE_READ : ezcWebdavLockRequest::TYPE_WRITE, $ownerElements->length > 0 ? new ezcWebdavPotentialUriContent($ownerElements->item(0)->textContent, $ownerElements->item(0)->hasChildNodes() && $ownerElements->item(0)->firstChild->localName === 'href') : new ezcWebdavPotentialUriContent());
     $request->setHeader('Timeout', $this->headerHandler->parseTimeoutHeader());
     return $request;
 }