Ground Sunlight

Windowsで作る - PHPプログラミングの開発環境

ユーザ用ツール

サイト用ツール


apricot:usage:ja:middleware

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

次のリビジョン
前のリビジョン
次のリビジョン 両方とも次のリビジョン
apricot:usage:ja:middleware [2020/07/29 13:28]
tanaka 作成
apricot:usage:ja:middleware [2020/08/05 09:46]
tanaka [Middleware インターフェース]
行 6: 行 6:
  --- //[[http://www.y2sunlight.com|y2sunlight]] 2020-07-29//  --- //[[http://www.y2sunlight.com|y2sunlight]] 2020-07-29//
  
-[[apricot:usage:ja|Apricotの使用法 に戻る]]+[[apricot:usage:ja|Apricot Document に戻る]]
  
 目次 目次
  
 +  * [[apricot:usage:ja:features|Apricot 特徴と概要]]
   * [[apricot:usage:ja:config|Apricot 配置と構成]]   * [[apricot:usage:ja:config|Apricot 配置と構成]]
 +  * [[apricot:usage:ja:errors-logging|Apricot ログとエラー処理]]
   * [[apricot:usage:ja:http|Apricot リクエストとレスポンス]]   * [[apricot:usage:ja:http|Apricot リクエストとレスポンス]]
   * [[apricot:usage:ja:frontend|Apricot フロントエンド]]   * [[apricot:usage:ja:frontend|Apricot フロントエンド]]
行 16: 行 18:
   * Apricot ミドルウェア   * Apricot ミドルウェア
   * [[apricot:usage:ja:controller|Apricot コントローラ]]   * [[apricot:usage:ja:controller|Apricot コントローラ]]
-  * [[apricot:usage:ja:errors-logging|Apricot ログとエラー処理]] 
   * [[apricot:usage:ja:utility|Apricot ユーティリティ]]   * [[apricot:usage:ja:utility|Apricot ユーティリティ]]
  
行 22: 行 23:
  
 ===== ミドルウェアの構成 ===== ===== ミドルウェアの構成 =====
->TODO+ 
 +本章ではミドルウェア基盤を作ります。ミドルウェアとはアクションを囲んでいる層のような存在で、ユーザからのリクエストは何層もあるミドルウェアを通って最終的にアクションにたどり着きそこでレスポンスが生成されますが、途中でリクエストが中断され、ミドルウェアがレスポンスを生成することもあります。これを図示すると以下のようになります。 
 + 
 +=== ミドルウェア構造 === 
 +{{:apricot:usage:ja:middleware:ext-fig01.svg?nolink&800}} 
 + 
 +上図のような処理のネスト構造を ''パイプライン'' (pipeline) と呼び、特に多層になったミドルウェア構造を ''ミドルウェアパイプライン'' と呼ぶ事にします。 
 + 
 +Apricotには以下のミドルウェアが実装されています。 
 + 
 +  * アクセスログ 
 +  * CSRF対策 
 +  * ユーザ認証 
 + 
 +ミドルウェアパイプラインを含めたミドルウェアの仕組みはApricotのコアの機能として実装しますが、上記のような具体的なミドルウェアの実装はアプリ側で行います。 
 + 
 +==== Middleware インターフェース ==== 
 + 
 +冒頭のミドルウェア構造の図から分かるように、ミドルウェアの役割は自分を処理の後に次のプロセッサーに制御を渡すことです。この時、プロセッサーにはミドルウェアとアクションの両方があるので、前出のInvoker インターフェースを使います。ミドルウェアは任意タイミングで Invokerを 使うことができるので、前処理、後処理またはその両方ができます。また、クライアントの要求を自分だけで消費して Invoker を使うことなく自分のレスポンスを返すことも可能です。 
 + 
 +{{fa>folder-open-o}} ** /apricot/core/Foundation/Middleware ** 
 +<code php Middleware.php> 
 +<?php 
 +namespace Apricot\Foundation\Middleware; 
 + 
 +use Apricot\Foundation\Invoker; 
 +use Apricot\Foundation\Response; 
 + 
 +/** 
 + * Middleware Interface 
 + */ 
 +interface Middleware 
 +
 +    /** 
 +     * Processes an incoming request and produces a response. 
 +     * 
 +     * @param Invoker $next Next invoker. 
 +     * @return \Apricot\Foundation\Response if return a response within this method, then don't call the next action. 
 +     */ 
 +    public function process(Invoker $next) :Response; 
 +
 +</code>
  
 \\ \\
apricot/usage/ja/middleware.txt · 最終更新: 2020/09/03 13:46 by y2sunlight