2017 © Pedro Peláez
 

library psr7-adapter

A PSR-7 middleware bridge for PHP-PM

image

php-pm/psr7-adapter

A PSR-7 middleware bridge for PHP-PM

  • Thursday, November 30, 2017
  • by franzliedke
  • Repository
  • 5 Watchers
  • 28 Stars
  • 507 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

[OBSOLETE] PSR-7 compatibility is now built into php-pm directly., (*1)

PHP-PM PSR-7 Adapter

PSR-7 adapter for use of PSR-7 middleware applications with PHP-PM. See https://github.com/php-pm/php-pm., (*2)

Setup

composer require php-pm/psr7-adapter

Usage

PPM bootstraps your application once, and then passes all incoming requests to this instance. This instance needs to be a PSR-7 compatible interface, which means it needs to implement the following interface:, (*3)

public function __invoke($request, $response, $next = null)

So, to be compatible with this adapter, you need to implement a class that, when instantiated, sets up your application, and implements the __invoke method as described above., (*4)

For example, if you use Zend's Stratigility library, your bootstrapper could look like this:, (*5)

namespace Your\App;

use Zend\Stratigility\MiddlewarePipe;

class Middleware
{
    protected $pipe;

    public function __construct()
    {
        // Set up the application

        $this->pipe = new MiddlewarePipe;

        $this->pipe->pipe(new MyFirstMiddleware);
        $this->pipe->pipe(new MySecondMiddleware);
        $this->pipe->pipe(new MyThirdMiddleware);
    }

    public function __invoke($request, $response, $next = null)
    {
        $middleware = $this->pipe;
        return $middleware($request, $response, $next);
    }
}

Starting the server

When starting PPM, pass your middleware as the bootstrapper:, (*6)

vendor/bin/ppm start --bridge=PHPPM\\Psr7\\Psr7Bridge --bootstrap=Your\\App\\Middleware

Alternatively, first configure PPM to use these options by default, and then start it directly:, (*7)

vendor/bin/ppm config --bridge=PHPPM\\Psr7\\Psr7Bridge --bootstrap=Your\\App\\Middleware
vendor/bin/ppm start

The Versions

30/11 2017

dev-master

9999999-dev

A PSR-7 middleware bridge for PHP-PM

  Sources   Download

MIT

The Requires