2013-07-16 1 views
2

컴파일러 통과를 통해 데이터 수집기를로드 할 수 없습니다. 사용할 수 있도록 데이터 수집기를 선택 유지하려고 시도하고 있습니다. 태그가없는 YAML 파일에 정의 된 다음 컴파일러 전달은 매개 변수 설정에 따라 태그를 추가합니다.Symfony2 컴파일러 패스에 data_collector 태그 추가

컴파일러 패스가 태그를 추가하기에는 너무 늦은 것 같습니다.

<?php 
    if ($container->getParameter('git_data_collector_enabled')) { 
     $gitDataCollectorDef = $container->getDefinition('git_data_collector'); 

     $gitDataCollectorDef->addTag('data_collector', array(
      'template' => 'Profiler:git_info_layout', 
      'id' => 'git', 
     )); 
    } 
+0

'git_data_collector_enabled'가 true인지 아닌지 컴파일러에서 전체 데이터 수집기를 초기화하는 방법은 무엇입니까? –

답변

0

data_collector 태그는 symfony framework bundle profiler pass 사용된다. symfony 프레임 워크 번들의 컴파일러 패스는 컴파일러가 통과하기 전에 실행될 가능성이 큽니다. 번들 (및 번들이이 순서대로로드되기 전에) 전에 응용 프로그램 커널에서 프레임 워크 번들을 목록 상단에 등록했기 때문입니다.

이것은 불행히도 data_collector 태그를 사용하기에는 너무 늦었 음을 의미합니다. 당신은 여전히 ​​인스턴스화하기 전에 프로파일 서비스를 조작하고 프로파일 정의에 addMethodCall 방법을 사용하여에 git_data_collector을 추가 할 수 있습니다 그러나 : 당신은 본질적으로 그것의 일부의 복제하려고으로 아이디어가 profiler compiler pass에서입니다

if ($container->getParameter('git_data_collector_enabled')) { 
    //Get the profiler definition 
    $definition = $container->getDefinition('profiler'); 
    //require the definition to run the add method with a reference to your data collector when it is instantiated 
    $definition->addMethodCall('add', array(new Reference('git_data_collector'))); 

    //Add your template to the data_collector templates 
    $templates = $container->getParameter('data_collector.templates'); 
    $container->setParameter('data_collector.templates', array_merge($templates,array('git' => array('git', 'Profiler:git_info_layout')))); 
} 

기능.

관련 문제