Symfony工厂服务不通过参数

时间:2012-03-21 17:13:00

标签: php symfony

我在Symfony2(click here for more info on that

中创建了一个工厂服务

然后我将服务添加到YAML配置中,如下所示:

services:
#crypto services manager
cs_manager:
    class: MyMC\Encrypt\Manager
    factory_class: MyMC\Encrypt\Manager
    factory_method: getInstance
    arguments:
        - %cs_application_cert%
        - %cs_service_cert%
        - %cs_cert_password%

#identity management system manager
ims_manager:
    class: MyMC\Ims\Manager
    factory_class: MyMC\Ims\Manager
    factory_method: getInstance
    arguments:
        - %ims_service_domain%
        - @cs_manager

你可以看到我将2个参数传递给ims_manager。在ims_manager工厂的getInstance()函数中,我检查以确保传递了这两个参数...

public static function getInstance($apiUrl = null, $cryptoService = null) {
    if(!isset(self::$service)) {
        $className = __CLASS__;
        if($apiUrl == null) {
            throw new Exception('getInstance','API url must not be null. Initiate with correct parameters on first call.');
        }
        if($cryptoService) {
            throw new Exception('getInstance', 'You must pass a valid Encryption object on first call.');
        }
        self::$service = new $className($apiUrl);
    }

    return self::$service;
}

但它抛出我的自定义异常,说我必须传入参数,这意味着在调用函数时它们不会被Symfony传递。 任何人都可以想到为什么Symfony不会传递我在配置文件中指定的参数?

此外,这是我最近10次通话的回溯:

at Manager::getInstance()
at call_user_func() in /var/www/app/cache/dev/appDevDebugProjectContainer.php line 734
at appDevDebugProjectContainer->getImsManagerService() in /var/www/app/bootstrap.php.cache line 190
at Container->get() in /var/www/app/cache/dev/appDevDebugProjectContainer.php line 217
at appDevDebugProjectContainer->getEntityManagerService() in /var/www/app/bootstrap.php.cache line 190
at Container->get() in /var/www/app/cache/dev/appDevDebugProjectContainer.php line 857
at appDevDebugProjectContainer->getMcSecurityProviderService() in /var/www/app/bootstrap.php.cache line 190
at Container->get() in /var/www/app/cache/dev/appDevDebugProjectContainer.php line 1929
at appDevDebugProjectContainer->getSecurity_Authentication_ManagerService() in /var/www/app/bootstrap.php.cache line 190

0 个答案:

没有答案