Download the PHP package minfrastructure/chains without Composer
On this page you can find all versions of the php package minfrastructure/chains. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download minfrastructure/chains
More information about minfrastructure/chains
Files in minfrastructure/chains
Package chains
Short Description Build Different type of chains with optional filtering
License MIT
Informations about the package chains
Chains
A PHP library for building event-driven execution chains with hooks, callbacks, policies, and a rich result system. Zero dependencies.
Chains lets you wrap any operation in a structured pipeline of phases and hooks, so that internal and external code can intercept, validate, transform, or react to every step — without tight coupling.
Current library focuses on reusability. You can implement once and customize the class behavior on according to the business needs.
Requirements
- PHP 8.2+
Installation
Quick Start
You can run the latest example here
How It Works
Every call to EventExecutor::run() executes a fixed sequence of phases:
- Hooks are functions, methods or closures you pass to
EventExecutor::run(), keyed by phase. - Callbacks are externally registered on the instance itself (via
CallbackInterface) and run at the PRE and POST stages. think of them as plugin. - Results flow through the chain. Each step can inspect, modify, or replace the current result.
- Policies control what happens on failure, incomplete results, retries, and early termination.
Key Concepts
Result
The value object that flows through the chain. Carries state flags and a data payload.
Callback Return Contract
Every hook/callback receives ($data, $phase, $executor, $result) and returns:
| Return value | Effect |
|---|---|
null or true |
Continue with the current result unchanged |
BasicResultInterface |
Replace the current result |
CommonEvents Helpers
Ready-made [Meta, callable] pairs for property operations on objects — including protected/private properties. Use the spread operator to pass them to EventExecutor::run():
CallbackInterface
Objects that implement CallbackInterface (via CallbackTrait) can register their own callbacks. The executor picks them up automatically:
Execution Policy
DefaultEventExecutorPolicy controls chain behavior:
Source Interfaces
An instance can implement these optional interfaces so the executor automatically queries it for configuration — no extra arguments needed:
| Interface | Method | Purpose |
|---|---|---|
EventSourceDataInterface |
getEventData($name, $data) |
Provide custom event data |
EventSourceHooksInterface |
getEventHooks($name, $hooks) |
Inject hooks automatically |
EventSourcePolicyInterface |
getEventExecutorPolicy($name) |
Provide per-event policy |
Retry Mechanism
A callback can request a retry by calling setAgain() on the result. The executor triggers ON_AGAIN, then re-runs the callback up to againLimit times:
Examples
The examples/ directory contains runnable scripts covering every feature:
| File | Topic |
|---|---|
01_minimal.php |
Simplest possible usage |
02_hooks_and_phases.php |
Full phase lifecycle, terminal hooks |
03_results.php |
Result creation, states, from() |
04_common_events.php |
getter/setter/adding/removing/cleanup, safe reflection |
05_callbacks.php |
CallbackInterface, PRE/POST stages, priority |
06_policy.php |
All policy options demonstrated |
07_retry.php |
again mechanism, limits, abort |
08_source_interfaces.php |
EventSourceData/Hooks/Policy interfaces |
09_model_lifecycle.php |
Full domain model with event-driven getters/setters |
Tutorial
See TUTORIAL.md for a step-by-step walkthrough from basic usage to building a full domain model with event-driven property access.