Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 从编译器传递包?_Symfony_Dependency Injection - Fatal编程技术网

Symfony 从编译器传递包?

Symfony 从编译器传递包?,symfony,dependency-injection,Symfony,Dependency Injection,在收集标记服务的编译器过程中,是否有任何方法(标记参数除外)访问“提供”包(对象或名称) class MyContainerPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { if (!$container->hasDefinition('my.service')) { return;

在收集标记服务的编译器过程中,是否有任何方法(标记参数除外)访问“提供”包(对象或名称)

class MyContainerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('my.service')) {
            return;
        }

        $definition = $container->getDefinition('my.service');

        foreach ($container->findTaggedServiceIds('my.tag') as $id => $linkContainer) {
             // here is where I would like the bundle name or object
             $definition->addMethodCall('add', array(new Reference($id)));
        }
    }
}

为什么要使用捆绑包名称?只是问,因为你可以用另一种方式实现你想要的。谢谢你的回答。我正在构建一个标记服务的数组,并希望将包名称作为数组索引的一部分。类似于
$definition->addMethodCall('add',[$bundleName.:'。$id,新引用($id)]确定,但为什么要存储捆绑包名称?在您的逻辑中是否需要它?是的,我稍后在逻辑中使用它。对不起,我不知道动态获取捆绑包名称的方法。