Merge pull request #17348 from eileenmcnaughton/payex
[civicrm-core.git] / Civi / Core / Lock / NullLock.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11 namespace Civi\Core\Lock;
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18 class NullLock implements LockInterface {
19
20 private $hasLock = FALSE;
21
22 /**
23 * Create lock.
24 *
25 * @param string $name
26 *
27 * @return static
28 */
29 public static function create($name) {
30 return new static();
31 }
32
33 /**
34 * Acquire lock.
35 *
36 * @param int|null $timeout
37 * The number of seconds to wait to get the lock.
38 * For a default value, use NULL.
39 *
40 * @return bool
41 */
42 public function acquire($timeout = NULL) {
43 $this->hasLock = TRUE;
44 return TRUE;
45 }
46
47 /**
48 * Release lock.
49 *
50 * @return bool|null|string
51 * Trueish/falsish.
52 */
53 public function release() {
54 $this->hasLock = FALSE;
55 return TRUE;
56 }
57
58 /**
59 * @return bool|null|string
60 * Trueish/falsish.
61 * @deprecated
62 * Not supported by some locking strategies. If you need to poll, better
63 * to use acquire(0).
64 */
65 public function isFree() {
66 return !$this->hasLock;
67 }
68
69 /**
70 * @return bool
71 */
72 public function isAcquired() {
73 return $this->hasLock;
74 }
75
76 }