northwoods / conditional-middleware
Middleware proxy for request condition checks
Installs: 2 272
Dependents: 0
Suggesters: 1
Security: 0
Stars: 3
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^7.1
- psr/http-server-middleware: ^1.0
Requires (Dev)
- nyholm/psr7: ^1.0
- phpstan/phpstan: ^0.10.3
- phpstan/phpstan-phpunit: ^0.10.0
- phpunit/phpunit: ^7.3
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-12-18 04:18:57 UTC
README
Middleware proxy that executes a middleware based on request conditions.
Installation
The best way to install and use this package is with composer:
composer require northwoods/conditional-middleware
Usage
use Northwoods\Middleware\ConditionalMiddleware; /** @var \Psr\Http\Server\MiddlewareInterface */ $actual = /* any existing middleware */ $middleware = new ConditionalMiddleware($actual, function (Request $request): bool { return $request->getHeaderLine('accept') === 'application/json'; });
In this example, the wrapped $actual
middleware will only be executed if the
request accepts the application/json
content type.
Condition Callable
The condition callable should use the following signature:
function (Request $request): bool;
The condition must return true
(by strict ===
comparison) for the wrapped
middleware to be executed. If the condition check fails the handler will be
called immediately.