2017 © Pedro Peláez
 

library php-middleware

Generalized middleware implementation for PHP.

image

hypercharge/php-middleware

Generalized middleware implementation for PHP.

  • Monday, January 27, 2014
  • by hypercharge
  • Repository
  • 9 Watchers
  • 5 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Middleware

This is a generalized library for using middleware patterns within your PHP projects., (*1)

php-middleware is a PHP port of the ruby middleware library., (*2)

Only a subset of ruby middleware is implemented yet. Stay tuned to see more features ported., (*3)

To get started, the best place to look is the user guide., (*4)

Build Status, (*5)

Installation

This project is distributed as a composer package., (*6)

in your project root folder create a composer.json file, (*7)

{
  "require": {
    "hypercharge/php-middleware": "dev-master"
  }
}
````
In a shell `cd` to your project root folder and run the command
```console
$ php composer.phar install

A Basic Example

Below is a basic example of the library in use. If you don't understand what middleware is, please read the ruby middleware doc. This example is simply meant to give you a quick idea of what the library looks like., (*8)

<?php
// basic env instance class
class LogEnv {
    public $log = array();

    public function to_string() {
        return join($this->log, "\n");
    }
}

// Basic middleware that just logs the inbound and
// outbound steps to env
class Trace implements Middleware\Middleware {
    private $app;
    private $value;
    public function __construct($app, $value) {
        $this->app = $app;
        $this->value = $value;
    }
    public function call($env) {
        $env->log[] = '--> '.$this->value;
        $this->app->call($env);
        $env->log[] = '<-- '.$this->value;
    }
}

// the env object passed to each middleware call($env) method
$env = new LogEnv();

// build the actual middleware stack which runs a sequence
// of slightly different versions of our middleware
$stack = new Middleware\Builder();
$stack
    ->uses('Trace', 'A')
    ->uses('Trace', 'B')
    ->uses('Trace', 'C');

// run it
$stack->call($env);

echo $env->to_string();

And the output:, (*9)

--> A
--> B
--> C
<-- C
<-- B
<-- A

Run The Tests

$ ./vendor/bin/phpunit

The Versions

27/01 2014

dev-master

9999999-dev

Generalized middleware implementation for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Jan Mentzel

middleware php