62 $this->server->xml->elementMap[
'{DAV:}lockinfo'] =
'Sabre\\DAV\\Xml\\Request\\Lock';
64 $server->on(
'method:LOCK', [$this,
'httpLock']);
65 $server->on(
'method:UNLOCK', [$this,
'httpUnlock']);
66 $server->on(
'validateTokens', [$this,
'validateTokens']);
67 $server->on(
'propFind', [$this,
'propFind']);
68 $server->on(
'afterUnbind', [$this,
'afterUnbind']);
96 $propFind->handle(
'{DAV:}supportedlock',
function() {
99 $propFind->handle(
'{DAV:}lockdiscovery',
function() use ($propFind) {
101 $this->
getLocks($propFind->getPath())
119 return [
'LOCK',
'UNLOCK'];
150 function getLocks($uri, $returnChildLocks =
false) {
152 return $this->locksBackend->getLocks($uri, $returnChildLocks);
175 $existingLocks = $this->
getLocks($uri);
180 $existingLock = null;
182 foreach ($existingLocks as $existingLock) {
184 throw new DAV\Exception\ConflictingLock($existingLock);
189 $lockInfo->depth = $this->server->getHTTPDepth();
190 $lockInfo->uri = $uri;
192 throw new DAV\Exception\ConflictingLock($existingLock);
197 $existingLocks = $this->
getLocks($uri);
198 $conditions = $this->server->getIfConditions($request);
201 foreach ($existingLocks as $existingLock) {
202 foreach ($conditions as $condition) {
203 foreach ($condition[
'tokens'] as
$token) {
204 if ($token[
'token'] ===
'opaquelocktoken:' . $existingLock->token) {
205 $found = $existingLock;
213 if (is_null($found)) {
214 if ($existingLocks) {
215 throw new DAV\Exception\Locked(reset($existingLocks));
217 throw new DAV\Exception\BadRequest(
'An xml body is required for lock requests');
226 if ($uri != $lockInfo->uri) $uri = $lockInfo->uri;
236 $this->server->tree->getNodeForPath($uri);
247 $this->server->createFile($uri,
fopen(
'php://memory',
'r'));
254 $response->
setHeader(
'Content-Type',
'application/xml; charset=utf-8');
255 $response->
setHeader(
'Lock-Token',
'<opaquelocktoken:' . $lockInfo->token .
'>');
256 $response->
setStatus($newFile ? 201 : 200);
277 $lockToken = $request->
getHeader(
'Lock-Token');
280 if (!$lockToken)
throw new DAV\Exception\BadRequest(
'No lock token was supplied');
287 if ($lockToken[0] !==
'<') $lockToken =
'<' . $lockToken .
'>';
289 foreach ($locks as $lock) {
291 if (
'<opaquelocktoken:' . $lock->token .
'>' == $lockToken) {
294 $response->
setHeader(
'Content-Length',
'0');
306 throw new DAV\Exception\LockTokenMatchesRequestUri();
321 foreach ($locks as $lock) {
339 if (!$this->server->emit(
'beforeLock', [$uri, $lockInfo]))
return;
340 return $this->locksBackend->lock($uri, $lockInfo);
355 if (!$this->server->emit(
'beforeUnlock', [$uri, $lockInfo]))
return;
356 return $this->locksBackend->unlock($uri, $lockInfo);
370 $header = $this->server->httpRequest->getHeader(
'Timeout');
376 else throw new DAV\Exception\BadRequest(
'Invalid HTTP timeout header');
396 return $this->server->xml->write(
'{DAV:}prop', [
397 '{DAV:}lockdiscovery' =>
398 new DAV\Xml\Property\LockDiscovery([$lockInfo])
427 $mustLocks = array_merge($mustLocks, $this->
getLocks(
437 $mustLocks = array_merge($mustLocks, $this->
getLocks(
443 $mustLocks = array_merge($mustLocks, $this->
getLocks(
447 $mustLocks = array_merge($mustLocks, $this->
getLocks(
448 $this->server->calculateUri($request->
getHeader(
'Destination')),
453 $mustLocks = array_merge($mustLocks, $this->
getLocks(
454 $this->server->calculateUri($request->
getHeader(
'Destination')),
461 foreach ($conditions as
$ii => $condition) {
462 foreach ($condition[
'tokens'] as $jj =>
$token) {
463 $conditions[
$ii][
'tokens'][$jj][
'validToken'] =
true;
473 foreach ($mustLocks as $lock) $tmp[$lock->token] = $lock;
474 $mustLocks = array_values($tmp);
476 foreach ($conditions as $kk => $condition) {
478 foreach ($condition[
'tokens'] as
$ii =>
$token) {
481 if (substr(
$token[
'token'], 0, 16) !==
'opaquelocktoken:') {
485 $checkToken = substr(
$token[
'token'], 16);
487 foreach ($mustLocks as $jj => $mustLock) {
489 if ($mustLock->token == $checkToken) {
493 unset($mustLocks[$jj]);
496 $conditions[$kk][
'tokens'][
$ii][
'validToken'] =
true;
515 $oddLocks = $this->
getLocks($condition[
'uri']);
516 foreach ($oddLocks as $oddLock) {
518 if ($oddLock->token === $checkToken) {
521 $conditions[$kk][
'tokens'][
$ii][
'validToken'] =
true;
539 throw new DAV\Exception\Locked(reset($mustLocks));
553 $result = $this->server->xml->expect(
560 $lockInfo->owner =
$result->owner;
562 $lockInfo->scope =
$result->scope;
583 'description' =>
'The locks plugin turns this server into a class-2 WebDAV server and adds support for LOCK and UNLOCK',
584 'link' =>
'http://sabre.io/dav/locks/',
httpLock(RequestInterface $request, ResponseInterface $response)
Locks an uri.
This interface represents a HTTP response.
The RequestInterface represents a HTTP request.
getPluginName()
Returns a plugin name.
This class represents the {DAV:}supportedlock property.
The baseclass for all server plugins.
setBody($body)
Updates the body resource with a new stream.
foreach($paths as $path) $request
parseLockRequest($body)
Parses a webdav lock xml body, and returns a new Sabre object.
getBodyAsString()
Returns the body as a string.
getPluginInfo()
Returns a bunch of meta-data about the plugin.
afterUnbind($path)
This method is called after a node is deleted.
const EXCLUSIVE
An exclusive lock.
This class holds all the information about a PROPFIND request.
getFeatures()
Returns a list of features for the HTTP OPTIONS Dav: header.
getHTTPMethods($uri)
Use this method to tell the server this plugin defines additional HTTP methods.
unlockNode($uri, LockInfo $lockInfo)
Unlocks a uri.
Represents {DAV:}lockdiscovery property.
initialize(DAV\Server $server)
Initializes the plugin.
setStatus($status)
Sets the HTTP status code.
getHeader($name)
Returns a specific HTTP header, based on it's name.
The INode interface is the base interface, and the parent class of both ICollection and IFile...
validateTokens(RequestInterface $request, &$conditions)
The validateTokens event is triggered before every request.
const SHARED
A shared lock.
getPath()
Returns the relative path.
getMethod()
Returns the current HTTP method.
getTimeoutHeader()
Returns the contents of the HTTP Timeout header.
const TIMEOUT_INFINITE
A never expiring timeout.
static getUUID()
Returns a pseudo-random v4 UUID.
getLocks($uri, $returnChildLocks=false)
Returns all lock information on a particular uri.
lockNode($uri, LockInfo $lockInfo)
Locks a uri.
propFind(DAV\PropFind $propFind, DAV\INode $node)
This method is called after most properties have been found it allows us to add in any Lock-related p...
generateLockResponse(LockInfo $lockInfo)
Generates the response for successful LOCK requests.
setHeader($name, $value)
Updates a HTTP header.
httpUnlock(RequestInterface $request, ResponseInterface $response)
Unlocks a uri.
__construct(Backend\BackendInterface $locksBackend)
__construct