dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.85k stars 519 forks source link

Relying on Doctrine ORM Bundle #1312

Closed IonBazan closed 2 years ago

IonBazan commented 2 years ago

BC Break Report

Q A
BC Break yes
Version 1.21.0

Summary

This bundle relies on doctrine service when Doctrine ORM Bundle is not installed (eg. Doctrine MongoDB ODM is used instead).

Introduced in #1305 (see discussion there for reference)

Previous behavior

This bundle did not require Doctrine ORM Bundle to be installed.

Current behavior

Following error is thrown if Doctrine Bundle is not installed:

The service "vich_uploader.metadata_driver.annotation" has a dependency on a non-existent service "doctrine"

How to reproduce

Upgrade from v1.20.0 to v1.21.0 and run bin/console c:c.

garak commented 2 years ago

I guess we should introduce a compiler pass and inject the proper service instead

IonBazan commented 2 years ago

It could actually be a set of services - one might have all 3 doctrine libs installed.

endelwar commented 2 years ago

I don't get why this doesn't work in mapping.xml

<service id="vich_uploader.metadata_driver.annotation" class="Vich\UploaderBundle\Metadata\Driver\AnnotationDriver" public="false">
    <argument key="$reader" type="service" id="vich_uploader.metadata.reader" />
    <argument key="$managerRegistry" type="service" id="Doctrine\Persistence\ManagerRegistry" />
</service>

resulting in error Cannot instantiate interface Doctrine\Persistence\ManagerRegistry

endelwar commented 2 years ago

I got why: Doctrine\Persistence\ManagerRegistry is too high in the stack to be injected, and every manager (orm, odm, phpcr) have to be configured (connection parameter, db name, etc), that's why we have doctrine_mongodb, doctrine_phpcr and doctrine services Id, all implementing Doctrine\Persistence\ManagerRegistry.

We need a compiler pass that looks for doctrine_mongodb, doctrine_phpcr and/or doctrine services id and inject all Manager found to Vich\UploaderBundle\Metadata\Driver\AnnotationDriver as an array of Manager.

endelwar commented 2 years ago

Pushed a PR, tested with a simple Symfony app with both ORM and ODM bundles enabled