Download the PHP package silassare/php-utils without Composer
On this page you can find all versions of the php package silassare/php-utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download silassare/php-utils
More information about silassare/php-utils
Files in silassare/php-utils
Package php-utils
Short Description PHP utils: a set of php utilities used across projects.
License MIT
Homepage https://github.com/silassare/php-utils#readme
Informations about the package php-utils
PHP Utils
A PHP 8.1+ utility library providing reusable components across projects, with strict typing throughout.
Requirements
- PHP ≥ 8.1
ext-jsonpsr/http-message ^2.0
Installation
Components
- String utilities (
Str) - Class introspection (
ClassUtils) - Stack trace utilities (
FuncUtils) - Dot/bracket path value object (
DotPath) - Portable regular expressions (
PortablePattern) - HTML node builder (
DOM) .envparser & editor (Env)- Event system (
Events) - Rich exceptions (
Exceptions) - Filesystem utilities (
FS) - Interfaces
- Lock system (
Lock) - Traits
- Key-value store (
Store)
Str
PHPUtils\Str — Static string manipulation utilities.
ClassUtils
PHPUtils\ClassUtils — Deep trait introspection with result caching.
FuncUtils
PHPUtils\FuncUtils — Stack-trace caller location.
DotPath
PHPUtils\DotPath — Value object for parsed JS-like dot/bracket path strings.
Supported syntax:
| Syntax | Example | Description |
|---|---|---|
| Plain | foo.bar |
Segments matching [a-zA-Z0-9_]+ |
| Bracket integer | items[0] |
Array index access |
| Bracket quoted | map['my.key'] |
Keys containing dots or special chars |
PortablePattern
PHPUtils\PortablePattern — A regular expression PHP (PCRE) and JavaScript read the same way, for a
rule declared on the server and checked again in the browser.
The form stays PHP's (<d>body<d>flags), so a pattern already written for preg_match() stays valid.
What PCRE has and JavaScript lacks, or reads otherwise, is refused when the pattern is declared, with the
reason and the offset: possessive quantifiers, atomic groups, conditionals, recursion, \A, \z, \K,
\Q...\E, POSIX classes, \x{...}, octal escapes, script properties, flags other than i, m, s
and u, ... toPcre() then runs it as JavaScript runs it: in Unicode mode, $ matching only at the very
end of the value (not before a final newline) unless m is set.
Known differences that remain, since the patterns meeting them are rare: \s also matches the Unicode
spaces in JavaScript, and . without s also stops at \r, U+2028 and U+2029.
DOM
PHPUtils\DOM\ — Lightweight HTML node builder.
Env
PHPUtils\Env\ — Tokenizing .env file parser and token-level editor.
Parsing
Casting rules:
- Unquoted
true/false→bool(whencast_bool=true) - Unquoted numbers →
int/float(whencast_numeric=true) - Quoted values are always
string
Editing
Events
PHPUtils\Events\ — Priority-based event system with channels.
Priority levels
| Constant | Value | Description |
|---|---|---|
EventInterface::RUN_FIRST |
1 |
Runs before default listeners |
EventInterface::RUN_DEFAULT |
2 |
Default priority |
EventInterface::RUN_LAST |
3 |
Runs after all others (reverse registration order) |
Usage
Exceptions
PHPUtils\Exceptions\RuntimeException — Rich exception with structured data and suspect tracking.
Suspect helpers:
| Method | Description |
|---|---|
suspect(array) |
Set raw suspect data |
suspectLocation(['file', 'line?', 'start?', 'end?']) |
Point to a source location |
suspectCallable(callable) |
Record a callable's file/line range |
suspectArray(array, ?string $path) |
Record an array (optionally with a DotPath) |
suspectObject(object, ?string $path) |
Record an object |
FS
PHPUtils\FS\ — Filesystem utilities.
PathUtils
PHPUtils\FS\PathUtils — Static path resolution and normalisation.
FSUtils
PHPUtils\FS\FSUtils — Filesystem operations rooted at a base path.
FilesFilter
PHPUtils\FS\FilesFilter — Chainable file finder / filter.
Interfaces
| Interface | Description |
|---|---|
PHPUtils\Interfaces\ArrayCapableInterface |
Contracts toArray(): array\|ArrayAccess and jsonSerialize(). |
PHPUtils\Interfaces\MetaCapableInterface |
Contracts getMeta(): Map, setMetaKey() and mergeMeta(). |
PHPUtils\Interfaces\RichExceptionInterface |
Rich exception contract with getData(bool $show_sensitive). |
PHPUtils\Lock\Interfaces\LockInterface |
Lock token contract: acquire(), isAcquired(). |
PHPUtils\Lock\Interfaces\ReleasableLockInterface |
Extends LockInterface with release() for reversible locks. |
PHPUtils\Lock\Interfaces\LockableInterface |
Lockable entity contract: getLock(), lock(), unlock(), isLocked(), assertNotLocked(). |
Lock
PHPUtils\Lock\ — Extensible lock system with support for both releasable and permanent locks.
Design
The lock token (LockInterface) is decoupled from the lockable entity (LockableInterface), so you can inject or share a custom lock implementation without changing the entity class.
| Class / Interface | Role |
|---|---|
Interfaces\LockInterface |
Token contract: acquire() + isAcquired() |
Interfaces\ReleasableLockInterface |
Extends LockInterface with release() for reversible locks |
Interfaces\LockableInterface |
Entity contract: getLock(), lock(), unlock(), isLocked(), assertNotLocked() |
Lock |
Default in-memory, releasable ReleasableLockInterface implementation |
PermanentLock |
Irreversible LockInterface implementation — no release() |
Traits\LockableTrait |
Default implementation of LockableInterface; override createLock() to inject a custom token |
Traits\PermanentlyLockableTrait |
Variant of LockableTrait using PermanentLock — unlock() always throws |
Basic usage
Permanent (irreversible) lock
Shared lock across instances
Traits
| Trait | Description |
|---|---|
PHPUtils\Traits\ArrayCapableTrait |
Implements jsonSerialize() by delegating to toArray(). Set $json_empty_array_is_object = true to serialize an empty result as {}. |
PHPUtils\Lock\Traits\LockableTrait |
Implements LockableInterface. Override createLock() to inject a custom LockInterface token. |
PHPUtils\Lock\Traits\PermanentlyLockableTrait |
Variant of LockableTrait using PermanentLock by default — unlock() always throws. |
PHPUtils\Traits\MetaCapableTrait |
Implements MetaCapableInterface. Provides getMeta(): Map (lazy), setMetaKey() and mergeMeta(). Guards mutation with assertNotLocked() when the host implements LockableInterface. |
PHPUtils\Traits\RichExceptionTrait |
Full implementation of RichExceptionInterface with suspect tracking. |
PHPUtils\Traits\RecordableTrait |
Records dynamic method calls via __call() and replays them on another object via play($target). |
MetaCapableTrait
When the host class implements LockableInterface, both setMetaKey() and mergeMeta() automatically call assertNotLocked().
RecordableTrait
Store
PHPUtils\Store\ — Generic data containers with dot/bracket-notation path access.
Map
PHPUtils\Store\Map — A Store specialised for array<string, mixed> data. Serialises an empty result as {} (JSON object) instead of [].
Store (editable)
StoreNotEditable (read-only)
License
MIT — see LICENSE for details.