Ground Sunlight

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

ユーザ用ツール

サイト用ツール


サイドバー

メインメニュー

XAMPP アレンジ

IED

WSL2

道具箱

リポジトリ編

フレームワーク編

公開ソフトウェア

メタ
リンク


このページへのアクセス
今日: 1 / 昨日: 0
総計: 1261

psr:psr15

文書の過去の版を表示しています。


編集中

PSR-15: HTTP Server Request Handlers

y2sunlight 2020-06-23

本章は、若干の補足を加筆してはいるものの単にPSRのサイトを日本語に翻訳したものに過ぎません。英語が堪能な方は原文をご参照下さい。翻訳に当たっては、基本的に機械翻訳を使い、理解できない部分は独断で意訳しております。拙い訳では御座いますが恥を忍んで投稿しておりますので、ご指摘など御座いましたらコメントを頂ければ幸いです。

関連記事


PSR-15: HTTPサーバーリクエストハンドラー

原文より翻訳 PSR-15: HTTP Server Request Handlers 2020-07-28 現在

このドキュメントでは、PSR-7またはその後の代替PSRで説明されているHTTPメッセージを使用するHTTPサーバーリクエストハンドラー(「リクエストハンドラー」)とHTTPサーバーミドルウェアコンポーネント(「ミドルウェア」)の一般的なインターフェースについて説明します。

HTTPリクエストハンドラーは、あらゆるWebアプリケーションの基本的な部分です。サーバー側コードは、リクエストメッセージを受信して処理し、応答メッセージを生成します。HTTPミドルウェアは、一般的なリクエストとレスポンスの処理をアプリケーション層から分離するための方法の1つです。

このドキュメントで説明するインターフェースは、リクエストハンドラーとミドルウェアを抽象化したものです。

注:「リクエストハンドラー」および「ミドルウェア」へのすべての参照は、サーバーリクエスト処理に固有なものです。

このドキュメントのキーワード MUST , MUST NOT , REQUIRED , SHALL , SHALL NOT , SHOULD , SHOULD NOT , RECOMMENDED , MAY 及び OPTIONAL は、 RFC 2119で説明されているように解釈して下さい。

RFC 2119の説明
MUST, REQUIRED, SHALL — 絶対必要
MUST NOT, SHALL NOT — 絶対禁止
SHOULD, RECOMMENDED — 推奨(但し、無視できる特定の正当な理由が存在するかもしれない)
SHOULD NOT — 推奨できない(但し、許可できる特定の正当な理由が存在するかもしれない)
MAY, OPTIONAL — オプション

References

  • PSR-7 ・・・ HTTP message interfaces
  • RFC 2119 ・・・ Key words for use in RFCs to Indicate Requirement Levels


1. 仕様

1.1 リクエストハンドラー

A request handler is an individual component that processes a request and produces a response, as defined by PSR-7.

リクエストハンドラーは、PSR-7で定義されているように、リクエストを処理して応答を生成する個別のコンポーネントです。

A request handler MAY throw an exception if request conditions prevent it from producing a response. The type of exception is not defined.

リクエスト条件によりリクエストハンドラーがレスポンスを生成できない場合、リクエストハンドラーは例外をスローする場合があります( MAY )。例外のタイプは定義されていません。

Request handlers using this standard MUST implement the following interface:

この規約を使用するリクエストハンドラーは、次のインターフェースを実装する必要があります( MUST ):

  • Psr\Http\Server\RequestHandlerInterface


1.2 ミドルウェア

A middleware component is an individual component participating, often together with other middleware components, in the processing of an incoming request and the creation of a resulting response, as defined by PSR-7.

ミドルウェアコンポーネントは、個別のコンポーネントですが、PSR-7で定義されているように、着信要求の処理と結果の応答の作成に他のミドルウェアコンポーネントと一緒に参加することが多いです。

A middleware component MAY create and return a response without delegating to a request handler, if sufficient conditions are met.

