Completed
Push — master ( b97427...e235cc )
by Raffael
30:35 queued 26:08
created

LockBackend   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 57
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLocks() 0 18 2
A lock() 0 5 1
A unlock() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\App\Webdav;
13
14
use Balloon\Filesystem;
15
use Balloon\Server;
16
use Sabre\DAV\Locks\Backend\BackendInterface;
17
use Sabre\DAV\Locks\LockInfo;
18
19
class LockBackend implements BackendInterface
20
{
21
    /**
22
     * Filesystem.
23
     *
24
     * @var Filesystem
25
     */
26
    protected $fs;
27
28
    /**
29
     * Constructor.
30
     */
31
    public function __construct(Server $server)
32
    {
33
        $this->fs = $server->getFilesystem();
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getLocks($uri, $returnChildLocks)
40
    {
41
        $node = $this->fs->findNodeByPath($uri);
42
43
        if (!$node->isLocked()) {
44
            return [];
45
        }
46
47
        $lock = $node->getLock();
48
        $info = new LockInfo();
49
        $info->owner = (string) $lock['owner'];
50
        $info->token = $lock['id'];
51
        $info->timeout = $lock['expire']->toDateTime()->format('U') - time();
52
        $info->created = $lock['created']->toDateTime()->format('U');
53
        $info->uri = $uri;
54
55
        return [$info];
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function lock($uri, LockInfo $lock)
62
    {
63
        $node = $this->fs->findNodeByPath($uri);
64
        $node->lock($lock->token, $lock->timeout);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function unlock($uri, LockInfo $lock)
71
    {
72
        $node = $this->fs->findNodeByPath($uri);
73
        $node->unlock($lock->token);
74
    }
75
}
76