doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.86k stars 2.5k forks source link

Added a new manager to manage multiple entity manager instances #11476

Closed fldv closed 1 month ago

fldv commented 1 month ago

Hi,

I encountered a problem with the console, I would have liked to be able to pass several instances of the entity manager. Currently, only one instance can be passed using SingleManagerProvider class.

Here is a new implementation of the MultipleManagerProvider class. It allows you to obtain several instances of the Entity manager within a console application.

Here is how it could be instantiated:

#!/usr/bin/env php
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\MultipleManagerProvider;

$em1 = GetEntityManager();
$em2 = GetEntityManager();

$commands = [
    // If you want to add your own custom console commands,
    // you can do so here.
];

$multipleManagerProvider = new MultipleManagerProvider(['em1' => $em1, 'em2' => $em2]);
ConsoleRunner::run($multipleManagerProvider, $commands);

It's now possible to execute the binary with the argument --em=em1or --em=em2

beberlei commented 1 month ago

This use case is what the interface is for, but we dont want to maintain this ourselves, this is why we intentionally only added the single one