如何使用 Symfony 依赖注入容器配置 Doctrine 2.1?
您好,我正在使用 Symfony DIC 来配置 Doctrine。 这与 Doctrine 2.0 完美配合,但想要升级到 v2.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()
);
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()
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能不是一个完全有效的配置,但应该会给您一些提示:
It might not be a fully working configuration but should give you some hints: