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 (3 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 165 All time: 8,614 This week: 386Up
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
  Performance   Level  
Name: Jeremiah Ogbomo <contact>
Classes: 3 packages by
Country: Nigeria Nigeria
Age: 25
All time rank: 352022 in Nigeria Nigeria
Week rank: 745 Up6 in Nigeria Nigeria Up
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:165
This week:0
All time:8,614
This week:386Up