Download the PHP package dynamik-dev/zenpipe-php without Composer
On this page you can find all versions of the php package dynamik-dev/zenpipe-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dynamik-dev/zenpipe-php
More information about dynamik-dev/zenpipe-php
Files in dynamik-dev/zenpipe-php
Package zenpipe-php
Short Description A simple, fluent pipeline implementation for PHP.
License MIT
Informations about the package zenpipe-php
ZenPipe
ZenPipe is a simple and flexible PHP pipeline library that allows you to chain operations together to process, transform, or act on input.
You can also run the pipeline on demand:
Sections
- ZenPipe
- Requirements
- Installation
- Usage
- Pipeline Operations
- Class Methods as Operations
- Context Passing
- Exception Handling
- PSR-15 Middleware
- More Examples
- API Reference
- Contributing
- License
Requirements
- PHP 8.2 or higher
Installation
Usage
Pipeline Operations
Pipeline operations are functions that take an input and return a processed value. Each operation can receive up to four parameters:
$input: The value being processed$next: A callback to pass the value to the next operation$return: (Optional) A callback to exit the pipeline early with a value$context: (Optional) A shared context object passed to all operations
Basic Operation Example
Let's build an input sanitization pipeline:
Operation with Early Return
Below is a practical example of a content moderation pipeline with early returns:
Class Methods as Operations
You can also use class methods as operations, with the same parameter options:
You can also pass an array of operations:
Context Passing
You can pass a shared context object to all operations using withContext(). This is useful for sharing state, configuration, or dependencies across the pipeline without threading them through the value.
Type hint your context parameter in the operation signature for IDE support:
Exception Handling
Use catch() to handle exceptions gracefully without breaking the pipeline:
The catch handler receives:
$e: The thrown exception (Throwable)$value: The original input value passed toprocess()$context: The context set viawithContext()(null if not set)
If no catch handler is set, exceptions propagate normally.
PSR-15 Middleware
ZenPipe provides bidirectional PSR-15 middleware support. Requires psr/http-server-middleware.
Using PSR-15 Middleware in a Pipeline
Pass any MiddlewareInterface directly to pipe():
When using PSR-15 middleware, the pipeline must return a ResponseInterface.
Using ZenPipe as PSR-15 Middleware
Wrap a pipeline with asMiddleware() for use in PSR-15 frameworks:
Behavior:
- If the pipeline returns a
ResponseInterface, it's returned directly - If the pipeline returns a
ServerRequestInterface, it's passed to the next handler - The PSR-15 handler is available via
$context->handlerfor explicit delegation
More Examples
RAG Processes
This pipeline can be used for RAG processes, where the output of one model is used as input for another.
Email Validation with Early Return
This pipeline demonstrates early returns for email validation:
API Reference
See API Reference for details.
Contributing
See CONTRIBUTING.md for details.
License
The MIT License (MIT). See LICENSE for details.