Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

ReturnMiddleware
in package
implements MiddlewareInterface

Return Middleware — nginx return directive parity.

Unconditionally returns a fixed response, like nginx return inside a location: the route handler never runs. Pair with ScopedMiddleware to limit it to a path (the nginx location { return ... } shape):

  • new ReturnMiddleware(403)return 403;
  • new ReturnMiddleware(301, '/new')return 301 /new; (Location)
  • new ReturnMiddleware(200, 'pong')return 200 "pong"; (body)

For 3xx statuses the second argument is treated as the redirect target (Location); for any other status it is the response body.

Usage in app.php:

$app->addMiddleware(ScopedMiddleware::location(new ReturnMiddleware(403), '/blocked'));
$app->addMiddleware(ScopedMiddleware::match(new ReturnMiddleware(301, '/new'), '#^/old$#'));

Table of Contents

Interfaces

MiddlewareInterface

Properties

$status  : int
$textOrUrl  : string|null

Methods

__construct()  : mixed
process()  : ResponseInterface

Properties

Methods

__construct()

public __construct(int $status[, string|null $textOrUrl = null ]) : mixed
Parameters
$status : int
$textOrUrl : string|null = null

process()

public process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
Parameters
$request : ServerRequestInterface
$handler : RequestHandlerInterface
Return values
ResponseInterface
On this page