PHP code example of bnf / slim3-psr15

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

    

bnf / slim3-psr15 example snippets



use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;

eResolver($container);
};

/* Add a PSR-15 middleware */
$app->add(new class implements Middleware {
    public function process(Request $request, RequestHandler $handler): Response
    {
        $request = $request->withAttribute('msg', 'Hello');
        return $handler->handle($request);
    }
});

$app->get('/hello/{name}', new class implements RequestHandler {
    public function handle(Request $request): Response {
        $name = $request->getAttribute('name');
        $msg = $request->getAttribute('msg');
        $response = new \Slim\Http\Response;
        $response->getBody()->write("$msg, $name");

        return $response;
    }
});
$app->run();