]> git.mxchange.org Git - friendica.git/blob - src/Core/Lock/AbstractLockDriver.php
Deleting return-types of methods
[friendica.git] / src / Core / Lock / AbstractLockDriver.php
1 <?php
2
3 namespace Friendica\Core\Lock;
4
5 /**
6  * Class AbstractLockDriver
7  *
8  * @package Friendica\Core\Lock
9  *
10  * @brief Basic class for Locking with common functions (local acquired locks, releaseAll, ..)
11  */
12 abstract class AbstractLockDriver implements ILockDriver
13 {
14         /**
15          * @var array The local acquired locks
16          */
17         protected $acquiredLocks = [];
18
19         /**
20          * @brief Check if we've locally acquired a lock
21          *
22          * @param string key The Name of the lock
23          * @return bool      Returns true if the lock is set
24          */
25         protected function hasAcquiredLock(string $key) {
26                 return isset($this->acquireLock[$key]);
27         }
28
29         /**
30          * @brief Mark a locally acquired lock
31          *
32          * @param string $key The Name of the lock
33          */
34         protected function markAcquire(string $key) {
35                 $this->acquiredLocks[$key] = true;
36         }
37
38         /**
39          * @brief Mark a release of a locally acquired lock
40          *
41          * @param string $key The Name of the lock
42          */
43         protected function markRelease(string $key) {
44                 unset($this->acquiredLocks[$key]);
45         }
46
47         /**
48          * @brief Releases all lock that were set by us
49          *
50          * @return void
51          */
52         public function releaseAll() {
53                 foreach ($this->acquiredLocks as $acquiredLock) {
54                         $this->releaseLock($acquiredLock);
55                 }
56         }
57 }