升级到Symfony 3.3之后。我明白了:
PHP致命错误:未捕获 Symfony的\分量\ DependencyInjection \异常\ InvalidArgumentException: 密钥"角色无效"在方法的参数中找到" setRoles()"对于 service" authbundle.auth.repository.role":只有整数或$ named 允许参数。在 /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']]);
}
有什么想法吗?
答案 0 :(得分:2)
原来我的方法调用不正确,我不得不从
更改它 $roleRepositoryDef->addMethodCall('setRoles', ['roles' => $config['roles']]);
$roleRepositoryDef->addMethodCall('setRoles', [$config['roles']]);
因此参数未命名为