2017 © Pedro Peláez
 

library http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

image

webimpress/http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

  • Sunday, November 12, 2017
  • by webimpress
  • Repository
  • 3 Watchers
  • 10 Stars
  • 147,597 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 25 % Grown

The README.md

http-middleware-compatibility

Build Status, (*1)

Purpose

The purpose of the library is to deliver consistent interface for different versions of http-interop/http-middleware which implements Draft of PSR-15 HTTP Middleware., (*2)

Many projects currently use different version of library http-interop/http-middleware and updating to newest version requires usually major release. The library lets consumers of your component decide what version of http-interop/http-middleware they want to use and allow them to migrate to the latest version at any time., (*3)

Usage

Your middleware should implement interface Webimpress\HttpMiddlewareCompatibility\MiddlewareInterface, and for delegator/request handler you should use interface Webimpress\HttpMiddlewareCompatibility\HandlerInterface., (*4)

<?php

namespace MyNamespace;

use Psr\Http\Message\ServerRequestInterface;
use Webimpress\HttpMiddlewareCompatibility\HandlerInterface;
use Webimpress\HttpMiddlewareCompatibility\MiddlewareInterface;

class MyMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, HandlerInterface $handler)
    {
        // ...
    }
}

Both interfaces are just aliases. It allows your middleware to work with currently installed version of http-interop/http-middleware library., (*5)

Delegate/Handler method

The method name was changed across the different versions of http-interop/http-middleware. First the method was called next (release 0.1.1), then process (from 0.2 - 0.4.1) and then handle (in 0.5.0). To accomplish all of them we provide constant Webimpress\HttpMiddlewareCompatibility\HANDLER_METHOD, which has appropriate value depends on used version of http-middleware. Here is an example how you can use it in your middleware:, (*6)

<?php

namespace MyNamespace;

use Psr\Http\Message\ServerRequestInterface;
use Webimpress\HttpMiddlewareCompatibility\HandlerInterface;
use Webimpress\HttpMiddlewareCompatibility\MiddlewareInterface;

use const Webimpress\HttpMiddlewareCompatibility\HANDLER_METHOD;

class MyMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, HandlerInterface $handler)
    {
        return $handler->{HANDLER_METHOD}($request);
    }
}

That's it! Now consumers of your component can decide what version of http-interop/http-middleware they want to use., (*7)

The Versions

12/11 2017

dev-feature/http-server-middleware

dev-feature/http-server-middleware https://github.com/webimpress/http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

middleware psr-15 webimpress

17/10 2017

dev-master

9999999-dev https://github.com/webimpress/http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

middleware psr-15 webimpress

17/10 2017

0.1.4

0.1.4.0 https://github.com/webimpress/http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

middleware psr-15 webimpress

12/10 2017

0.1.3

0.1.3.0 https://github.com/webimpress/http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

middleware psr-15 webimpress

11/10 2017

0.1.2

0.1.2.0 https://github.com/webimpress/http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

middleware psr-15 webimpress

05/10 2017

0.1.1

0.1.1.0 https://github.com/webimpress/http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

middleware psr-15 webimpress

05/10 2017

0.1.0

0.1.0.0 https://github.com/webimpress/http-middleware-compatibility

Compatibility library for Draft PSR-15 HTTP Middleware

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

middleware psr-15 webimpress