Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration with non bundled mapping and xml mapping is broken in 5.0 #841

Closed
frenchcomp opened this issue Jan 20, 2024 · 4 comments
Closed
Labels
Milestone

Comments

@frenchcomp
Copy link

frenchcomp commented Jan 20, 2024

Hi,

I have a project, with persisted document are not in bundle and use a xml mapping.
The configuration is

doctrine_mongodb:
    document_managers:
        default:
            auto_mapping: true
            mappings:
                TeknooEastCommon:
                    type: 'xml'
                    dir: '%kernel.project_dir%/vendor/teknoo/east-common/infrastructures/doctrine/config/universal'
                    is_bundle: false
                    prefix: 'Teknoo\East\Common\Object'

It's work with the bundle under v4.7 (With Symfony 6.4 or 7.0) but not with v5.0
I have this error :

PHP Fatal error: Uncaught TypeError: is_dir(): Argument #1 ($filename) must be of type string, int given in /home/richard/Prog/teknoo/websites/website-deloge-io/appliance/vendor/doctrine/persistence/src/Persistence/Mapping/Driver/SymfonyFileLocator.php:180

After debug, the compiled DI for the document manager is different, The error come from the XmlDriver configuration and the Symfony DoctrineBridge and this bunde.

With 4.7, the generated code is :

$c = new \Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver([(\dirname(__DIR__, 4).'/vendor/teknoo/east-common/infrastructures/doctrine/config/universal') => 'Teknoo\\East\\Common\\Object', (\dirname(__DIR__, 4).'/vendor/teknoo/east-common/infrastructures/doctrine/config/doctrine') => 'Teknoo\\East\\Common\\Doctrine\\Object', (\dirname(__DIR__, 4).'/vendor/teknoo/east-website/infrastructures/doctrine/config/universal') => 'Teknoo\\East\\Website\\Object', (\dirname(__DIR__, 4).'/vendor/teknoo/east-website/infrastructures/doctrine/config/doctrine') => 'Teknoo\\East\\Website\\Doctrine\\Object']);
        $c->setGlobalBasename('mapping');

But with 5.0

$c = new \Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver([(\dirname(__DIR__, 4).'/vendor/teknoo/east-common/infrastructures/doctrine/config/universal'), (\dirname(__DIR__, 4).'/vendor/teknoo/east-common/infrastructures/doctrine/config/doctrine'), (\dirname(__DIR__, 4).'/vendor/teknoo/east-website/infrastructures/doctrine/config/universal'), (\dirname(__DIR__, 4).'/vendor/teknoo/east-website/infrastructures/doctrine/config/doctrine')]);

The first argument of XmlDriver has only array's values wihout keys.

It come from the 'vendor/symfony/doctrine-bridge/DependencyInjection/AbstractDoctrineExtension.php', line 218

if (str_contains($mappingDriverDef->getClass(), 'yml') || str_contains($mappingDriverDef->getClass(), 'xml')) {
    $mappingDriverDef->setArguments([array_flip($driverPaths)]);
    $mappingDriverDef->addMethodCall('setGlobalBasename', ['mapping']);
}

The mappingDriverDef->getClass() return %doctrine_mongodb.odm.metadata.xml.class% and the condition will be true
But it 5.0 Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver and because the condition is sensible to the case, it will never be true.

Thanks.

@malarzm malarzm added the bug label Jan 20, 2024
@malarzm malarzm added this to the 5.0.2 milestone Jan 20, 2024
@GromNaN GromNaN changed the title Configuration with non bundled mapping is broken in %.0 Configuration with non bundled mapping is broken in 5.0 Jan 20, 2024
@frenchcomp frenchcomp changed the title Configuration with non bundled mapping is broken in 5.0 Configuration with non bundled mapping and xml mapping is broken in 5.0 Jan 20, 2024
@MatthieuPoudevigne-cnic

I confirm i have the same problem when i try to update symfony 6.4 to 7.0 with the update of this bundle

@GromNaN
Copy link
Member

GromNaN commented Jan 25, 2024

Thanks for the reminder, I'm checking.

@GromNaN
Copy link
Member

GromNaN commented Jan 25, 2024

We use SimplifiedXmlDriver to parse the mapping with type: xml. This class accepts a list of strings string[] as $prefixes. (see SimplifiedXmlDriver::__construct())

But the SymfonyFileLocator that is used, only keep the "keys" from this array of paths. That's why we get 0 instead of the actual file path.
https://github.com/doctrine/persistence/blob/e7cf418cafe83a75f7a7096cc9fa890b201d28f1/src/Persistence/Mapping/Driver/SymfonyFileLocator.php#L95

@GromNaN
Copy link
Member

GromNaN commented Jan 30, 2024

The issue is caused by #821
See the fix in Symfony DoctrineBridge: symfony/symfony#53681

nicolas-grekas added a commit to symfony/symfony that referenced this issue Jan 30, 2024
…rineExtension (GromNaN)

This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

[DoctrineBridge]  Fix detection of Xml/Yaml driver in DoctrineExtension

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix doctrine/DoctrineMongoDBBundle#841
| License       | MIT

In DoctrineMongoDBBundle v5, we removed `.class` attributes to plain class names in service definitions (see doctrine/DoctrineMongoDBBundle#821). The class for `doctrine_mongodb.odm.default_xml_metadata_driver` changed from `doctrine_mongodb.odm.metadata.xml.class` to `Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver`.

I fixed the detection of the driver by checking the uppercase `Xml` and `Yaml` because it might be necessary if the same change is made to DoctrineBundle.

[`doctrine/mongodb-odm-bundle` requires `symfony/doctrine-bridge: "^6.4 || ^7.0"`](https://github.com/doctrine/DoctrineMongoDBBundle/blob/4d8d32b726e7af21a562a2b6a227f0496c7d39d5/composer.json#L36) so this patch if not required for older versions of Symfony even if it could be applied.

Commits
-------

662b8f2 [DoctrineBridge]  Fix detection of Xml/Yaml driver in DoctrineExtension
@GromNaN GromNaN closed this as completed Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants