public function evaluateCondition(ResourceInterface $resource = NULL) { if ($this->not) { if ($resource === NULL) { return true; } if (!$resource instanceof LockableResourceInterface) { return true; } if (!$resource->isLocked()) { return true; } return (string) $this->token !== (string) $resource->getLockInfo()->getToken(); } if ($resource === NULL) { return false; } if (!$resource instanceof LockableResourceInterface) { return false; } if (!$resource->isLocked()) { return false; } return (string) $this->token === (string) $resource->getLockInfo()->getToken(); }
protected function handleUnlock(ResourceInterface $resource, Uri $baseUri, HttpRequest $request, LockStorageInterface $storage) { if (!$resource instanceof LockableResourceInterface) { throw new MethodNotAllowedException(); } if (!$resource->isLockSupported()) { throw new MethodNotAllowedException(); } if (!$resource->isLocked()) { throw new LockTokenMatchesRequestUriException(WebDav::CODE_CONFLICT); } if (!$request->hasHeader('Lock-Token')) { throw new BadRequestException(); } try { $tmp = $request->getHeader('Lock-Token', ''); $m = NULL; if (!preg_match("'^<?urn:webdav:lock:([0-9a-f\\-]{36})>?\$'i", $tmp, $m)) { throw new BadRequestException(); } $token = new UUID($m[1]); } catch (\InvalidArgumentException $e) { throw new BadRequestException($e); } $lockInfo = $resource->getLockInfo(); if ($token != $lockInfo->getToken() || $lockInfo->getExpires() < new \DateTime()) { throw new LockTokenMatchesRequestUriException(WebDav::CODE_CONFLICT); } $storage->beginTransaction(); try { $storage->removeLock($lockInfo); } catch (\Exception $e) { $storage->rollBack(); throw $e; } $storage->commit(); return new HttpResponse(Http::CODE_NO_CONTENT); }