19declare(strict_types=1);
24use Sabre\DAV\Locks\Backend\AbstractBackend;
28use Sabre\DAV\Locks\LockInfo;
46 $this->cache =
$DIC->globalCache()->get($this);
47 $this->cache->flush();
49 use DeriveApplyToFromTransform;
50 use DeriveInvokeFromTransform;
62 return 'webdav:locks';
70 private function key(
string $uri): string
72 return 'locks:' . md5($uri);
75 public function getLocks($uri, $returnChildLocks): array
77 $key = $this->
key($uri);
82 if (!$this->cache->has($key)) {
87 foreach ($this->cache->get($key, $this->raw) as $item) {
94 private function asArray(LockInfo $lockInfo): array
97 'owner' => $lockInfo->owner,
98 'token' => $lockInfo->token,
99 'scope' => $lockInfo->scope,
100 'depth' => $lockInfo->depth,
101 'timeout' => $lockInfo->timeout,
102 'uri' => $lockInfo->uri,
103 'created' => $lockInfo->created,
109 $lock =
new LockInfo();
110 $lock->owner = $item[
'owner'];
111 $lock->token = $item[
'token'];
112 $lock->scope = $item[
'scope'];
113 $lock->depth = $item[
'depth'];
114 $lock->timeout = $item[
'timeout'];
115 $lock->uri = $item[
'uri'];
116 $lock->created = $item[
'created'];
121 public function lock($uri, LockInfo $lockInfo): bool
123 $key = $this->
key($uri);
125 $locks = $this->cache->get($key, $this->
raw) ?? [];
127 $lock =
new LockInfo();
128 $lock->owner = $lockInfo->owner;
129 $lock->token = $lockInfo->token;
130 $lock->scope = LockInfo::EXCLUSIVE;
131 $lock->depth = $lockInfo->depth;
132 $lock->timeout = $lockInfo->timeout;
134 $lock->created = $lockInfo->created ?? time();
136 $locks[] = $this->
asArray($lock);
138 $this->cache->set($key, $locks);
143 public function unlock($uri, LockInfo $lockInfo): bool
145 $key = $this->
key($uri);
149 $this->cache->set($key, []);
151 $entity = $this->entity_factory->getByFullPath($uri);
152 $proxy = $entity?->getObjectProxy();
153 if ($proxy !==
null && $proxy->getType() === Type::FILE) {
154 $proxy->getStreamHandler()->publish();
trait DeriveInvokeFromTransform
trait DeriveApplyToFromTransform
asArray(LockInfo $lockInfo)
lock($uri, LockInfo $lockInfo)
__construct(private Factory $entity_factory)
getLocks($uri, $returnChildLocks)
unlock($uri, LockInfo $lockInfo)