ミドルウェアコンポーネントは、十分な条件が満たされている場合、リクエストハンドラーに委任することなく応答を作成して返すことができます( MAY )。

Middleware using this standard MUST implement the following interface:

この規約を使用するミドルウェアは、次のインターフェースを実装する必要があります( MUST ):

  • Psr\Http\Server\MiddlewareInterface


1.3 レスポンスの生成

It is RECOMMENDED that any middleware or request handler that generates a response will either compose a prototype of a PSR-7 ResponseInterface or a factory capable of generating a ResponseInterface instance in order to prevent dependence on a specific HTTP message implementation.

応答を生成するミドルウェアまたはリクエストハンドラーは、PSR-7の ResponseInterface プロトタイプまたは ResponseInterface インスタンスを生成できるファクトリーを構成することをお勧めします( RECOMMENDED )。それは、特定のHTTPメッセージの実装への依存を防ぐためです。


1.4 例外のハンドリング

It is RECOMMENDED that any application using middleware includes a component that catches exceptions and converts them into responses. This middleware SHOULD be the first component executed and wrap all further processing to ensure that a response is always generated.

ミドルウェアを使用するアプリケーションは、例外をキャッチしてそれらをレスポンスに変換するコンポーネントを含むことが推奨されます( RECOMMENDED )。このミドルウェアは、最初に実行されるコンポーネントであり、すべての他の処理をラップすべきです( SHOULD )。それは、レスポンスが常に生成されることを保証するためです。


2. インターフェース

2.1 Psr\Http\Server\RequestHandlerInterface

The following interface MUST be implemented by request handlers.

リクエストハンドラーは次のインターフェースを実装する必要があります( MUST )。

RequestHandlerInterface.php
namespace Psr\Http\Server;
 
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
 
/**
 * Handles a server request and produces a response.
 * サーバーリクエストを処理し、レスポンスを生成します。
 *
 * An HTTP request handler process an HTTP request in order to produce an
 * HTTP response.
 * HTTPリクエストハンドラーは、HTTPレスポンスを生成するためにHTTPリクエストを処理します。
 */
interface RequestHandlerInterface
{
    /**
     * Handles a request and produces a response.
     * リクエストを処理し、レスポンスを生成します。
     *
     * May call other collaborating code to generate the response.
     * レスポンスを生成するために、他の協調するコードを呼び出すことができます。
     */
    public function handle(ServerRequestInterface $request): ResponseInterface;
}


2.2 Psr\Http\Server\MiddlewareInterface

The following interface MUST be implemented by compatible middleware components.

互換性のあるミドルウェアコンポーネントは次のインターフェースを実装する必要があります( MUST )。

MiddlewareInterface.php
namespace Psr\Http\Server;
 
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
 
/**
 * Participant in processing a server request and response.
 * サーバーのリクエストとレスポンスを処理する参加者。
 *
 * An HTTP middleware component participates in processing an HTTP message:
 * by acting on the request, generating the response, or forwarding the
 * request to a subsequent middleware and possibly acting on its response.
 * HTTPミドルウェアコンポーネントは、HTTPメッセージの処理に参加します:
 * つまり、リクエストに基づいて動作するか、レスポンスを生成するか、
 * またはリクエストを後続のミドルウェアに転送し、場合によってはそのレスポンスに基づいて動作します。
 */
interface MiddlewareInterface
{
    /**
     * Process an incoming server request.
     * 着信サーバー要求を処理します。
     *
     * Processes an incoming server request in order to produce a response.
     * If unable to produce the response itself, it may delegate to the provided
     * request handler to do so.
     * レスポンスを生成するために、着信サーバーリクエストを処理します。
     * レスポンス自体を生成できない場合は、それをするのに提供されたリクエストハンドラーに委任します。
     */
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;
}


コメント

コメントを入力. Wiki文法が有効です:
 
psr/psr15.1595916449.txt.gz · 最終更新: 2020/07/28 15:07 by y2sunlight