tom
tom

Reputation: 8359

Howto configure Doctrine 2.1 with Symfony Dependency Injection Container?

Hi I'm using Symfony DIC to configure Doctrine. This was working perfectly fine with Doctrine 2.0, but wanted to upgrade to v2.1 and needed to add some extra configuration as seen below.

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

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

My DIC configuration for the above code without my problem:

<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>

My question is how can I add the following to the DIC configuration?

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

Upvotes: 0

Views: 660

Answers (1)

Jakub Zalas
Jakub Zalas

Reputation: 36191

It might not be a fully working configuration but should give you some hints:

<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>

Upvotes: 1

Related Questions