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(); } }