PHP code example of jasny / dummy-middleware

1. Go to this page and download the library: Download jasny/dummy-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/ */

    

jasny / dummy-middleware example snippets


use Jasny\Dummy\ServerMiddleware;
use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\ResponseFactory;

$middleware = new ServerMiddleware();

$app = new MiddlewarePipe();
$app->pipe($middleware);

fn(ServerRequestInterface $request, ResponseInterface $response, callable $next): ResponseInterface

use Jasny\Dummy\ServerMiddleware;
use Relay\RelayBuilder;

$middleware = new ServerMiddleware();

$relayBuilder = new RelayBuilder($resolver);
$relay = $relayBuilder->newInstance([
    $middleware->asDoublePass(),
]);

$response = $relay($request, $baseResponse);

fn(RequestInterface $request, ResponseInterface $response, callable $next): ResponseInterface

use Relay\RelayBuilder;
use Jasny\Dummy\ClientMiddleware;

$middleware = new ClientMiddleware();

$relayBuilder = new RelayBuilder($resolver);
$relay = $relayBuilder->newInstance([
    $middleware->asDoublePass(),
]);

$response = $relay($request, $baseResponse);

use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client;
use Jasny\Dummy\ClientMiddleware;

$middleware = new ClientMiddleware();

$stack = new HandlerStack();
$stack->push($middleware->forGuzzle());

$client = new Client(['handler' => $stack]);

use Http\Discovery\HttpClientDiscovery;
use Http\Client\Common\PluginClient;
use Jasny\Dummy\ClientMiddleware;

$middleware = new ClientMiddleware();

$pluginClient = new PluginClient(
    HttpClientDiscovery::find(),
    [
        $middleware->forHttplug(),
    ]
);