-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translate container.md (v5.5) #357
Conversation
0c853ca
to
500c59e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review 有任何問題都可以討論
container.md
Outdated
- [The Make Method](#the-make-method) | ||
- [Automatic Injection](#automatic-injection) | ||
- [Container Events](#container-events) | ||
# 服務容器( Container ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要 Container & 大括號
container.md
Outdated
|
||
The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection. Dependency injection is a fancy phrase that essentially means this: class dependencies are "injected" into the class via the constructor or, in some cases, "setter" methods. | ||
Laravel 服務容器(Container)是管理類別依賴與執行依賴注入的強大工具。依賴注入是個花俏的名詞,實際上是指:類別的依賴透過建構子「注入」,或在某些情況下透過「setter」方法注入。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 不需要 Container & 大括號
container.md
Outdated
@@ -61,65 +61,65 @@ Let's look at a simple example: | |||
} | |||
} | |||
|
|||
In this example, the `UserController` needs to retrieve users from a data source. So, we will **inject** a service that is able to retrieve users. In this context, our `UserRepository` most likely uses [Eloquent](/docs/{{version}}/eloquent) to retrieve user information from the database. However, since the repository is injected, we are able to easily swap it out with another implementation. We are also able to easily "mock", or create a dummy implementation of the `UserRepository` when testing our application. | |||
在這例子中,`UserController` 需要從資料來源中取得使用者,所以我們將要**注入** `UserRepository` 該服務來取得使用者。在這種情況下,`UserRepository` 像是使用 [Eloquent](/docs/{{version}}/eloquent) 取得在資料庫中有關使用者的資訊。由於儲存庫是被注入的,因此我們才能輕易地切換其他的實作。當我們在做測試的時候,一樣也能輕易地「模擬(mock)」,或建立假的 `UserRepository` 實作來測試我們的程式。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在這個範例中,UserController
需要從資料來源中取得使用者。所以我們將注入一個服務讓我們能取得使用者。在這個情境下,我們的 UserRepository
像是使用 Eloquent 一樣,從資料庫取得使用者資訊。然而,由於 Repository 是被注入的,我們可以更容易的抽換成其他的實作。我們可以很容易的「mock」,或是建立一個假的 UserRepository
實作來測試我們的應用程式。
這裡保留 Repository
& Mock
這兩詞。
container.md
Outdated
|
||
A deep understanding of the Laravel service container is essential to building a powerful, large application, as well as for contributing to the Laravel core itself. | ||
深入地理解 Laravel 服務容器,對於構建功能強大的大型 Laravel 應用程式而言至關重要。甚至是貢獻 Laravel 核心的程式碼也是不可或缺的。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
深入了解 Laravel 的服務容器對於建立一個強大、大型的應用程式以及為 Laravel 核心程式碼本身做出貢獻是必要的。
container.md
Outdated
|
||
Almost all of your service container bindings will be registered within [service providers](/docs/{{version}}/providers), so most of these examples will demonstrate using the container in that context. | ||
幾乎所有的服務容器綁定都會在[服務提供者](/docs/{{version}}/providers)中註冊,所以下方所有的例子將示範在該情境中使用容器。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
幾乎所有的服務容器綁定都會在服務提供者中被註冊,所以下方所有的範例將示範在該情境中使用容器。
container.md
Outdated
|
||
$api = resolve('HelpSpot\API'); | ||
|
||
If some of your class' dependencies are not resolvable via the container, you may inject them by passing them as an associative array into the `makeWith` method: | ||
如果你有一些類別的依賴不能透過容器來解析,你可以將它們弄成一組關聯陣列傳到 `makeWith` 方法來注入: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果你有一些類別的依賴不能透過容器來解析,你可以將它們組成為關聯陣列傳入到 makeWith
方法來注入:
container.md
Outdated
|
||
For example, you may type-hint a repository defined by your application in a controller's constructor. The repository will automatically be resolved and injected into the class: | ||
舉個例子,你可以在控制器的建構子中對應用程式中定義的儲存庫進行型別提示。儲存庫會自動被解析及注入至類別中: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
例如,你可以透過你應用程式控制器的建構子型別提示一個被定義的 Repository。Repository 將自動地被解析並注入到類別中:
container.md
Outdated
|
||
The service container fires an event each time it resolves an object. You may listen to this event using the `resolving` method: | ||
每當服務容器解析一個物件時就會觸發事件。你可以使用 `resolving` 方法監聽這個事件: | ||
|
||
$this->app->resolving(function ($object, $app) { | ||
// Called when container resolves object of any type... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
當容器解析任何的類型物件時被呼叫
container.md
Outdated
@@ -251,12 +251,12 @@ The service container fires an event each time it resolves an object. You may li | |||
// Called when container resolves objects of type "HelpSpot\API"... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
當容器解析「HelpSpot\API」的類型物件時被呼叫
container.md
Outdated
@@ -251,12 +251,12 @@ The service container fires an event each time it resolves an object. You may li | |||
// Called when container resolves objects of type "HelpSpot\API"... | |||
}); | |||
|
|||
As you can see, the object being resolved will be passed to the callback, allowing you to set any additional properties on the object before it is given to its consumer. | |||
如你所見,被解析的物件會被傳遞至回呼函式中,從而允許你在傳遞給消費者之前,設置任何額外的屬性至物件。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如你所見,被解析的物件會被傳遞至回呼函式中,在它被提供給它的消費者之前,允許你在物件上設定任何額外的屬性。
500c59e
to
a4f2dda
Compare
文件內部分的程式碼區塊的註解再麻煩翻譯一下,謝謝! |
已補從註解翻譯了,麻煩再檢查一下,感恩 |
container.md
Outdated
@@ -48,7 +48,7 @@ Let's look at a simple example: | |||
} | |||
|
|||
/** | |||
* Show the profile for the given user. | |||
* 顯示給定使用者個資。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
顯示個人資料給特定使用者。
Translate
container.md
(v5.5)type-hint
在本文件中一直被當動詞使用,可是如果把型別提示
當成動名詞使用,可讀性會很低。目前稍微用
注入
來取代