Download the PHP package tommyknocker/chain without Composer
On this page you can find all versions of the php package tommyknocker/chain. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download tommyknocker/chain
More information about tommyknocker/chain
Files in tommyknocker/chain
Download tommyknocker/chain
More information about tommyknocker/chain
Files in tommyknocker/chain
Vendor tommyknocker
Package chain
Short Description Chainable class for fluent, cross-object method chaining.
License MIT
Package chain
Short Description Chainable class for fluent, cross-object method chaining.
License MIT
Please rate this library. Is it a good library?
Informations about the package chain
Chain
Fluent method chaining & context switching utility for PHP. Call methods across objects, transform or branch chains, and conditionally execute logic in a concise style.
Quick Example
Installation
Core Concepts
- Start with
Chain::of($object)orChain::of(ClassName::class, ...$args) - Every method call stays fluent; if a method returns an object, the chain context switches to it automatically
- Use
change($idOrObject)to jump to another object (resolved via PSR-11 container if configured) - Use
get()to read the last result (or the current instance if there is no last result)
API Overview
Core Methods:
of(string|object $target, ...$args): Chain- Start a chain from an object or instantiate a classget(): mixed- Get final resultvalue(): mixed- Alias for get(), more semanticinstance(): object- Get current wrapped object
Transformation:
tap(callable $fn): Chain- Execute side effectsmap(callable $fn): Chain- Transform to another objectpipe(callable ...$pipes): Chain- Functional pipeline
Enhanced Control Flow:
whenAll(callable ...$conditions): Chain- Execute when ALL conditions are truewhenAny(callable ...$conditions): Chain- Execute when ANY condition is truewhenNone(callable ...$conditions): Chain- Execute when NO conditions are truewhen(bool|callable $cond, callable $cb, ?callable $else = null): Chain- Conditional executionunless(bool|callable $cond, callable $cb, ?callable $else = null): Chain- Inverse conditionalclone(): Chain- Branch immutably
Resilience:
rescue(callable $callback, callable $handler): Chain- Handle exceptions with fallbackcatch(string $exceptionClass, callable $callback, callable $handler): Chain- Catch specific exceptionsretry(int $times, callable $callback, int $delayMs = 0): Chain- Retry with backofftimeout(int $seconds, callable $callback): Chain- Timeout protection
Iteration & Debugging:
each(callable $fn): Chain- Iterate over collectionsdump(string $label = ''): Chain- Debug output, continues chaindd(string $label = ''): never- Dump and die
Container Integration:
change(string|object $target): Chain- Switch to another object (PSR-11)
Configuration & Extensions:
Chain::configure(ChainConfig $config): void- Configure Chain behavioraddExtension(ChainExtensionInterface $extension): Chain- Add extension for monitoring/logging
Examples
Basic Chaining
Conditional Logic
Enhanced Conditional Logic
Pipeline
Pipelines with pipe()
Tap for Side Effects
Branching
Immutable Branching with clone()
Composite Scenario
Timeout Protection
Configuration & Extensions
Development
Installation
Testing
Code Quality
Examples
Release Management
Examples
See the examples/ directory for working examples:
workflow.php- Complete workflow with User→Profile context switchingconditionals.php- Conditional execution with when/unlessbranching.php- Clone chains for independent branchespipeline.php- Functional pipelines with pipe()processing.php- Data processing with each(), dump(), value()resilience.php- Error handling with rescue(), catch(), retry()container.php- PSR-11 container integrationadvanced-features.php- NEW! All enhanced features demo
Run examples:
License
MIT. See LICENSE file.
Changelog
See CHANGELOG.md for a list of changes and version history.
All versions of chain with dependencies
PHP Build Version
Package Version
The package tommyknocker/chain contains the following files
Loading the files please wait ...