From 3d77f63c02b8455c13086c1f2135b6d85a2a9163 Mon Sep 17 00:00:00 2001 From: Matthias Neid Date: Thu, 6 May 2021 00:03:41 +0200 Subject: [PATCH] add getter for identifier and allow disabling of auto lock break on destruct --- src/EtcdLock.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/EtcdLock.php b/src/EtcdLock.php index df520a3..2744efc 100644 --- a/src/EtcdLock.php +++ b/src/EtcdLock.php @@ -234,6 +234,13 @@ public static function setDelayPerUnavailableRetry(int $delayPerRetry) */ protected $retries = 0; + /** + * Automatically try to break the lock on destruct if possible + * + * @var bool + */ + protected $breakOnDestruct = true; + /** * Create a lock * @@ -295,6 +302,26 @@ public function isLocked() return false; } + /** + * Get the used identifier for this lock + * + * @return string + */ + public function getIdentifier(): ?string + { + return $this->identifier; + } + + /** + * Dis/enable automatic lock break on object destruct + * + * @param bool $breakOnDestruct + */ + public function setBreakOnDestruct(bool $breakOnDestruct): void + { + $this->breakOnDestruct = $breakOnDestruct; + } + /** * Refresh the lock * @@ -559,7 +586,7 @@ protected function updateFromString($lockString) */ public function __destruct() { - if ($this->isLocked()) { + if ($this->breakOnDestruct && $this->isLocked()) { $this->break(); } }