Framework Agnostic Middleware Library
The Mw library is a very flexible framework for converting middleware into handlers. Middleware offer a clean syntax for implementing the Decorator Pattern
<?php
use Krak\Mw;
$handler = mw\compose([
function($s, $next) {
return strtoupper($s);
},
function($s, $next) {
return 'x' . $next($s . 'x');
}
]);
$res = $handler('abc');
assert($res == 'xABCX');
You can install this as a composer package at krak/mw
View them at http://mw.readthedocs.io/en/latest/
Or build them:
make doc
Run tests via:
make test
The Mw library uses Peridot. These tests also provide good examples of how to use the library.