Symfony 如何访问twig loader文件系统中的容器?

Symfony 如何访问twig loader文件系统中的容器?,symfony,twig,Symfony,Twig,我正在准备模板AB测试并运行,我需要访问twig loader中的容器,以便如果用户是AB测试的一部分,我可以交换模板。到目前为止,我已经尝试: twig.loader.filesystem: class: %twig.loader.filesystem.class% arguments: [%templating.locator%, %templating.name_parser%, @service_container] 及 但他们只会犯错误 但是,如果我删除容器并执行下面

我正在准备模板AB测试并运行,我需要访问twig loader中的容器,以便如果用户是AB测试的一部分,我可以交换模板。到目前为止,我已经尝试:

twig.loader.filesystem:
    class: %twig.loader.filesystem.class%
    arguments: [%templating.locator%, %templating.name_parser%, @service_container]

但他们只会犯错误

但是,如果我删除容器并执行下面的设置,它仍然可以工作

在my parameters.yml中:

parameters:
    twig.loader.filesystem.class: Project\Components\Extensions\TwigFilesystemLoader\ProjectFilesystemLoader
在我的文件中:

class ProjectFilesystemLoader extends \Twig_Loader_Filesystem
{
/**
 * @var \Symfony\Component\Config\FileLocatorInterface
 */
protected $locator;

/**
 * @var \Symfony\Component\Templating\TemplateNameParserInterface
 */
protected $parser;

/**
 * @var \Symfony\Component\DependencyInjection\ContainerInterface
 */
protected $container;

public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser, ContainerInterface $container)
{
    parent::__construct(array());

    $this->locator = $locator;
    $this->parser = $parser;
    $this->container = $container;
    $this->cache = array();
}

protected function findTemplate($template)
{
 ...
}
}

所以我迷路了,如何将容器放入细枝加载器?

当包含“@service\u container”?“\uu construct()必须实现接口Symfony\Component\DependencyInjection\ContainerInterface,未给出”时,您会遇到什么错误看起来正在调用原始构造函数,而我的重写只是覆盖了类。为什么要调用
parent::u构造(array())?因为Twig\u Loader\u文件系统使用它来设置路径。公共函数_构造($paths=array()){if($paths){$this->setPaths($paths);}您使用的是哪个版本的symfony2?
class ProjectFilesystemLoader extends \Twig_Loader_Filesystem
{
/**
 * @var \Symfony\Component\Config\FileLocatorInterface
 */
protected $locator;

/**
 * @var \Symfony\Component\Templating\TemplateNameParserInterface
 */
protected $parser;

/**
 * @var \Symfony\Component\DependencyInjection\ContainerInterface
 */
protected $container;

public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser, ContainerInterface $container)
{
    parent::__construct(array());

    $this->locator = $locator;
    $this->parser = $parser;
    $this->container = $container;
    $this->cache = array();
}

protected function findTemplate($template)
{
 ...
}
}