Ground Sunlight

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

ユーザ用ツール

サイト用ツール


psr:psr11

差分

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

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

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
psr:psr11 [2020/06/24 09:05]
y2sunlight [1.1 基本]
psr:psr11 [2020/09/01 11:53] (現在)
tanaka [PSR-11: Container interface]
行 3: 行 3:
  --- //[[http://www.y2sunlight.com|y2sunlight]] 2020-05-25//  --- //[[http://www.y2sunlight.com|y2sunlight]] 2020-05-25//
  
-本章は、若干の補足を加筆してはいるものの単に[[https://www.php-fig.org/psr/|PSRのサイト]]を翻訳したものに過ぎません。英語が堪能な方は原文をご参照下さい。翻訳に当たっては、基本的に機械翻訳を使い、理解できない部分は独断で意訳しております。拙い訳では御座いますが恥を忍んで投稿しておりますので、ご指摘など御座いましたらコメントを頂ければ幸いです。+本章は、若干の補足を加筆してはいるものの単に[[https://www.php-fig.org/psr/|PSRのサイト]]を日本語に翻訳したものに過ぎません。英語が堪能な方は原文をご参照下さい。翻訳に当たっては、基本的に機械翻訳を使い、理解できない部分は独断で意訳しております。拙い訳では御座いますが恥を忍んで投稿しておりますので、ご指摘など御座いましたらコメントを頂ければ幸いです。 
 + 
 +関連記事
  
-==== 目次 ==== 
   * [[psr:top|PSR - PHP標準勧告]]   * [[psr:top|PSR - PHP標準勧告]]
   * [[psr:psr1|PSR-1: Basic Coding Standard - 基本コーディング規約]]   * [[psr:psr1|PSR-1: Basic Coding Standard - 基本コーディング規約]]
行 14: 行 15:
   * [[psr:psr7|PSR-7: HTTP Message Interface - HTTPメッセージインターフェイス]]    * [[psr:psr7|PSR-7: HTTP Message Interface - HTTPメッセージインターフェイス]] 
   * PSR-11: Container Interface - コンテナインターフェイス   * PSR-11: Container Interface - コンテナインターフェイス
-  * [[psr:psr12|PSR-12: Extended Coding Style Guide - 拡張コーディングスタイルガイド]] +  * [[psr:psr12|PSR-12: Extended Coding Style - 拡張コーディングスタイル]] 
   * [[psr:psr13|PSR-13: Link definition interfaces - リンク定義インターフェース]]   * [[psr:psr13|PSR-13: Link definition interfaces - リンク定義インターフェース]]
   * [[psr:psr14|PSR-14: Event Dispatcher - イベントディスパッチャー]]    * [[psr:psr14|PSR-14: Event Dispatcher - イベントディスパッチャー]] 
-  * [[psr:psr15|PSR-15: HTTP Handlers - HTTPハンドラー]] +  * [[psr:psr15|PSR-15: HTTP Server Request Handlers - HTTPサーバーリクエストハンドラー]]  
 +  * [[psr:psr16|PSR-16: Common Interface for Caching Libraries - キャッシングライブラリのための共通インターフェース]]  
 +  * [[psr:psr17|PSR-17: HTTP Factories - HTTPファクトリー]]  
 +  * [[psr:psr18|PSR-18: HTTP Client - HTTPクライアント]]  
 +  * [[psr:psr19|PSR-19: PHPDoc tags(Draft) - PHPDocタグ]] 
  
 ----- -----
行 38: 行 43:
 > ''MAY'', ''OPTIONAL'' --- オプション > ''MAY'', ''OPTIONAL'' --- オプション
  
-このドキュメントの「インプリメンター」という言葉は、依存性注入に関連するライブラリまたはフレームワークに ContainerInterface を実装している人のことと解釈して下さい。依存性注入コンテナー(DIC)の利用者はユーザーと呼びます。+このドキュメントの「インプリメンター」という言葉は、依存性注入に関連するライブラリまたはフレームワークに ''ContainerInterface'' を実装している人のことと解釈して下さい。依存性注入コンテナー(DIC)の利用者はユーザーと呼びます。
  
 \\ \\
行 55: 行 60:
   * Psr\Container\ContainerInterfaceは、''get'' と ''has'' の2つのメソッドを公開しています。   * Psr\Container\ContainerInterfaceは、''get'' と ''has'' の2つのメソッドを公開しています。
  
-  * get takes one mandatory parameter: an entry identifier, which MUST be a string. get can return anything (a mixed value), or throw a NotFoundExceptionInterface if the identifier is not known to the container. Two successive calls to get with the same identifier SHOULD return the same value. However, depending on the implementor design and/or user configuration, different values might be returned, so user SHOULD NOT rely on getting the same value on 2 successive calls.\\ \\ getは、必須のパラメータを1つ取ります:そはエントリ識別子で文字列でなければなりません (''MUST'')。 getは何でもを返すことができ( mixed value )、識別子がコンテナに認識されない場合はNotFoundExceptionInterfaceをスローできます。 同じ識別子で取得する2つの連続した呼び出しは、同じ値を返すべきです (''SHOULD'')。 ただし、実装者の設計やユーザー設定によっては、異なる値が返される可能性があるため、ユーザーは2つの連続した呼び出しで同じ値を取得することに依存すべきではありません (''SHOULD NOT'')。+  * ''get'' は、必須のパラメータを1つ取ります:そのパラメータはエントリ識別子で文字列でなければなりません ( ''MUST'' )。 ''get'' は何でもを返すことができ( ''mixed'' value )、識別子がコンテナに認識されない場合は''NotFoundExceptionInterface'' をスローできます。同じ識別子で取得する2つの連続した呼び出しは、同じ値を返すべきです ( ''SHOULD'' )。 ただし、実装者の設計やユーザー設定によっては、異なる値が返される可能性があるため、ユーザーは2つの連続した呼び出しで同じ値を取得することに依存すべきではありません ( ''SHOULD NOT'' )。
  
-  * has takes one unique parameter: an entry identifier, which MUST be a string. has MUST return true if an entry identifier is known to the container and false if it is not. If has($id) returns false, get($id) MUST throw a NotFoundExceptionInterface.\\ \\ hasは、一意のパラメータを1つ取ります:そはエントリ識別子で文字列でなければなりません (''MUST'')。 hasはエントリ識別子がコンテナに認識されている場合はtrueを、認識されていない場合はfalseを返す必要があります (''MUST'')。 has($id)がfalseを返す場合、get($id)はNotFoundExceptionInterfaceをスローする必要があります (''MUST'')。+  * ''has'' は、一意のパラメータを1つ取ります:そのパラメータはエントリ識別子で文字列でなければなりません ( ''MUST'' )。''has'' はエントリ識別子がコンテナに認識されている場合は ''true'' を、認識されていない場合は ''false'' を返す必要があります ( ''MUST'' )。''has($id)'' が ''false'' を返す場合、''get($id)'' ''NotFoundExceptionInterface'' をスローする必要があります ( ''MUST'' )。
  
 \\ \\
行 63: 行 68:
 ==== 1.2 例外 ===== ==== 1.2 例外 =====
  
-Exceptions directly thrown by the container SHOULD implement the Psr\Container\ContainerExceptionInterface.+コンテナによって直接スローされる例外は [[#3.2. Psr\Container\ContainerExceptionInterface|Psr\Container\ContainerExceptionInterface]] を実装すべきです ( ''SHOULD'' )。
  
-コンテナによって直接スローされる例外は、Psr\Container\ContainerExceptionInterfaceを実装すべきです (''SHOULD'')。 +存在しないIDでgetメソッドを呼び出すと、[[#3.3. Psr\Container\NotFoundExceptionInterface|Psr\Container\NotFoundExceptionInterface]] がスローる必要があります ( ''MUST'' )。
- +
-A call to the get method with a non-existing id MUST throw a Psr\Container\NotFoundExceptionInterface. +
- +
-存在しないIDでgetメソッドを呼び出すと、Psr\Container\NotFoundExceptionInterfaceがスローされる必要があります (''MUST'')。+
  
 \\ \\
行 75: 行 76:
 ==== 1.3 推奨される使用法 ===== ==== 1.3 推奨される使用法 =====
  
-Users SHOULD NOT pass a container into an object so that the object can retrieve its own dependenciesThis means the container is used as a Service Locator which is a pattern that is generally discouraged.+オブジェクトが独自の依存関係を取得できるように、ユーザーはコンテナをオブジェクトに渡すべきではありません ( ''SHOULD NOT'' )。つまり、コンテナーを[[https://en.wikipedia.org/wiki/Service_locator_pattern|サービスロケーター]]として使用することは、一般的には推奨されないパターンです。
  
-オブジェクトが独自の依存関係を取得できるように、ユーザーはコンテナをオブジェクトに渡すべきではありません (''SHOULD NOT'')。 つまり、コンテナーをサービスロケーターとして使用することは、一般的には推奨されないパターンです。 +詳細については、METAドキュメントの[[https://www.php-fig.org/psr/psr-11/meta/#4-recommended-usage-container-psr-and-the-service-locator|セクション4]]を参照してください。
- +
-Please refer to section 4 of the META document for more details. +
- +
-詳細については、METAドキュメントのセクション4を参照してください。+
  
 \\ \\
行 87: 行 84:
 ===== 2. パッケージ ===== ===== 2. パッケージ =====
  
-The interfaces and classes described as well as relevant exceptions are provided as part of the psr/container package. +説明されているインターフェースとクラス、および関連する例外は、[[https://packagist.org/packages/psr/container|psr/container]] パッケージの一部として提供されます。
- +
-説明されているインターフェースとクラス、および関連する例外は、psr/containerパッケージの一部として提供されます。 +
- +
-Packages providing a PSR container implementation should declare that they provide psr/container-implementation 1.0.0. +
- +
-PSRコンテナーの実装を提供するパッケージは、psr/container-implementation 1.0.0を提供することを宣言する必要があります。+
  
-Projects requiring an implementation should require psr/container-implementation 1.0.0.+PSRコンテナーの実装を提供するパッケージは、''psr/container-implementation'' ''1.0.0'' を提供することを宣言する必要があります。
  
-実装が必要なプロジェクトでは、psr/container-implementation 1.0.0をrequireする必要があります。+実装が必要なプロジェクトでは、''psr/container-implementation'' ''1.0.0'' を 要求する必要があります。
  
 \\ \\
行 119: 行 110:
      * 識別子によってコンテナのエントリを検索して返します。      * 識別子によってコンテナのエントリを検索して返します。
      *      *
-     * @param string $id Identifier of the entry to look for. +     * @param string $id 検索するエントリの識別子
-     *          検索するエントリの識別子+
      *      *
-     * @throws NotFoundExceptionInterface  No entry was found for **this** identifier. +     * @throws NotFoundExceptionInterface  この識別子のエントリが見つかりませんでした 
-     *                   この識別子のエントリが見つかりませんでした +     * @throws ContainerExceptionInterface エントリの取得中にエラーが発生しました
-     * @throws ContainerExceptionInterface Error while retrieving the entry. +
-     *                   エントリの取得中にエラーが発生しました+
      *      *
-     * @return mixed Entry. +     * @return mixed エントリ
-                   エントリ+
      */      */
     public function get($id);     public function get($id);
行 135: 行 122:
      * Returns true if the container can return an entry for the given identifier.      * Returns true if the container can return an entry for the given identifier.
      * Returns false otherwise.      * Returns false otherwise.
 +     
      * コンテナが指定された識別子のエントリを返すことができる場合はtrueを返します。      * コンテナが指定された識別子のエントリを返すことができる場合はtrueを返します。
      * それ以外の場合はfalseを返します。      * それ以外の場合はfalseを返します。
行 140: 行 128:
      * `has($id)` returning true does not mean that `get($id)` will not throw an exception.      * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
      * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.      * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
 +     
      * has($id)がtrueを返すことは、get($id)が例外をスローしないことを意味しません。      * has($id)がtrueを返すことは、get($id)が例外をスローしないことを意味しません。
      * ただし、get($id)はNotFoundExceptionInterfaceをスローしないことは意味します。      * ただし、get($id)はNotFoundExceptionInterfaceをスローしないことは意味します。
      *      *
-     * @param string $id Identifier of the entry to look for. +     * @param string $id 検索するエントリの識別子
-                       検索するエントリの識別子+
      *      *
      * @return bool      * @return bool
行 162: 行 150:
 /** /**
  * Base interface representing a generic exception in a container.  * Base interface representing a generic exception in a container.
- * コンテナの一般的な例外を表す基本インターフェース+ * コンテナの一般的な例外を表す基本インターフェース
  */  */
 interface ContainerExceptionInterface interface ContainerExceptionInterface
行 179: 行 167:
 /** /**
  * No entry was found in the container.  * No entry was found in the container.
- * コンテナにエントリが見つかりませんでした+ * コンテナにエントリが見つかりませんでした
  */  */
 interface NotFoundExceptionInterface extends ContainerExceptionInterface interface NotFoundExceptionInterface extends ContainerExceptionInterface
psr/psr11.1592957136.txt.gz · 最終更新: 2020/06/24 09:05 by y2sunlight