在 Symfony 3.4 应用程序中定义服务定义参数的正确方法是什么
What is the correct way to define service definition arguments in a Symfony 3.4 application
在 Symfony 3.4 应用程序中定义服务定义参数的正确方法是什么?
我注意到以下所有内容都是有效的:
AppBundle\Services\RFC\Spackman:
arguments:
$watpSdk: '@watp.client'
calls:
- [setPlayerName, ['%p_name%']]
AppBundle\Services\RFC\Gordon:
$client: '@crmpicco.client'
zendesk.client:
class: Zendesk\API\HttpClient
arguments:
- '%zendesk_subdomain%'
官方文档是这样说的,但是我不确定正确的标准是什么:
New in version 3.3: The ability to configure an argument by its name
($adminEmail) was added in Symfony 3.3. Previously, you could
configure it only by its index (2 in this case) or by using empty
quotes for the other arguments.
- 当您使用连字符时,它会提供参数以便
constructor/factory 您的服务。
- 当你使用“$argname”时,它
根据 constructor/factory 的名称提供参数
范围。
- 您也可以使用 "index_#" 通过
具体指数.
其中任何一个都是正确的方法。我更喜欢使用连字符,因为如果有一天你重构了参数的名称,你就不必在配置中也重构它了。
当我需要扩展服务定义并替换父服务中定义的参数之一时,我也使用 "index_#"。
这是一个品味问题,因为服务扩展可以完全忽略。
在 Symfony 3.4 应用程序中定义服务定义参数的正确方法是什么?
我注意到以下所有内容都是有效的:
AppBundle\Services\RFC\Spackman:
arguments:
$watpSdk: '@watp.client'
calls:
- [setPlayerName, ['%p_name%']]
AppBundle\Services\RFC\Gordon:
$client: '@crmpicco.client'
zendesk.client:
class: Zendesk\API\HttpClient
arguments:
- '%zendesk_subdomain%'
官方文档是这样说的,但是我不确定正确的标准是什么:
New in version 3.3: The ability to configure an argument by its name ($adminEmail) was added in Symfony 3.3. Previously, you could configure it only by its index (2 in this case) or by using empty quotes for the other arguments.
- 当您使用连字符时,它会提供参数以便 constructor/factory 您的服务。
- 当你使用“$argname”时,它 根据 constructor/factory 的名称提供参数 范围。
- 您也可以使用 "index_#" 通过 具体指数.
其中任何一个都是正确的方法。我更喜欢使用连字符,因为如果有一天你重构了参数的名称,你就不必在配置中也重构它了。
当我需要扩展服务定义并替换父服务中定义的参数之一时,我也使用 "index_#"。
这是一个品味问题,因为服务扩展可以完全忽略。