phpbotgram

Lock
in package

FinalYes

A thin wrapper around an optional `Amp\Sync\Lock` that implements the acquire/release pattern for FSM event isolation.

Ported from the async context-manager pattern of aiogram.fsm.storage.base.BaseEventIsolation.lock (aiogram/fsm/storage/base.py:200-208).

The $inner is nullable to support DisabledEventIsolation, which needs a no-op lock. An optional $releaseFn closure allows Redis-backed (or other distributed) implementations to supply a custom release action without subclassing. A $released guard prevents double-release: calling release() more than once is silently ignored.

Table of Contents

Properties

$inner  : Lock|null
$released  : bool
$releaseFn  : Closure|null

Methods

__construct()  : mixed
Construct a `Lock` in one of two exclusive modes:
release()  : void
Releases the underlying lock. Idempotent — subsequent calls are no-ops.

Properties

$inner read-only

private Lock|null $inner

$released

private bool $released = false

$releaseFn read-only

private Closure|null $releaseFn = null

Methods

__construct()

Construct a `Lock` in one of two exclusive modes:

public __construct(Lock|null $inner[, null|callable(): void $releaseFn = null ]) : mixed
  • Amp mode: supply $inner (an Amp\Sync\Lock) and leave $releaseFn null. release() calls $inner->release().
  • Custom-fn mode: supply $releaseFn and leave $inner null. release() invokes the closure. Used by RedisEventIsolation where the release must execute a Lua check-and-delete atomically.
  • Disabled mode: both null is valid for DisabledEventIsolation (a no-op lock).

Providing both $inner and $releaseFn is a programming error — it is ambiguous which release protocol to follow and would silently leak the $inner Amp lock unreleased. The constructor rejects this to fail fast.

Parameters
$inner : Lock|null
$releaseFn : null|callable(): void = null

Optional custom release callback.

Tags
throws
InvalidArgumentException

When both $inner and $releaseFn are provided.

release()

Releases the underlying lock. Idempotent — subsequent calls are no-ops.

public release() : void

When a custom $releaseFn was provided at construction, it is invoked and $inner is left alone (the closure handles the full release protocol). When only $inner is present, the standard Amp\Sync\Lock::release() is called.

On this page

Search results