PHP code example of slince / middleware

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

    

slince / middleware example snippets


$dispatcher = new Slince\Middleware\Dispatcher([$middleware1, $middleware2]);

$response = $dispatcher->process(Zend\Diactoros\ServerRequestFactory::fromGlobals());

var_dump($response instanceof Psr\Http\Message\ResponseInterface);

use Psr\Http\Message\ServerRequestInterface;
use Interop\Http\Server\MiddlewareInterface;
use Interop\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response;

class MyMiddleware implements MiddlewareInteface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $next) 
    {
        $response = new Response();
        $response->getBody()->write('hello world');
        return $response;
    }
}
$dispatcher = new Slince\Middleware\Dispatcher([
    new MyMiddleware()
]);

$dispatcher->push(function(ServerRequestInterface $request, RequestHandlerInterface $next){
    return $delegate->process($request);
});

try {
    $response = $dispatcher->process(Zend\Diactoros\ServerRequestFactory::fromGlobals());
} catch (Slince\Middleware\Exception\MissingResponseException $exception) {
    //...
}