2017-06-02 48 views
2

升級到Symfony 3.3後。我得到這個:Symfony升級到3.3服務參數錯誤

PHP Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Invalid key "roles" found in arguments of method "setRoles()" for service "authbundle.auth.repository.role": only integer or $named arguments are allowed. in /app/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php:47

這是我的服務定義:

authbundle.auth.repository.role: 
    class: AuthBundle\Auth\Repository\RoleRepository 

我在這裏注射自定義配置成服務於AuthExtension類:

public function load(array $configs, ContainerBuilder $container) 
{ 
    $loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config')); 
    $configuration = new Configuration(); 
    $config = $this->processConfiguration($configuration, $configs); 
    $loader->load('services.yml'); 

    $roleRepositoryDef = $container->getDefinition('authbundle.auth.repository.role'); 
    $roleRepositoryDef->addMethodCall('setRoles', ['roles' => $config['roles']]); 
} 

任何想法,請?

回答

2

原來我的方法調用是不正確的,我不得不把它從

$roleRepositoryDef->addMethodCall('setRoles', ['roles' => $config['roles']]);

$roleRepositoryDef->addMethodCall('setRoles', [$config['roles']]);

這樣的說法是沒有命名

+0

只是出於好奇改變,做你原來的代碼工作?換句話說,升級到3.3是否確實會破壞你的代碼? – Cerad

+0

是的,我有那裏一兩個月,工作好,測試確保它的工作等,絕對停止工作後3.1 - > 3.3更新 – m1n0

+3

[UPGRADE-3.3](https://github.com/symfony/symfony /blob/master/UPGRADE-3.3.md)文檔聲明:* [BC BREAK]方法和構造函數參數中的非數字鍵從未得到支持,現在被禁止。請刪除它們,如果你碰巧有一個。*。 – ccKep