aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/lib/DAV/Locks/Backend/File.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/lib/DAV/Locks/Backend/File.php')
-rw-r--r--vendor/sabre/dav/lib/DAV/Locks/Backend/File.php87
1 files changed, 44 insertions, 43 deletions
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);
-
}
-
}