19/01
2018
dev-master
9999999-devA middlewares library
MIT
The Development Requires
by Noel Garcia
A middlewares library
A simple middlewares implementation in php. Like Damascus Steel, this is about layers, (*1)
composer require ww/damascus
class IncFooMiddleware implements Damascus\MiddlewareInterface { public function run(Damascus\DataBucketInterface $dataBucket, MiddlewareStep $next) { $dataBucket['foo'] += rand(0,12); if ($dataBucket['foo'] < 10) { $next->run($dataBucket); } } } class MailerMiddleware implements Damascus\MiddlewareInterface { private $mailer; //I'm not coding the constructor of this public function run(Damascus\DataBucketInterface $dataBucket, MiddlewareStep $next) { $this->mailer->send($dataBucket['from'], $dataBucket['to'], $dataBucket['subject'], $dataBucket['body']); } }
$middleware = ; $stack = (new Damascus\MiddlewareStack()) ->pushMiddleware(new IncFooMiddleware()) ->pushMiddleware(new MailerMiddleware());
$dataBucket = new Damascus\DataBucket([ 'from' => 'asdf@gmail.com', 'to' => 'asdf@gmail.com', 'subject' => 'threshold 10 not reached', 'body' => 'threshold 10 not reached', 'foo' => 0, ]); $stack->run($dataBucket);
I would like to create in a near future a Symfony bundle for this, allowing, using DIC tags to automatically generate middleware stacks., (*2)
A middlewares library
MIT