Skip to content

Commit 3d77f63

Browse files
committed
add getter for identifier and allow disabling of auto lock break on destruct
1 parent 50a6968 commit 3d77f63

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/EtcdLock.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ public static function setDelayPerUnavailableRetry(int $delayPerRetry)
234234
*/
235235
protected $retries = 0;
236236

237+
/**
238+
* Automatically try to break the lock on destruct if possible
239+
*
240+
* @var bool
241+
*/
242+
protected $breakOnDestruct = true;
243+
237244
/**
238245
* Create a lock
239246
*
@@ -295,6 +302,26 @@ public function isLocked()
295302
return false;
296303
}
297304

305+
/**
306+
* Get the used identifier for this lock
307+
*
308+
* @return string
309+
*/
310+
public function getIdentifier(): ?string
311+
{
312+
return $this->identifier;
313+
}
314+
315+
/**
316+
* Dis/enable automatic lock break on object destruct
317+
*
318+
* @param bool $breakOnDestruct
319+
*/
320+
public function setBreakOnDestruct(bool $breakOnDestruct): void
321+
{
322+
$this->breakOnDestruct = $breakOnDestruct;
323+
}
324+
298325
/**
299326
* Refresh the lock
300327
*
@@ -559,7 +586,7 @@ protected function updateFromString($lockString)
559586
*/
560587
public function __destruct()
561588
{
562-
if ($this->isLocked()) {
589+
if ($this->breakOnDestruct && $this->isLocked()) {
563590
$this->break();
564591
}
565592
}

0 commit comments

Comments
 (0)