DownloadClass 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
|