2011-09-16 53 views
0

嗨我正在使用Symfony DIC配置原则。 这对于Doctrine 2.0来说工作得很好,但是想升级到V2.1并需要添加一些额外的配置,如下所示。如何用Symfony依赖注入容器配置Doctrine 2.1?

$ reader = new \ Doctrine \ Common \ Annotations \ AnnotationReader();

$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); 
// new code necessary starting here 
$reader->setIgnoreNotImportedAnnotations(true); 
$reader->setEnableParsePhpImports(false); 

上面的代码没有我的问题,我的DIC配置:

<service id="doctrine.metadriver" class="Doctrine\ORM\Mapping\Driver\AnnotationDriver"> 
    <argument type="service"> 
     <argument type="service" id="doctrine.cache" /> 
     <service class="Doctrine\Common\Annotations\AnnotationReader"> 
      <call method="setDefaultAnnotationNamespace"> 
       <argument>Doctrine\ORM\Mapping\</argument> 
      </call> 
      <call method="setIgnoreNotImportedAnnotations"> 
       <argument>TRUE</argument> 
      </call> 
      <call method="setEnableParsePhpImports"> 
       <argument>FALSE</argument> 
      </call> 
     </service> 
    </argument> 
    <argument>%doctrine.entity.path%</argument> 
</service> 

我的问题是我怎么可以添加以下到DIC配置?

$reader = new \Doctrine\Common\Annotations\CachedReader(
    new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache() 
); 

回答

1

这可能不是一个完全有效的配置,但应该给你一些提示:

<service id="annotations.base_reader" 
    class="Doctrine\Common\Annotations\AnnotationReader" 
    public="false"> 
     <call method="setDefaultAnnotationNamespace"> 
      <argument>Doctrine\ORM\Mapping\</argument> 
     </call> 
     <call method="setIgnoreNotImportedAnnotations"> 
      <argument>TRUE</argument> 
     </call> 
     <call method="setEnableParsePhpImports"> 
      <argument>FALSE</argument> 
     </call> 
    </argument> 
</service> 

<service id="annotations.indexed_reader" 
    class="Doctrine\Common\Annotations\IndexedReader" 
    public="false"> 
    <argument type="service" id="annotations.base_reader" /> 
</service> 

<service id="annotations.cached_reader" 
    class="Doctrine\Common\Annotations\CachedReader"> 
    <argument type="service" id="annotations.indexed_reader" /> 
    <argument /> 
</service> 

<service id="annotation_reader" alias="annotations.cached_reader" />  

<service id="doctrine.metadriver" class="Doctrine\ORM\Mapping\Driver\AnnotationDriver"> 
    <argument type="service" id="annotation_reader" /> 
    <argument>%doctrine.entity.path%</argument> 
</service>