Search code examples
phpsymfonydoctrine-ormdoctrinelibxml2

libxml2 cannot load Doctrine entity metadata


I'm heaving a really weird issue with Doctrine. It fails to load the metadata for a specific entity. All my other entities are loading fine, but when I try to load the following XML it fails:

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

It throws the following exception:

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

and libxml2 gives me the following error:

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

The weird thing is, all my other entities are just fine! Does anyone have an idea on how to fix this?

I'm using libxml version 2.9.0, Doctrine ORM version 2.4.7 and Symfony version 2.6, and PHP 5.6.5.

[edit] Forgot the best part: this only happens when I'm loading the metadata to fetch an entity from the repository. Not when I'm inserting an entity into the repository.

Also, when I try to load the file manually using simplexml_load_file it works fine.


Solution

  • And I have found the cause.

    I'm using another library (picoFeed) which calls the libxml_disable_entity_loader(true) function which in turn causes an known bug. I've now created a pull request for picoFeed which enables the entity loader after security checks are done. This fixes the issue described above.