このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 次のリビジョン 両方とも次のリビジョン | ||
apricot:usage:ja:middleware [2020/08/03 12:17] tanaka [ミドルウェアの構成] |
apricot:usage:ja:middleware [2020/08/05 09:46] tanaka [Middleware インターフェース] |
||
---|---|---|---|
行 6: | 行 6: | ||
--- // | --- // | ||
- | [[apricot: | + | [[apricot: |
目次 | 目次 | ||
+ | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
+ | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
行 16: | 行 18: | ||
* Apricot ミドルウェア | * Apricot ミドルウェア | ||
* [[apricot: | * [[apricot: | ||
- | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
行 26: | 行 27: | ||
=== ミドルウェア構造 === | === ミドルウェア構造 === | ||
- | {{:apricot:ext: | + | {{:apricot:usage: |
上図のような処理のネスト構造を '' | 上図のような処理のネスト構造を '' | ||
行 40: | 行 41: | ||
==== Middleware インターフェース ==== | ==== Middleware インターフェース ==== | ||
- | 冒頭の[[#ミドルウェア構造|ミドルウェア構造]]の図から分かるように、ミドルウェアの役割は自分を処理の後に次のプロセッサーに制御を渡すことです。この時、プロセッサーにはミドルウェアとアクションの両方があるので、前出の | + | 冒頭のミドルウェア構造の図から分かるように、ミドルウェアの役割は自分を処理の後に次のプロセッサーに制御を渡すことです。この時、プロセッサーにはミドルウェアとアクションの両方があるので、前出のInvoker インターフェースを使います。ミドルウェアは任意タイミングで Invokerを 使うことができるので、前処理、後処理またはその両方ができます。また、クライアントの要求を自分だけで消費して Invoker を使うことなく自分のレスポンスを返すことも可能です。 |
{{fa> | {{fa> | ||
<code php Middleware.php> | <code php Middleware.php> | ||
<?php | <?php | ||
- | namespace | + | namespace |
- | use Core\Foundation\Invoker; | + | use Apricot\Foundation\Invoker; |
- | use Core\Foundation\Response; | + | use Apricot\Foundation\Response; |
/** | /** | ||
行 56: | 行 57: | ||
{ | { | ||
/** | /** | ||
- | | + | |
- | * @param Invoker $next Next invoker | + | * |
- | * @return \Core\Foundation\Response if return response, then don'true call next action | + | * @param Invoker $next Next invoker. |
+ | * @return \Apricot\Foundation\Response if return | ||
*/ | */ | ||
public function process(Invoker $next) :Response; | public function process(Invoker $next) :Response; |