Naify\Psr\Middleware\MiddlewarePipeline クラス
implements
Naify\Psr\Server\RequestHandlerInterface
PSR-15 ミドルウェアパイプライン — Middleware Dispatcher
ミドルウェアを LIFO(後入れ先出し)順で実行するパイプライン。 Slim Framework と同じ順序で動作する。
設計:
add() で追加されたミドルウェアはスタックに積まれ、
handle() 実行時に最後に追加されたものから順に process() が呼ばれる。
最も内側のハンドラ(コアハンドラ)がルーティング&ディスパッチを行う。使用例
$pipeline = new MiddlewarePipeline($coreHandler);
$pipeline->add(new ResponseHeaderMiddleware());
$pipeline->add(new ErrorMiddleware());
$response = $pipeline->handle($request);
プロパティ
| 名前 | 型 | 説明 |
|---|---|---|
private
$stack
|
array |
ミドルウェアスタック(LIFO) |
private
$coreHandler
|
RequestHandlerInterface |
最も内側のハンドラ |
メソッド
| メソッド | 説明 |
|---|---|
public
__construct(RequestHandlerInterface $coreHandler):
|
パイプラインを初期化する |
public
add(MiddlewareInterface $middleware): void
|
ミドルウェアをスタックに追加する
最後に追加されたミドルウェアが最初に実行される(LIFO)。 |
public
handle(ServerRequestInterface $request): ResponseInterface
|
パイプラインを実行する
スタックを逆順(LIFO)でチェーンし、リクエストを処理する。 |