PHP code example of pawel-jakowczyk / middleware

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

    

pawel-jakowczyk / middleware example snippets



use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequest;
use PJ\Middleware\AttributeNames;
use PJ\Middleware\HandlerFactory;
use PJ\Middleware\MiddlewareFactoryRequestHandler;
use PJ\Middleware\EmptyMiddlewareFactory;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\RequestHandlerInterface;

(new MiddlewareFactoryRequestHandler())->handle(
    (new ServerRequest())
        ->withAttribute(
            AttributeNames::MIDDLEWARE_FACTORY,
            new EmptyMiddlewareFactory()
        )
        ->withAttribute(
            AttributeNames::HANDLER_FACTORY,
            new class () implements HandlerFactory {
                public function createRequestHandler(): RequestHandlerInterface
                {
                    return new class() implements RequestHandlerInterface
                    {
                        public function handle(ServerRequestInterface $request): ResponseInterface
                        {
                            return new Response();
                        }
                    };
                }
            }
        )
);