krak/mw

Middleware Framework

v0.5.2 2017-04-30 19:46 UTC

This package is auto-updated.

Last update: 2024-10-18 18:08:53 UTC


README

Author Source Code Latest Version Software License Documentation Status Total Downloads

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');

Installation

You can install this as a composer package at krak/mw

Documentation

View them at http://mw.readthedocs.io/en/latest/

Or build them:

make doc

Tests and Examples

Run tests via:

make test

The Mw library uses Peridot. These tests also provide good examples of how to use the library.