【问题标题】:libxml2 cannot load Doctrine entity metadatalibxml2 无法加载 Doctrine 实体元数据
【发布时间】:2015-04-10 20:24:58
【问题描述】:

我对 Doctrine 提出了一个非常奇怪的问题。它无法加载特定实体的元数据。我所有其他实体都加载正常,但是当我尝试加载以下 XML 时失败:

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                    http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Foo\ContentBundle\Entity\Item" table="content_item">
    <id name="id" column="id" type="integer">
        <generator strategy="AUTO" />
    </id>

    <field name="gid" column="gid" type="string" nullable="false" unique="false" />
    <field name="url" column="url" type="string" nullable="true" unique="false" />
    <field name="title" column="title" type="string" nullable="false" unique="false" />
    <field name="content" column="content" type="text" nullable="false" unique="false" />
    <field name="timestamp" column="timestamp" type="datetime" nullable="false" unique="false" />

    <many-to-one field="feed" target-entity="Foo\ContentBundle\Entity\Feed">
        <join-column name="feed" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
    </many-to-one>
</entity>

它会抛出以下异常:

Invalid mapping file 'Foo.ContentBundle.Entity.Item.orm.xml' for class 'Foo\ContentBundle\Entity\Item'.

而 libxml2 给了我以下错误:

failed to load external entity "/Users/ramon/Development/foo/src/Foo/ContentBundle/Resources/config/doctrine/Item.orm.xml"

奇怪的是,我所有的其他实体都很好!有没有人知道如何解决这个问题?

我正在使用 libxml 2.9.0 版、Doctrine ORM 2.4.7 版和 Symfony 2.6 版以及 PHP 5.6.5。

[edit] 忘记了最好的部分:这只发生在我加载元数据以从存储库中获取实体时。不是在我将实体插入存储库时。

另外,当我尝试使用 simplexml_load_file 手动加载文件时,它工作正常。

【问题讨论】:

    标签: php symfony doctrine-orm doctrine libxml2


    【解决方案1】:

    我找到了原因。

    我正在使用另一个库 (picoFeed),它调用 libxml_disable_entity_loader(true) 函数,这反过来会导致 known bug。我现在为 picoFeed 创建了一个pull request,它在完成安全检查后启用实体加载器。这解决了上述问题。

    【讨论】:

      猜你喜欢
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 2019-05-02
      • 2015-05-15
      • 1970-01-01
      • 2014-09-30
      相关资源
      最近更新 更多