adachsoft / lease-lock-contracts
Contracts for expiring, owner-bound lease locks: lease lock interface, lease DTO and exceptions.
Requires
- php: ^8.3
Requires (Dev)
- adachsoft/php-code-style: ^0.7.3
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.5
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/lease-lock-contracts defines a storage-independent API for expiring lease locks bound to an owner. It provides the lock interface, an immutable lease snapshot, and exceptions for invalid arguments and storage failures. The package contains contracts only; applications supply an implementation backed by their chosen storage.
Features
- Atomic acquisition contract for competing callers.
- Owner-checked renewal and release operations.
- Lookup of active leases and an immutable
LeaseDtowith expiration checks. - Validation of lease identifiers, TTLs, and lease time ranges through the documented contract.
Requirements
- PHP 8.3 or later.
Installation
composer require adachsoft/lease-lock-contracts
Usage
Type application services against LeaseLockInterface and configure an implementation supplied by your application or another package. For an example of acquiring, renewing, and releasing a lease, see Lease lock usage.
Acquisition is not reentrant: an active lease returns null, including when it belongs to the requesting owner. Renewal returns false for a missing, expired, or differently owned lease and does not change the original acquisition time. Release only removes an active lease owned by the caller; missing, expired, and differently owned leases are left unchanged. Lookup returns null for absent or expired leases.
Keys and owners must be non-empty and no longer than 255 characters, and TTL values must be positive. LeaseDto::isActiveAt() considers a lease active only when its expiration is strictly later than the supplied time. Invalid arguments raise InvalidLeaseArgumentException; storage failures raise LeaseLockStorageException. Both extend AbstractLeaseLockException.