Skip to content

PSR-15 compatible HTTP middleware which can utilize closure type request handlers.

License

Notifications You must be signed in to change notification settings

kovagoz/http-middleware-closure-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Closure Handler Middleware

PSR-15 compatible HTTP middleware which can utilize closure type request handlers.

If you don't want to bother about those ugly HTTP controllers and love simplicity, this middleware is your best friend.

phpunit workflow

Requirements

  • PHP >=8.0

Usage

$request = $serverRequestFactory
    ->createServerRequest('GET', '/')
    ->withAttribute('__handler', fn() => 'hello world!');

$middleware = new ClosureHandler($responseFactory, $streamFactory);

$response = $middleware->process($request, $nextHandler);

echo $response->getBody(); // Will print "hello world!"

If no handler found in the request object, or handler is not closure, then the middleware passes the request to the next middleware in the row.

Name of the request attribute (__handler) can be changed by the watchRequestAttribute() method.

About

PSR-15 compatible HTTP middleware which can utilize closure type request handlers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published