@@ -17,7 +17,7 @@ ZenPipe is a simple and flexible PHP pipeline library that allows you to chain o
1717
1818``` php
1919$calculator = zenpipe()
20- ->pipe(fn($price, $next) => $next($price * 0.8)) // 20% discount
20+ ->pipe(fn($price, $next) => $next($price * 0.8)) // 20% discount
2121 ->pipe(fn($price, $next) => $next($price * 1.1)); // add 10% tax
2222
2323$calculator(100); // $88 (100 -> 80 -> 88)
@@ -27,7 +27,7 @@ You can also run the pipeline on demand:
2727
2828``` php
2929zenpipe(100)
30- ->pipe(fn($price, $next) => $next($price * 0.8)) // 20% discount
30+ ->pipe(fn($price, $next) => $next($price * 0.8)) // 20% discount
3131 ->pipe(fn($price, $next) => $next($price * 1.1)) // add 10% tax
3232 ->process(); // 88
3333```
@@ -57,17 +57,22 @@ zenpipe(100)
5757``` bash
5858composer require dynamik-dev/zenpipe-php
5959```
60+
6061## Usage
62+
6163### Pipeline Operations
6264
6365Pipeline operations are functions that take an input and return a processed value. Each operation can receive up to four parameters:
66+
6467- ` $input ` : The value being processed
6568- ` $next ` : A callback to pass the value to the next operation
6669- ` $return ` : (Optional) A callback to exit the pipeline early with a value
6770- ` $context ` : (Optional) A shared context object passed to all operations
6871
6972#### Basic Operation Example
73+
7074Let's build an input sanitization pipeline:
75+
7176``` php
7277// String sanitization pipeline
7378$sanitizer = zenpipe()
@@ -92,7 +97,9 @@ $result = zenpipe($dirtyInput)
9297```
9398
9499#### Operation with Early Return
100+
95101Below is a practical example of a content moderation pipeline with early returns:
102+
96103``` php
97104// Content moderation pipeline with early returns
98105$moderationPipeline = zenpipe()
@@ -125,7 +132,7 @@ $moderationPipeline = zenpipe()
125132 });
126133
127134// Usage:
128- $result = $moderationPipeline("Hello, world!");
135+ $result = $moderationPipeline("Hello, world!");
129136// Trusted user: Immediately returns approved
130137// Regular user: Goes through full moderation
131138```
@@ -225,6 +232,7 @@ $result = zenpipe($userData)
225232```
226233
227234The catch handler receives:
235+
228236- ` $e ` : The thrown exception (` Throwable ` )
229237- ` $value ` : The original input value passed to ` process() `
230238- ` $context ` : The context set via ` withContext() ` (null if not set)
@@ -288,14 +296,14 @@ $emailValidationPipeline = zenpipe()
288296 if (!$email) {
289297 return $return('Invalid email format');
290298 }
291-
299+
292300 $domain = substr(strrchr($email, "@"), 1);
293301 $mxhosts = [];
294-
302+
295303 if (!getmxrr($domain, $mxhosts)) {
296304 return $return('Domain has no valid mail servers');
297305 }
298-
306+
299307 return $next(true);
300308 });
301309
@@ -319,5 +327,3 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
319327The MIT License (MIT). See [ LICENSE] ( LICENSE ) for details.
320328
321329## Roadmap
322-
323- - [ ] Add support for PSR-15 middleware
0 commit comments