Comments (1)
// This is one way to check for errors and skip to the end of a pipeline during processing . . .
// Create the Pipeline
$pipeline = (new Pipeline(
// Set the processor to InterruptibleProcessor (instead of FingersCrossed)
new InterruptibleProcessor(
// Create a class GetOkay->__invoke() that calls $payload->getOkay()
// Pass GetOkay into InterruptibleProcessor so it knows where to check.
new GetOkay
)
))
// Create a Payload class with setOkay(), getOkay(), and a private property $okay
// Note: Line 25 InterruptibleProcessor is " if (true !== $check($payload)) { "
->pipe(new CreatePayload)
// Create a CheckBeforeFirstAction class to update $payload->setOkay() as needed.
// This class can check to make sure all requirements are OK to run FirstAction.
// Tip: Every class in the pipeline should (modify and) return the $payload object.
->pipe(new CheckBeforeFirstAction)
// CheckBeforeFirstAction(Payload $payload) returns the $payload object.
// The InterruptibleProcessor will check for an error using GetOkay->_invoke()
// If $payload->okay is still set to true the FirstAction will run
->pipe(new FirstAction)
// Create a CheckBeforeSecondAction class to $payload->setOkay() as needed.
->pipe(new CheckBeforeSecondAction)
// Set $payload->setOkay('false') inside CheckBeforeSecondAction as a test.
// The InterruptibleProcessor will check for an error using GetOkay->_invoke()
// The SecondAction will NOT be run since $payload->okay = false.
->pipe(new SecondAction);
// The $payload will be returned from InterruptibleProcessor.
// wowcut: Set a property in the $payload to specify which stages should run.
// I don't think you will reduce the if-then-else, but you can hide them in Check classes
Thanks to creator and maintainer of the Pipeline!
Drew
from pipeline.
Related Issues (20)
- Pipeline should use call_user_func HOT 2
- Add variadic variable to __invoke HOT 4
- Add PipelineBuilderInterface HOT 3
- Remove InterruptibleProcessor and Rename FingersCrossedProcessor HOT 3
- quick question on the pipe methos HOT 2
- tag new version with processor included
- Never heard of a pattern named pipeline HOT 2
- Isn't process method available on PipelineInterface? It's expected to be there. HOT 5
- [feature request] Inject errorHandler into processor (optional) HOT 1
- [Feature Request] Attach a listener to a pipeline HOT 2
- [Feature Request] Fork-Join HOT 2
- Generator Processor HOT 1
- When to use a PipelineBuilder? HOT 1
- Simple question HOT 6
- windows is ok? HOT 2
- PipelineBuilder build returns PipelineBuilderInterface in error HOT 2
- [Feature Request] Lazily retrieve pipeline stages from PSR-11 container HOT 3
- Why do you want to clone the current object when you execute the pipe method? HOT 1
- PipelineInterface does not have a `process` method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pipeline.