このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 最新のリビジョン 両方とも次のリビジョン | ||
slim:4:concepts [2020/10/02 14:01] y2sunlight [Configuring the application via a container] |
slim:4:concepts [2020/10/05 16:50] y2sunlight |
||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== Slim4 のコンセプト ====== | + | ====== Slim4 コンセプト ====== |
Version 4.5.0 | Version 4.5.0 | ||
- | --- // | + | --- // |
[[slim: | [[slim: | ||
行 8: | 行 8: | ||
関連記事 | 関連記事 | ||
- | * [[slim: | + | * [[slim: |
- | * Slim4のコンセプト | + | * Slim4 コンセプト |
- | * [[slim:4:basic|Slim4の基本的な使い方]] | + | * [[slim:4:request|Slim4 |
+ | * [[slim: | ||
+ | * [[slim: | ||
+ | * [[slim: | ||
- | 本章は以下のサイトの | + | 本章は以下のサイトの **Concepts** のセクションを翻訳し若干の補足を加えたのもです。 |
* https:// | * https:// | ||
行 413: | 行 416: | ||
===== 依存性コンテナ― ===== | ===== 依存性コンテナ― ===== | ||
- | Slim uses an optional dependency container to prepare, manage, and inject application dependencies. | + | Slimは、オプションの依存性コンテナーを使用して、アプリケーションの依存関係を準備、管理、および注入します。Slimは、[[https:// |
- | Slimは、オプションの依存関係コンテナーを使用して、アプリケーションの依存関係を準備、管理、および挿入します。 Slimは、PHP-DIのようなPSR-11を実装するコンテナーをサポートします。 | + | > PSR-11の邦訳は[[psr: |
- | ==== Example usage with PHP-DI ==== | + | |
- | You don’t have to provide a dependency container. If you do, however, you must provide an instance of the container to '' | + | \\ |
+ | |||
+ | ==== PHP-DIでの使用例 ==== | ||
- | 依存関係コンテナを提供する必要はありません。 | + | 依存関係コンテナを必ず提供する必要があるとは限りません。但し、そうする場合は、'' |
<code php> | <code php> | ||
行 439: | 行 443: | ||
</ | </ | ||
- | Add a service to your container: | + | そして、コンテナにサービスを追加します: |
- | + | ||
- | コンテナにサービスを追加します。 | + | |
<code php> | <code php> | ||
行 450: | 行 452: | ||
</ | </ | ||
- | You can fetch services from your container explicitly as well as from inside a Slim application route like this: | + | 次のように、明示的にコンテナからからだけでなく、Slimアプリケーションルートの内からサービスをフェッチできます: |
- | + | ||
- | 次のように、コンテナから明示的に、およびSlimアプリケーションルート内からサービスをフェッチできます。 | + | |
<code php> | <code php> | ||
行 473: | 行 473: | ||
</ | </ | ||
- | To test if a service exists in the container before using it, use the '' | + | コンテナを使用する前にサービスがコンテナに存在するかどうかをテストするには、次のように '' |
- | + | ||
- | コンテナを使用する前にサービスがコンテナに存在するかどうかをテストするには、次のように '' | + | |
<code php> | <code php> | ||
行 497: | 行 495: | ||
\\ | \\ | ||
- | ==== Configuring the application via a container | + | ==== コンテナを介したアプリケーションの構成 |
- | In case you want to create the '' | + | コンテナに依存性が既に定義されている |
- | + | ||
- | コンテナに依存関係がすでに定義されている「アプリ」を作成する場合は、「AppFactory :: createFromContainer()」メソッドを使用できます。 | + | |
**例題** | **例題** | ||
行 531: | 行 527: | ||
$app-> | $app-> | ||
</ | </ | ||
- | |||
- | Supported App dependencies are: | ||
サポートされているアプリの依存関係は次のとおりです: | サポートされているアプリの依存関係は次のとおりです: |