techworker/middleware

PSR-7 middleware function for building and dispatching middlewares.

v1.0.1 2017-05-04 00:11 UTC

This package is auto-updated.

Last update: 2024-10-25 10:21:58 UTC


README

This library provides a single function to implement a PHP 7 middleware workflow for your PHP applications.

It is heavily inspired from the relay php implementation by Paul M. Jones

Usage

Import the function and define a list of middlewares.

<?php

use Psr7Middlewares\Middleware;
use Psr7Middlewares\Middleware\ErrorHandler;

use function Techworker\Functional\middleware;

/**
 * This function checks whether the 'Authorization' is given.
 */
$middleware1 = function(
    \Psr\Http\Message\ServerRequestInterface $request,
    \Psr\Http\Message\ResponseInterface $response,
    callable $next
) {
    return $next($request, $response);
};

$middlewares = [$middleware1, \Psr7Middlewares\Middleware::uuid()];

middleware($request, $response, $middlewares);

Installation

Add this to your composer.json

"require": {
	"techworker/middleware": "^1.0"
}

.. or use the following command on your command line:

composer require techworker/middleware