PHP code example of waglpz / webapp-middleware
1. Go to this page and download the library: Download waglpz/webapp-middleware library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
waglpz / webapp-middleware example snippets
$request;
\assert($request instanceof \Psr\Http\Message\ServerRequestInterface);
$middleware_1;
\assert($middleware_1 instanceof Waglpz\Webapp\Middleware\Middleware);
$middleware_2;
\assert($middleware_2 instanceof Waglpz\Webapp\Middleware\Middleware);
$middleware_3;
\assert($middleware_3 instanceof Waglpz\Webapp\Middleware\Middleware);
$finnaly;
\assert(\is_callable($finnaly));
$middlewares = [
$middleware_1,// execute first
$middleware_2,// execute second
$middleware_3 // executes third
];
$middlewareStack = new Waglpz\Webapp\Middleware\MiddlewareStack($middlewares);
$response = $middlewareStack($request);
// or exact same as manual call
$response = $middleware_1(
$request,
fn ($request) => $middleware_2(
$request,
fn ($request) => $middleware_3(
$request,
fn ($request) => $finnaly(
$request
)
)
)
);
\assert($response instanceof \Psr\Http\Message\ResponseInterface)