Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 168 | All time: 8,873 This week: 206 |
Version | License | PHP version | Categories | |||
middleware 1.0.1 | MIT/X Consortium ... | 5.5 | PHP 5, Design Patterns |
Description | Author | |||
This package can run queued processes using the middleware pattern. Innovation Award
|
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 (5) |
File | Role | Description |
---|---|---|
Middleware.php | Class | Middleware base class |
MiddlewareInterface.php | Class | Middleware objects interface |
MiddlewareObject.php | Class | Wrapper for middleware processes |
MiddlewareQueue.php | Class | Queue object class |
README.md | Doc. | A basic demonstration |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
0% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.