我想创建一个访问Rackspace Cloud Files的服务。我已将以下配置添加到services.yml
:
services:
# Rackspace
# Note: Rackspace parameters (e.g., %rackspace_username%, etc.) are set in
# app/config/parameters.yml.
rackspace:
class: OpenCloud\Rackspace
arguments:
- "%rackspace_identity_endpoint%"
- {"username": "%rackspace_username%", "apiKey": "%rackspace_api_key%"}
rackspace.cloudfiles:
parent: rackspace
calls:
- [objectStoreService, ["cloudFiles", '%rackspace_cloudfiles_region%', '%rackspace_url_type%']]
rackspace.cloudfiles
服务无法正常工作,因为我需要objectStoreService()
(OpenCloud\ObjectStore\Service
的实例)的结果,而不是OpenCloud\Rackspace
实例的结果。
是否可以根据调用computeService()
的结果定义服务?
答案 0 :(得分:0)
将rackspace
服务视为工厂:
services:
# Rackspace
# Note: Rackspace parameters (e.g., %rackspace_username%, etc.) are set in
# app/config/parameters.yml.
rackspace:
class: OpenCloud\Rackspace
arguments:
- "%rackspace_identity_endpoint%"
- {"username": "%rackspace_username%", "apiKey": "%rackspace_api_key%"}
rackspace.cloudfiles:
class: OpenCloud\ObjectStore\Service
factory_service: rackspace
factory_method: objectStoreService
arguments:
- "cloudFiles"
- "%rackspace_cloudfiles_region%"
- "%rackspace_url_type%"
有关详细信息,请参阅http://symfony.com/doc/current/components/dependency_injection/factories.html。