Using Anonymous Classes to Write Middleware - Matthew Weier O'Phinney

Planet PHP

Guest
I faced an interesting question recently with regards to middleware: What happens when we go from a convention-based to a contract-based approach when programming?

Convention-based approaches usually allow for duck-typing; with middleware, it means you can write PHP callables — usually closures — and just expect them to work.

Contract-based approaches use interfaces. I think you can see where this is going.

PSR-7 Middleware


When PSR-7 was introduced, a number of middleware microframeworks adopted a common signature for middleware:

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

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




Читать дальше...
 
Последнее редактирование модератором:
Сверху