diff options
Diffstat (limited to 'vendor/sabre/dav/lib/DAV/Locks')
-rw-r--r-- | vendor/sabre/dav/lib/DAV/Locks/Backend/AbstractBackend.php | 6 | ||||
-rw-r--r-- | vendor/sabre/dav/lib/DAV/Locks/Backend/BackendInterface.php | 28 | ||||
-rw-r--r-- | vendor/sabre/dav/lib/DAV/Locks/Backend/File.php | 87 | ||||
-rw-r--r-- | vendor/sabre/dav/lib/DAV/Locks/Backend/PDO.php | 80 | ||||
-rw-r--r-- | vendor/sabre/dav/lib/DAV/Locks/LockInfo.php | 30 | ||||
-rw-r--r-- | vendor/sabre/dav/lib/DAV/Locks/Plugin.php | 265 |
6 files changed, 238 insertions, 258 deletions
diff --git a/vendor/sabre/dav/lib/DAV/Locks/Backend/AbstractBackend.php b/vendor/sabre/dav/lib/DAV/Locks/Backend/AbstractBackend.php index 044316cdb..a1bf48699 100644 --- a/vendor/sabre/dav/lib/DAV/Locks/Backend/AbstractBackend.php +++ b/vendor/sabre/dav/lib/DAV/Locks/Backend/AbstractBackend.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV\Locks\Backend; /** @@ -13,6 +15,6 @@ namespace Sabre\DAV\Locks\Backend; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -abstract class AbstractBackend implements BackendInterface { - +abstract class AbstractBackend implements BackendInterface +{ } diff --git a/vendor/sabre/dav/lib/DAV/Locks/Backend/BackendInterface.php b/vendor/sabre/dav/lib/DAV/Locks/Backend/BackendInterface.php index a2d2fe89c..9a6919f50 100644 --- a/vendor/sabre/dav/lib/DAV/Locks/Backend/BackendInterface.php +++ b/vendor/sabre/dav/lib/DAV/Locks/Backend/BackendInterface.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV\Locks\Backend; use Sabre\DAV\Locks; @@ -12,10 +14,10 @@ use Sabre\DAV\Locks; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -interface BackendInterface { - +interface BackendInterface +{ /** - * Returns a list of Sabre\DAV\Locks\LockInfo objects + * Returns a list of Sabre\DAV\Locks\LockInfo objects. * * This method should return all the locks for a particular uri, including * locks that might be set on a parent uri. @@ -24,27 +26,29 @@ interface BackendInterface { * any locks in the subtree of the uri for locks. * * @param string $uri - * @param bool $returnChildLocks + * @param bool $returnChildLocks + * * @return array */ - function getLocks($uri, $returnChildLocks); + public function getLocks($uri, $returnChildLocks); /** - * Locks a uri + * Locks a uri. * - * @param string $uri + * @param string $uri * @param Locks\LockInfo $lockInfo + * * @return bool */ - function lock($uri, Locks\LockInfo $lockInfo); + public function lock($uri, Locks\LockInfo $lockInfo); /** - * Removes a lock from a uri + * Removes a lock from a uri. * - * @param string $uri + * @param string $uri * @param Locks\LockInfo $lockInfo + * * @return bool */ - function unlock($uri, Locks\LockInfo $lockInfo); - + public function unlock($uri, Locks\LockInfo $lockInfo); } diff --git a/vendor/sabre/dav/lib/DAV/Locks/Backend/File.php b/vendor/sabre/dav/lib/DAV/Locks/Backend/File.php index 849539bee..5957f35dd 100644 --- a/vendor/sabre/dav/lib/DAV/Locks/Backend/File.php +++ b/vendor/sabre/dav/lib/DAV/Locks/Backend/File.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV\Locks\Backend; use Sabre\DAV\Locks\LockInfo; @@ -17,28 +19,27 @@ use Sabre\DAV\Locks\LockInfo; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class File extends AbstractBackend { - +class File extends AbstractBackend +{ /** - * The storage file + * The storage file. * * @var string */ private $locksFile; /** - * Constructor + * Constructor. * * @param string $locksFile path to file */ - function __construct($locksFile) { - + public function __construct($locksFile) + { $this->locksFile = $locksFile; - } /** - * Returns a list of Sabre\DAV\Locks\LockInfo objects + * Returns a list of Sabre\DAV\Locks\LockInfo objects. * * This method should return all the locks for a particular uri, including * locks that might be set on a parent uri. @@ -47,47 +48,47 @@ class File extends AbstractBackend { * any locks in the subtree of the uri for locks. * * @param string $uri - * @param bool $returnChildLocks + * @param bool $returnChildLocks + * * @return array */ - function getLocks($uri, $returnChildLocks) { - + public function getLocks($uri, $returnChildLocks) + { $newLocks = []; $locks = $this->getData(); foreach ($locks as $lock) { - if ($lock->uri === $uri || //deep locks on parents - ($lock->depth != 0 && strpos($uri, $lock->uri . '/') === 0) || + (0 != $lock->depth && 0 === strpos($uri, $lock->uri.'/')) || // locks on children - ($returnChildLocks && (strpos($lock->uri, $uri . '/') === 0))) { - + ($returnChildLocks && (0 === strpos($lock->uri, $uri.'/')))) { $newLocks[] = $lock; - } - } // Checking if we can remove any of these locks foreach ($newLocks as $k => $lock) { - if (time() > $lock->timeout + $lock->created) unset($newLocks[$k]); + if (time() > $lock->timeout + $lock->created) { + unset($newLocks[$k]); + } } - return $newLocks; + return $newLocks; } /** - * Locks a uri + * Locks a uri. * - * @param string $uri + * @param string $uri * @param LockInfo $lockInfo + * * @return bool */ - function lock($uri, LockInfo $lockInfo) { - + public function lock($uri, LockInfo $lockInfo) + { // We're making the lock timeout 30 minutes $lockInfo->timeout = 1800; $lockInfo->created = time(); @@ -105,32 +106,31 @@ class File extends AbstractBackend { } $locks[] = $lockInfo; $this->putData($locks); - return true; + return true; } /** - * Removes a lock from a uri + * Removes a lock from a uri. * - * @param string $uri + * @param string $uri * @param LockInfo $lockInfo + * * @return bool */ - function unlock($uri, LockInfo $lockInfo) { - + public function unlock($uri, LockInfo $lockInfo) + { $locks = $this->getData(); foreach ($locks as $k => $lock) { - if ($lock->token == $lockInfo->token) { - unset($locks[$k]); $this->putData($locks); - return true; + return true; } } - return false; + return false; } /** @@ -138,9 +138,11 @@ class File extends AbstractBackend { * * @return array */ - protected function getData() { - - if (!file_exists($this->locksFile)) return []; + protected function getData() + { + if (!file_exists($this->locksFile)) { + return []; + } // opening up the file, and creating a shared lock $handle = fopen($this->locksFile, 'r'); @@ -155,19 +157,20 @@ class File extends AbstractBackend { // Unserializing and checking if the resource file contains data for this file $data = unserialize($data); - if (!$data) return []; - return $data; + if (!$data) { + return []; + } + return $data; } /** - * Saves the lockdata + * Saves the lockdata. * * @param array $newData - * @return void */ - protected function putData(array $newData) { - + protected function putData(array $newData) + { // opening up the file, and creating an exclusive lock $handle = fopen($this->locksFile, 'a+'); flock($handle, LOCK_EX); @@ -179,7 +182,5 @@ class File extends AbstractBackend { fwrite($handle, serialize($newData)); flock($handle, LOCK_UN); fclose($handle); - } - } diff --git a/vendor/sabre/dav/lib/DAV/Locks/Backend/PDO.php b/vendor/sabre/dav/lib/DAV/Locks/Backend/PDO.php index 510f266f7..36a12d1ab 100644 --- a/vendor/sabre/dav/lib/DAV/Locks/Backend/PDO.php +++ b/vendor/sabre/dav/lib/DAV/Locks/Backend/PDO.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV\Locks\Backend; use Sabre\DAV\Locks\LockInfo; @@ -14,8 +16,8 @@ use Sabre\DAV\Locks\LockInfo; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class PDO extends AbstractBackend { - +class PDO extends AbstractBackend +{ /** * The PDO tablename this backend uses. * @@ -24,25 +26,24 @@ class PDO extends AbstractBackend { public $tableName = 'locks'; /** - * The PDO connection object + * The PDO connection object. * * @var pdo */ protected $pdo; /** - * Constructor + * Constructor. * * @param \PDO $pdo */ - function __construct(\PDO $pdo) { - + public function __construct(\PDO $pdo) + { $this->pdo = $pdo; - } /** - * Returns a list of Sabre\DAV\Locks\LockInfo objects + * Returns a list of Sabre\DAV\Locks\LockInfo objects. * * This method should return all the locks for a particular uri, including * locks that might be set on a parent uri. @@ -51,16 +52,17 @@ class PDO extends AbstractBackend { * any locks in the subtree of the uri for locks. * * @param string $uri - * @param bool $returnChildLocks + * @param bool $returnChildLocks + * * @return array */ - function getLocks($uri, $returnChildLocks) { - + public function getLocks($uri, $returnChildLocks) + { // NOTE: the following 10 lines or so could be easily replaced by // pure sql. MySQL's non-standard string concatenation prevents us // from doing this though. - $query = 'SELECT owner, token, timeout, created, scope, depth, uri FROM ' . $this->tableName . ' WHERE (created > (? - timeout)) AND ((uri = ?)'; - $params = [time(),$uri]; + $query = 'SELECT owner, token, timeout, created, scope, depth, uri FROM '.$this->tableName.' WHERE (created > (? - timeout)) AND ((uri = ?)'; + $params = [time(), $uri]; // We need to check locks for every part in the uri. $uriParts = explode('/', $uri); @@ -71,20 +73,18 @@ class PDO extends AbstractBackend { $currentPath = ''; foreach ($uriParts as $part) { - - if ($currentPath) $currentPath .= '/'; + if ($currentPath) { + $currentPath .= '/'; + } $currentPath .= $part; $query .= ' OR (depth!=0 AND uri = ?)'; $params[] = $currentPath; - } if ($returnChildLocks) { - $query .= ' OR (uri LIKE ?)'; - $params[] = $uri . '/%'; - + $params[] = $uri.'/%'; } $query .= ')'; @@ -94,7 +94,6 @@ class PDO extends AbstractBackend { $lockList = []; foreach ($result as $row) { - $lockInfo = new LockInfo(); $lockInfo->owner = $row['owner']; $lockInfo->token = $row['token']; @@ -104,22 +103,21 @@ class PDO extends AbstractBackend { $lockInfo->depth = $row['depth']; $lockInfo->uri = $row['uri']; $lockList[] = $lockInfo; - } return $lockList; - } /** - * Locks a uri + * Locks a uri. * - * @param string $uri + * @param string $uri * @param LockInfo $lockInfo + * * @return bool */ - function lock($uri, LockInfo $lockInfo) { - + public function lock($uri, LockInfo $lockInfo) + { // We're making the lock timeout 30 minutes $lockInfo->timeout = 30 * 60; $lockInfo->created = time(); @@ -128,11 +126,13 @@ class PDO extends AbstractBackend { $locks = $this->getLocks($uri, false); $exists = false; foreach ($locks as $lock) { - if ($lock->token == $lockInfo->token) $exists = true; + if ($lock->token == $lockInfo->token) { + $exists = true; + } } if ($exists) { - $stmt = $this->pdo->prepare('UPDATE ' . $this->tableName . ' SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE token = ?'); + $stmt = $this->pdo->prepare('UPDATE '.$this->tableName.' SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE token = ?'); $stmt->execute([ $lockInfo->owner, $lockInfo->timeout, @@ -140,10 +140,10 @@ class PDO extends AbstractBackend { $lockInfo->depth, $uri, $lockInfo->created, - $lockInfo->token + $lockInfo->token, ]); } else { - $stmt = $this->pdo->prepare('INSERT INTO ' . $this->tableName . ' (owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?)'); + $stmt = $this->pdo->prepare('INSERT INTO '.$this->tableName.' (owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?)'); $stmt->execute([ $lockInfo->owner, $lockInfo->timeout, @@ -151,30 +151,26 @@ class PDO extends AbstractBackend { $lockInfo->depth, $uri, $lockInfo->created, - $lockInfo->token + $lockInfo->token, ]); } return true; - } - - /** - * Removes a lock from a uri + * Removes a lock from a uri. * - * @param string $uri + * @param string $uri * @param LockInfo $lockInfo + * * @return bool */ - function unlock($uri, LockInfo $lockInfo) { - - $stmt = $this->pdo->prepare('DELETE FROM ' . $this->tableName . ' WHERE uri = ? AND token = ?'); + public function unlock($uri, LockInfo $lockInfo) + { + $stmt = $this->pdo->prepare('DELETE FROM '.$this->tableName.' WHERE uri = ? AND token = ?'); $stmt->execute([$uri, $lockInfo->token]); - return $stmt->rowCount() === 1; - + return 1 === $stmt->rowCount(); } - } diff --git a/vendor/sabre/dav/lib/DAV/Locks/LockInfo.php b/vendor/sabre/dav/lib/DAV/Locks/LockInfo.php index 2c8cca0fe..df8227566 100644 --- a/vendor/sabre/dav/lib/DAV/Locks/LockInfo.php +++ b/vendor/sabre/dav/lib/DAV/Locks/LockInfo.php @@ -1,9 +1,11 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV\Locks; /** - * LockInfo class + * LockInfo class. * * An object of the LockInfo class holds all the information relevant to a * single lock. @@ -12,69 +14,69 @@ namespace Sabre\DAV\Locks; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class LockInfo { - +class LockInfo +{ /** - * A shared lock + * A shared lock. */ const SHARED = 1; /** - * An exclusive lock + * An exclusive lock. */ const EXCLUSIVE = 2; /** - * A never expiring timeout + * A never expiring timeout. */ const TIMEOUT_INFINITE = -1; /** - * The owner of the lock + * The owner of the lock. * * @var string */ public $owner; /** - * The locktoken + * The locktoken. * * @var string */ public $token; /** - * How long till the lock is expiring + * How long till the lock is expiring. * * @var int */ public $timeout; /** - * UNIX Timestamp of when this lock was created + * UNIX Timestamp of when this lock was created. * * @var int */ public $created; /** - * Exclusive or shared lock + * Exclusive or shared lock. * * @var int */ public $scope = self::EXCLUSIVE; /** - * Depth of lock, can be 0 or Sabre\DAV\Server::DEPTH_INFINITY + * Depth of lock, can be 0 or Sabre\DAV\Server::DEPTH_INFINITY. */ public $depth = 0; /** - * The uri this lock locks + * The uri this lock locks. * * TODO: This value is not always set + * * @var mixed */ public $uri; - } diff --git a/vendor/sabre/dav/lib/DAV/Locks/Plugin.php b/vendor/sabre/dav/lib/DAV/Locks/Plugin.php index 41a3bf3fa..6d3e9b883 100644 --- a/vendor/sabre/dav/lib/DAV/Locks/Plugin.php +++ b/vendor/sabre/dav/lib/DAV/Locks/Plugin.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV\Locks; use Sabre\DAV; @@ -7,7 +9,7 @@ use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; /** - * Locking plugin + * Locking plugin. * * This plugin provides locking support to a WebDAV server. * The easiest way to get started, is by hooking it up as such: @@ -20,53 +22,50 @@ use Sabre\HTTP\ResponseInterface; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class Plugin extends DAV\ServerPlugin { - +class Plugin extends DAV\ServerPlugin +{ /** - * locksBackend + * locksBackend. * * @var Backend\BackendInterface */ protected $locksBackend; /** - * server + * server. * * @var DAV\Server */ protected $server; /** - * __construct + * __construct. * * @param Backend\BackendInterface $locksBackend */ - function __construct(Backend\BackendInterface $locksBackend) { - + public function __construct(Backend\BackendInterface $locksBackend) + { $this->locksBackend = $locksBackend; - } /** - * Initializes the plugin + * Initializes the plugin. * * This method is automatically called by the Server class after addPlugin. * * @param DAV\Server $server - * @return void */ - function initialize(DAV\Server $server) { - + public function initialize(DAV\Server $server) + { $this->server = $server; $this->server->xml->elementMap['{DAV:}lockinfo'] = 'Sabre\\DAV\\Xml\\Request\\Lock'; - $server->on('method:LOCK', [$this, 'httpLock']); - $server->on('method:UNLOCK', [$this, 'httpUnlock']); + $server->on('method:LOCK', [$this, 'httpLock']); + $server->on('method:UNLOCK', [$this, 'httpUnlock']); $server->on('validateTokens', [$this, 'validateTokens']); - $server->on('propFind', [$this, 'propFind']); - $server->on('afterUnbind', [$this, 'afterUnbind']); - + $server->on('propFind', [$this, 'propFind']); + $server->on('afterUnbind', [$this, 'afterUnbind']); } /** @@ -77,31 +76,28 @@ class Plugin extends DAV\ServerPlugin { * * @return string */ - function getPluginName() { - + public function getPluginName() + { return 'locks'; - } /** * This method is called after most properties have been found - * it allows us to add in any Lock-related properties + * it allows us to add in any Lock-related properties. * * @param DAV\PropFind $propFind - * @param DAV\INode $node - * @return void + * @param DAV\INode $node */ - function propFind(DAV\PropFind $propFind, DAV\INode $node) { - - $propFind->handle('{DAV:}supportedlock', function() { + public function propFind(DAV\PropFind $propFind, DAV\INode $node) + { + $propFind->handle('{DAV:}supportedlock', function () { return new DAV\Xml\Property\SupportedLock(); }); - $propFind->handle('{DAV:}lockdiscovery', function() use ($propFind) { + $propFind->handle('{DAV:}lockdiscovery', function () use ($propFind) { return new DAV\Xml\Property\LockDiscovery( $this->getLocks($propFind->getPath()) ); }); - } /** @@ -112,12 +108,12 @@ class Plugin extends DAV\ServerPlugin { * available for the specified uri. * * @param string $uri + * * @return array */ - function getHTTPMethods($uri) { - - return ['LOCK','UNLOCK']; - + public function getHTTPMethods($uri) + { + return ['LOCK', 'UNLOCK']; } /** @@ -128,14 +124,13 @@ class Plugin extends DAV\ServerPlugin { * * @return array */ - function getFeatures() { - + public function getFeatures() + { return [2]; - } /** - * Returns all lock information on a particular uri + * Returns all lock information on a particular uri. * * This function should return an array with Sabre\DAV\Locks\LockInfo objects. If there are no locks on a file, return an empty array. * @@ -144,17 +139,17 @@ class Plugin extends DAV\ServerPlugin { * for any possible locks and return those as well. * * @param string $uri - * @param bool $returnChildLocks + * @param bool $returnChildLocks + * * @return array */ - function getLocks($uri, $returnChildLocks = false) { - + public function getLocks($uri, $returnChildLocks = false) + { return $this->locksBackend->getLocks($uri, $returnChildLocks); - } /** - * Locks an uri + * Locks an uri. * * The WebDAV lock request can be operated to either create a new lock on a file, or to refresh an existing lock * If a new lock is created, a full XML body should be supplied, containing information about the lock such as the type @@ -164,12 +159,13 @@ class Plugin extends DAV\ServerPlugin { * * Additionally, a lock can be requested for a non-existent file. In these case we're obligated to create an empty file as per RFC4918:S7.3 * - * @param RequestInterface $request + * @param RequestInterface $request * @param ResponseInterface $response + * * @return bool */ - function httpLock(RequestInterface $request, ResponseInterface $response) { - + public function httpLock(RequestInterface $request, ResponseInterface $response) + { $uri = $request->getPath(); $existingLocks = $this->getLocks($uri); @@ -180,7 +176,7 @@ class Plugin extends DAV\ServerPlugin { $existingLock = null; // Checking if there's already non-shared locks on the uri. foreach ($existingLocks as $existingLock) { - if ($existingLock->scope === LockInfo::EXCLUSIVE) { + if (LockInfo::EXCLUSIVE === $existingLock->scope) { throw new DAV\Exception\ConflictingLock($existingLock); } } @@ -188,11 +184,10 @@ class Plugin extends DAV\ServerPlugin { $lockInfo = $this->parseLockRequest($body); $lockInfo->depth = $this->server->getHTTPDepth(); $lockInfo->uri = $uri; - if ($existingLock && $lockInfo->scope != LockInfo::SHARED) + if ($existingLock && LockInfo::SHARED != $lockInfo->scope) { throw new DAV\Exception\ConflictingLock($existingLock); - + } } else { - // Gonna check if this was a lock refresh. $existingLocks = $this->getLocks($uri); $conditions = $this->server->getIfConditions($request); @@ -201,7 +196,7 @@ class Plugin extends DAV\ServerPlugin { foreach ($existingLocks as $existingLock) { foreach ($conditions as $condition) { foreach ($condition['tokens'] as $token) { - if ($token['token'] === 'opaquelocktoken:' . $existingLock->token) { + if ($token['token'] === 'opaquelocktoken:'.$existingLock->token) { $found = $existingLock; break 3; } @@ -216,18 +211,20 @@ class Plugin extends DAV\ServerPlugin { } else { throw new DAV\Exception\BadRequest('An xml body is required for lock requests'); } - } // This must have been a lock refresh $lockInfo = $found; // The resource could have been locked through another uri. - if ($uri != $lockInfo->uri) $uri = $lockInfo->uri; - + if ($uri != $lockInfo->uri) { + $uri = $lockInfo->uri; + } } - if ($timeout = $this->getTimeoutHeader()) $lockInfo->timeout = $timeout; + if ($timeout = $this->getTimeoutHeader()) { + $lockInfo->timeout = $timeout; + } $newFile = false; @@ -240,56 +237,52 @@ class Plugin extends DAV\ServerPlugin { // // See Issue 222 // $this->server->emit('beforeWriteContent',array($uri)); - } catch (DAV\Exception\NotFound $e) { - // It didn't, lets create it $this->server->createFile($uri, fopen('php://memory', 'r')); $newFile = true; - } $this->lockNode($uri, $lockInfo); $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); - $response->setHeader('Lock-Token', '<opaquelocktoken:' . $lockInfo->token . '>'); + $response->setHeader('Lock-Token', '<opaquelocktoken:'.$lockInfo->token.'>'); $response->setStatus($newFile ? 201 : 200); $response->setBody($this->generateLockResponse($lockInfo)); // Returning false will interrupt the event chain and mark this method // as 'handled'. return false; - } /** - * Unlocks a uri + * Unlocks a uri. * * This WebDAV method allows you to remove a lock from a node. The client should provide a valid locktoken through the Lock-token http header * The server should return 204 (No content) on success * - * @param RequestInterface $request + * @param RequestInterface $request * @param ResponseInterface $response - * @return void */ - function httpUnlock(RequestInterface $request, ResponseInterface $response) { - + public function httpUnlock(RequestInterface $request, ResponseInterface $response) + { $lockToken = $request->getHeader('Lock-Token'); // If the locktoken header is not supplied, we need to throw a bad request exception - if (!$lockToken) throw new DAV\Exception\BadRequest('No lock token was supplied'); - + if (!$lockToken) { + throw new DAV\Exception\BadRequest('No lock token was supplied'); + } $path = $request->getPath(); $locks = $this->getLocks($path); // Windows sometimes forgets to include < and > in the Lock-Token // header - if ($lockToken[0] !== '<') $lockToken = '<' . $lockToken . '>'; + if ('<' !== $lockToken[0]) { + $lockToken = '<'.$lockToken.'>'; + } foreach ($locks as $lock) { - - if ('<opaquelocktoken:' . $lock->token . '>' == $lockToken) { - + if ('<opaquelocktoken:'.$lock->token.'>' == $lockToken) { $this->unlockNode($path, $lock); $response->setHeader('Content-Length', '0'); $response->setStatus(204); @@ -297,14 +290,11 @@ class Plugin extends DAV\ServerPlugin { // Returning false will break the method chain, and mark the // method as 'handled'. return false; - } - } // If we got here, it means the locktoken was invalid throw new DAV\Exception\LockTokenMatchesRequestUri(); - } /** @@ -313,51 +303,54 @@ class Plugin extends DAV\ServerPlugin { * We use this event to clean up any locks that still exist on the node. * * @param string $path - * @return void */ - function afterUnbind($path) { - + public function afterUnbind($path) + { $locks = $this->getLocks($path, $includeChildren = true); foreach ($locks as $lock) { $this->unlockNode($path, $lock); } - } /** - * Locks a uri + * Locks a uri. * * All the locking information is supplied in the lockInfo object. The object has a suggested timeout, but this can be safely ignored * It is important that if the existing timeout is ignored, the property is overwritten, as this needs to be sent back to the client * - * @param string $uri + * @param string $uri * @param LockInfo $lockInfo + * * @return bool */ - function lockNode($uri, LockInfo $lockInfo) { + public function lockNode($uri, LockInfo $lockInfo) + { + if (!$this->server->emit('beforeLock', [$uri, $lockInfo])) { + return; + } - if (!$this->server->emit('beforeLock', [$uri, $lockInfo])) return; return $this->locksBackend->lock($uri, $lockInfo); - } /** - * Unlocks a uri + * Unlocks a uri. * * This method removes a lock from a uri. It is assumed all the supplied information is correct and verified * - * @param string $uri + * @param string $uri * @param LockInfo $lockInfo + * * @return bool */ - function unlockNode($uri, LockInfo $lockInfo) { + public function unlockNode($uri, LockInfo $lockInfo) + { + if (!$this->server->emit('beforeUnlock', [$uri, $lockInfo])) { + return; + } - if (!$this->server->emit('beforeUnlock', [$uri, $lockInfo])) return; return $this->locksBackend->unlock($uri, $lockInfo); - } - /** * Returns the contents of the HTTP Timeout header. * @@ -365,37 +358,36 @@ class Plugin extends DAV\ServerPlugin { * * @return int */ - function getTimeoutHeader() { - + public function getTimeoutHeader() + { $header = $this->server->httpRequest->getHeader('Timeout'); if ($header) { - - if (stripos($header, 'second-') === 0) $header = (int)(substr($header, 7)); - elseif (stripos($header, 'infinite') === 0) $header = LockInfo::TIMEOUT_INFINITE; - else throw new DAV\Exception\BadRequest('Invalid HTTP timeout header'); - + if (0 === stripos($header, 'second-')) { + $header = (int) (substr($header, 7)); + } elseif (0 === stripos($header, 'infinite')) { + $header = LockInfo::TIMEOUT_INFINITE; + } else { + throw new DAV\Exception\BadRequest('Invalid HTTP timeout header'); + } } else { - $header = 0; - } return $header; - } /** - * Generates the response for successful LOCK requests + * Generates the response for successful LOCK requests. * * @param LockInfo $lockInfo + * * @return string */ - protected function generateLockResponse(LockInfo $lockInfo) { - + protected function generateLockResponse(LockInfo $lockInfo) + { return $this->server->xml->write('{DAV:}prop', [ - '{DAV:}lockdiscovery' => - new DAV\Xml\Property\LockDiscovery([$lockInfo]) + '{DAV:}lockdiscovery' => new DAV\Xml\Property\LockDiscovery([$lockInfo]), ]); } @@ -410,11 +402,10 @@ class Plugin extends DAV\ServerPlugin { * tokens. * * @param RequestInterface $request - * @param mixed $conditions - * @return void + * @param mixed $conditions */ - function validateTokens(RequestInterface $request, &$conditions) { - + public function validateTokens(RequestInterface $request, &$conditions) + { // First we need to gather a list of locks that must be satisfied. $mustLocks = []; $method = $request->getMethod(); @@ -422,24 +413,23 @@ class Plugin extends DAV\ServerPlugin { // Methods not in that list are operations that doesn't alter any // resources, and we don't need to check the lock-states for. switch ($method) { - - case 'DELETE' : + case 'DELETE': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), true )); break; - case 'MKCOL' : - case 'MKCALENDAR' : - case 'PROPPATCH' : - case 'PUT' : - case 'PATCH' : + case 'MKCOL': + case 'MKCALENDAR': + case 'PROPPATCH': + case 'PUT': + case 'PATCH': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), false )); break; - case 'MOVE' : + case 'MOVE': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), true @@ -449,13 +439,13 @@ class Plugin extends DAV\ServerPlugin { false )); break; - case 'COPY' : + case 'COPY': $mustLocks = array_merge($mustLocks, $this->getLocks( $this->server->calculateUri($request->getHeader('Destination')), false )); break; - case 'LOCK' : + case 'LOCK': //Temporary measure.. figure out later why this is needed // Here we basically ignore all incoming tokens... foreach ($conditions as $ii => $condition) { @@ -463,31 +453,29 @@ class Plugin extends DAV\ServerPlugin { $conditions[$ii]['tokens'][$jj]['validToken'] = true; } } - return; + return; } // It's possible that there's identical locks, because of shared // parents. We're removing the duplicates here. $tmp = []; - foreach ($mustLocks as $lock) $tmp[$lock->token] = $lock; + foreach ($mustLocks as $lock) { + $tmp[$lock->token] = $lock; + } $mustLocks = array_values($tmp); foreach ($conditions as $kk => $condition) { - foreach ($condition['tokens'] as $ii => $token) { - // Lock tokens always start with opaquelocktoken: - if (substr($token['token'], 0, 16) !== 'opaquelocktoken:') { + if ('opaquelocktoken:' !== substr($token['token'], 0, 16)) { continue; } $checkToken = substr($token['token'], 16); // Looping through our list with locks. foreach ($mustLocks as $jj => $mustLock) { - if ($mustLock->token == $checkToken) { - // We have a match! // Removing this one from mustlocks unset($mustLocks[$jj]); @@ -497,9 +485,7 @@ class Plugin extends DAV\ServerPlugin { // Advancing to the next token continue 2; - } - } // If we got here, it means that there was a @@ -514,42 +500,34 @@ class Plugin extends DAV\ServerPlugin { // lock-token that was expired. $oddLocks = $this->getLocks($condition['uri']); foreach ($oddLocks as $oddLock) { - if ($oddLock->token === $checkToken) { - // We have a hit! $conditions[$kk]['tokens'][$ii]['validToken'] = true; continue 2; - } } // If we get all the way here, the lock-token was // really unknown. - - } - } // If there's any locks left in the 'mustLocks' array, it means that // the resource was locked and we must block it. if ($mustLocks) { - throw new DAV\Exception\Locked(reset($mustLocks)); - } - } /** - * Parses a webdav lock xml body, and returns a new Sabre\DAV\Locks\LockInfo object + * Parses a webdav lock xml body, and returns a new Sabre\DAV\Locks\LockInfo object. * * @param string $body + * * @return LockInfo */ - protected function parseLockRequest($body) { - + protected function parseLockRequest($body) + { $result = $this->server->xml->expect( '{DAV:}lockinfo', $body @@ -562,7 +540,6 @@ class Plugin extends DAV\ServerPlugin { $lockInfo->scope = $result->scope; return $lockInfo; - } /** @@ -576,14 +553,12 @@ class Plugin extends DAV\ServerPlugin { * * @return array */ - function getPluginInfo() { - + public function getPluginInfo() + { return [ - 'name' => $this->getPluginName(), + 'name' => $this->getPluginName(), 'description' => 'The locks plugin turns this server into a class-2 WebDAV server and adds support for LOCK and UNLOCK', - 'link' => 'http://sabre.io/dav/locks/', + 'link' => 'http://sabre.io/dav/locks/', ]; - } - } |