siriusphp / invokator
Library that implements a unified way to execute a list of commands/callables that are used by various patterns: events, pipelines, middleware etc
Requires
- php: ^8.0|^8.1|^8.2
- psr/container: ^2.0
- psr/event-dispatcher: ^1.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.6
Provides
README
Sirius Invokator is a library that implements a unified way to execute a list of commands/callables that are used by various patterns:
- middlewares
- pipelines
- events
- command bus (with middleware)
- actions a la Wordpress
- filters a la Wordpress
All of the above patterns have in common that they are actually a list of callables, and they differ in the way they are executed in different ways.
In the case of middlewares, the starting parameter (eg: a HTTP request) is passed from one callable to the next, each callable having the option to terminate with a result or call the next callable in the list.
In the case of pipelines, the result of each callable is passed to the next callable and the last callable will return the result of the pipeline
In the case of events, an event
object is passed through each callable in the list and each callable is independent.
In th case of the command buss, a command
object is sent to be handled by only one callable.
Elevator pitch
use Sirius\Invokator\Invoker; use Sirius\Invokator\Processors\PipelineProcessor; use Sirius\Invokator\CallableCollection; $container = app(); // your application DI container $invoker = new Invoker($container) $processor = new PipelineProcessor($invoker); $processor->add('pipeline_name', 'trim'); $processor->add('pipeline_name', 'Str::toUppercase'); $processor->add('pipeline_name', function($value) { // anonymous function return $value . '!!!'; }); $processor->add('pipeline_name', 'Logger@info'); $processor->process('pipeline_name', " hello world "); // returns `HELLO WORLD!!!`