File: README.md

Recommend this page to a friend!
  Classes of Jeremiah Ogbomo  >  Middleware  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: A basic demonstration
Class: Middleware
Run queued processes using the middleware pattern
Author: By
Last change:
Date: 5 years ago
Size: 1,111 bytes
 

Contents

Class file image Download

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


For more information send a message to info at phpclasses dot org.