File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,13 @@ public static function setDelayPerUnavailableRetry(int $delayPerRetry)
234
234
*/
235
235
protected $ retries = 0 ;
236
236
237
+ /**
238
+ * Automatically try to break the lock on destruct if possible
239
+ *
240
+ * @var bool
241
+ */
242
+ protected $ breakOnDestruct = true ;
243
+
237
244
/**
238
245
* Create a lock
239
246
*
@@ -295,6 +302,26 @@ public function isLocked()
295
302
return false ;
296
303
}
297
304
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
+
298
325
/**
299
326
* Refresh the lock
300
327
*
@@ -559,7 +586,7 @@ protected function updateFromString($lockString)
559
586
*/
560
587
public function __destruct ()
561
588
{
562
- if ($ this ->isLocked ()) {
589
+ if ($ this ->breakOnDestruct && $ this -> isLocked ()) {
563
590
$ this ->break ();
564
591
}
565
592
}
You can’t perform that action at this time.
0 commit comments