0

我想创建一个访问 Rackspace 云文件的服务。我已将以下配置添加到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()(instance of OpenCloud\ObjectStore\Service) 的结果,而不是OpenCloud\Rackspace实例。

是否可以根据调用结果定义服务computeService()

4

1 回答 1

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

于 2013-11-09T23:41:59.817 回答