【问题标题】:Symfony2 - How to remove the Doctrine Bundle?Symfony2 - 如何删除 Doctrine Bundle?
【发布时间】:2026-02-14 03:30:01
【问题描述】:

我目前正在使用 Symfony2 进行项目,我不需要 Doctrine Bundle。我曾多次尝试删除它,但我不断收到破坏安装的错误。

我已经对 app 目录中的所有 'Doctrine' 实例进行了 grep'ed,并在以下文件中注释掉了对 Doctrine 的任何引用:

  • app/config/config.yml
  • app/AppKernel.php
  • app/autoload.php

然后我清除了缓存(当前工作在 dev 模式,所以删除了 cache/dev 目录)。

我目前遇到的错误是:

致命错误:类 'Doctrine\Common\Annotations\FileCacheReader' 不是 在发现 /path/to/application/app/cache/dev/appDevDebugProjectContainer.php on 第 45 行

这里指的是缓存中的这段代码

/**
 * Gets the 'annotation_reader' service.
 *
 * This service is shared.
 * This method always returns the same instance of the service.
 *
 * @return Doctrine\Common\Annotations\FileCacheReader A Doctrine\Common\Annotations\FileCacheReader instance.
 */
protected function getAnnotationReaderService()
{
    return $this->services['annotation_reader'] = new \Doctrine\Common\Annotations\FileCacheReader(new \Doctrine\Common\Annotations\AnnotationReader(), '/path/to/application/app/cache/dev/annotations', true);
}

但我找不到阻止它被添加到缓存中的方法,因为我找不到与 annotation_reader 相关的任何设置。

【问题讨论】:

  • 我怀疑它实际上无法删除。你真的需要删除它吗?你不能忽略它吗?
  • 我想我可以忽略它,但更愿意在项目中只包含项目实际使用的包。
  • 我同意,因为 S2 是基于捆绑包构建的,所以我认为它应该是可移动的。如果您想使用非原则数据存储会发生什么。

标签: doctrine symfony bundle


【解决方案1】:

Symfony 使用 Doctrine 的注解库。你不需要 Doctrine 的 ORM 或 DBAL,你可以删除它们。但是,如果您在项目中的任何地方使用注释,则需要注释阅读器。

编辑:您必须自己测试它。我自己从未尝试过。

这些包似乎使用注释阅读器:

  • DoctrineBundle
  • DoctrineAbstractBundle
  • SecurityExtraBundle
  • FrameworkExtraBundle
  • 框架包

请注意,这可能不值得付出努力。如果您不使用给定的服务,则不会创建它们。

【讨论】:

  • 没错。如果你使用控制器注解,你需要保留 Doctrine Common 包。
  • 这很好顺便说一句。 Symfony 没有重新发明*,而是使用了 Doctrine 中已经存在的东西。
  • 我也没有使用注释。我可能会在未来的项目中,但不会在这个项目中。所以问题是我如何禁用注释以便不生成上面的代码块?配置中唯一提到的是在框架下:验证:{ enable_annotations: true }。将此设置为 false 并不会阻止它。
  • 我也想要这个问题的答案,因为我打算使用 Propel 并且不打算使用注释。
【解决方案2】: