PHP Classes
elePHPant
Icontem

Middleware: Run queued processes using the middleware pattern

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-04-13 (6 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 146 This week: 1All time: 8,195 This week: 1,047Up
Version License PHP version Categories
middleware 1.0.1MIT/X Consortium ...5.5PHP 5, Design Patterns
Description Author

This package can run queued processes using the middleware pattern.

A queue class can add middleware objects or closure functions to a queue to be executed on the first in, first out basis.

The queue class can take the middleware objects from the queue, call them and return the responses.

The middleware objects can execute the next object in the queue.

Innovation Award
PHP Programming Innovation award nominee
February 2016
Number 3


Prize: One ebook of choice by Packt
Middleware is a piece of software that connects different pieces of software to perform a certain action.

This package implements generic middle functionality for the process of queuing and processing a certain task using middleware objects and returning the results to the calling code.

Manuel Lemos
Picture of Jeremiah Ogbomo
  Performance   Level  
Name: Jeremiah Ogbomo <contact>
Classes: 3 packages by
Country: Nigeria Nigeria
Innovation award
Innovation award
Nominee: 2x

Details

Class Application {
  function __construct(){
    $this->request = [];
    $this->response = [];
    // or
    $this->request = new \stdClass;
    $this->response = new \stdClass;
  }
}

$application = new Application;

or

$application = new \stdClass()
$application->request = new \stdClass()
$application->response = new \stdClass()

$MiddlewareQueue = new MiddlewareQueue($application);

$MiddlewareQueue->add(function($req, $res, $next){
  echo 'A ';
  $next();
  echo 'A_2 ';
});
 
Class OneMiddleware extends Middleware {
  public function call(){
    echo 'B ';
    $this->next->call();
    echo 'B_2 ';
  }
}
$MiddlewareQueue->add(new OneMiddleware);

Class Two {
  public function call(){
    echo 'C ';
    $this->next->call();
    echo 'C_2 ';
  }
}
$MiddlewareQueue->add(new Two);

$MiddlewareQueue->add(function($req, $res, $next){
  echo 'D ->';
  $next();
  echo 'D_2 ';
});

$MiddlewareQueue->run();

RESULT:

A B C D -> D_2 C_2 B_2 A_2

  Files folder image Files  
File Role Description
Plain text file Middleware.php Class Middleware base class
Plain text file MiddlewareInterface.php Class Middleware objects interface
Plain text file MiddlewareObject.php Class Wrapper for middleware processes
Plain text file MiddlewareQueue.php Class Queue object class
Accessible without login Plain text file README.md Doc. A basic demonstration

 Version Control Unique User Downloads Download Rankings  
 0%
Total:146
This week:1
All time:8,195
This week:1,047Up