このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 最新のリビジョン 両方とも次のリビジョン | ||
psr:psr11 [2020/06/24 09:57] y2sunlight [2. パッケージ] |
psr:psr11 [2020/07/28 14:08] tanaka [目次] |
||
---|---|---|---|
行 3: | 行 3: | ||
--- // | --- // | ||
- | 本章は、若干の補足を加筆してはいるものの単に[[https:// | + | 本章は、若干の補足を加筆してはいるものの単に[[https:// |
+ | |||
+ | 関連記事 | ||
- | ==== 目次 ==== | ||
* [[psr: | * [[psr: | ||
* [[psr: | * [[psr: | ||
行 14: | 行 15: | ||
* [[psr: | * [[psr: | ||
* PSR-11: Container Interface - コンテナインターフェイス | * PSR-11: Container Interface - コンテナインターフェイス | ||
- | * [[psr: | + | * [[psr: |
* [[psr: | * [[psr: | ||
* [[psr: | * [[psr: | ||
- | * [[psr: | + | * [[psr: |
+ | * [[psr: | ||
+ | * [[psr: | ||
+ | * [[psr: | ||
+ | * [[psr: | ||
----- | ----- | ||
行 71: | 行 76: | ||
==== 1.3 推奨される使用法 ===== | ==== 1.3 推奨される使用法 ===== | ||
- | Users SHOULD NOT pass a container into an object so that the object can retrieve its own dependencies. This means the container is used as a Service Locator which is a pattern that is generally discouraged. | + | オブジェクトが独自の依存関係を取得できるように、ユーザーはコンテナをオブジェクトに渡すべきではありません ( '' |
- | オブジェクトが独自の依存関係を取得できるように、ユーザーはコンテナをオブジェクトに渡すべきではありません ('' | + | 詳細については、METAドキュメントの[[https:// |
- | + | ||
- | Please refer to section 4 of the META document for more details. | + | |
- | + | ||
- | 詳細については、METAドキュメントのセクション4を参照してください。 | + | |
\\ | \\ | ||
===== 2. パッケージ ===== | ===== 2. パッケージ ===== | ||
- | |||
- | The interfaces and classes described as well as relevant exceptions are provided as part of the psr/ | ||
説明されているインターフェースとクラス、および関連する例外は、[[https:// | 説明されているインターフェースとクラス、および関連する例外は、[[https:// | ||
- | Packages providing a PSR container implementation should declare that they provide psr/ | + | PSRコンテナーの実装を提供するパッケージは、'' |
- | + | ||
- | PSRコンテナーの実装を提供するパッケージは、psr/ | + | |
- | + | ||
- | Projects requiring an implementation should require psr/ | + | |
- | 実装が必要なプロジェクトでは、psr/ | + | 実装が必要なプロジェクトでは、'' |
\\ | \\ | ||
行 115: | 行 110: | ||
* 識別子によってコンテナのエントリを検索して返します。 | * 識別子によってコンテナのエントリを検索して返します。 | ||
* | * | ||
- | * @param string $id Identifier of the entry to look for. | + | * @param string $id 検索するエントリの識別子 |
- | * 検索するエントリの識別子 | + | |
* | * | ||
- | * @throws NotFoundExceptionInterface | + | * @throws NotFoundExceptionInterface |
- | * この識別子のエントリが見つかりませんでした。 | + | * @throws ContainerExceptionInterface エントリの取得中にエラーが発生しました |
- | * @throws ContainerExceptionInterface | + | |
- | * エントリの取得中にエラーが発生しました。 | + | |
* | * | ||
- | * @return mixed Entry. | + | * @return mixed エントリ |
- | | + | |
*/ | */ | ||
public function get($id); | public function get($id); | ||
行 131: | 行 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を返します。 | ||
行 136: | 行 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 | ||
行 158: | 行 150: | ||
/** | /** | ||
* Base interface representing a generic exception in a container. | * Base interface representing a generic exception in a container. | ||
- | * コンテナの一般的な例外を表す基本インターフェース。 | + | * コンテナの一般的な例外を表す基本インターフェース |
*/ | */ | ||
interface ContainerExceptionInterface | interface ContainerExceptionInterface | ||
行 175: | 行 167: | ||
/** | /** | ||
* No entry was found in the container. | * No entry was found in the container. | ||
- | * コンテナにエントリが見つかりませんでした。 | + | * コンテナにエントリが見つかりませんでした |
*/ | */ | ||
interface NotFoundExceptionInterface extends ContainerExceptionInterface | interface NotFoundExceptionInterface extends ContainerExceptionInterface |