Total Complexity | 5 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
6 | class Locker |
||
7 | { |
||
8 | /** @var LockerDriver $driver */ |
||
9 | private $driver; |
||
10 | |||
11 | /** |
||
12 | * Creates a new Locker instance |
||
13 | * |
||
14 | * @param LockerDriver $driver The instance of the LockerDriver to use to check the state of locked pages |
||
15 | */ |
||
16 | public function __construct(LockerDriver $driver) |
||
17 | { |
||
18 | $this->driver = $driver; |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * Is the specified URL locked? |
||
23 | * |
||
24 | * @param string $url The URL to check the lock status for |
||
25 | * @return bool true if locked, otherwise false |
||
26 | */ |
||
27 | public function isLocked(string $url): bool |
||
28 | { |
||
29 | $status = $this->driver->getURLStatus($url); |
||
30 | return $status->isLocked(); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Gets the full status of a page |
||
35 | * |
||
36 | * @param string $url |
||
37 | * @return Status |
||
38 | */ |
||
39 | public function getURLStatus(string $url): Status |
||
40 | { |
||
41 | return $this->driver->getURLStatus($url); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Locks the given URL for a specified amount of time |
||
46 | * |
||
47 | * @param string $url The URL to lock |
||
48 | * @param string $lockedBy The identifier of the user locking the page |
||
49 | * @param int $lockFor The amount of seconds to lock the page for |
||
50 | */ |
||
51 | public function lock(string $url, string $lockedBy, int $lockFor): void |
||
52 | { |
||
53 | $this->driver->lockURL($url, $lockedBy, $lockFor); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Unlocks the given URL |
||
58 | * |
||
59 | * @param string $url The URL to unlock |
||
60 | */ |
||
61 | public function unlock(string $url): void |
||
64 | } |
||
65 | } |
||
66 |