1
votes

I have a SaaS Symfony2 project with many bundles and a global database connection defined in config.yml. Now lets say, a specific client wants some custom funcionality. Because I want it to be integrated with my main project I decided to create a new bundle with the code specific of that client. That bundle might need some new database tables, but because they are specific to that client I create a new database with them.

Then I need to define a new doctrine connection. Instead of putting all the conenction settings in the main config.yml (which can become quite confusing if I have 10 clients with a specific bundle) is there any way I can define it in some config file inside the client bundle?. That way I can easily encapsulate all the client code and configurations inside the bundle

I think that it might be possible with the Dependency Injection componnet and using a Compiler Pass to create the new database connection based in some parameters file defined in the bundle but I am not sure how to do it. Also I need to define some listeners related to the connection (Doctrine Extensions) which makes the task even harder.

I think I will have only one "client bundle" active in each request, so maybe I can define some "client" connection and then change the connection string at runtime? (Well in this case I need to make sure to load only the correct client bundle, based on subdomain or something).

Thank you for your help.

2
did you solve this problem at the end? Can you please guide how did you do this ? - Nis

2 Answers

0
votes

You could start from DoctrineExtension.php in /vendor/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/DependencyInjection/

It contains two methods loadDbalConnection() and loadOrmEntityManager() that load the configuration values and build Connection and Mappings objects. You can copy the code you need from that class.

-1
votes

Take a look at \src\Acme\DemoBundle\DependencyInjection\AcmeDemoExtension.php and the folder \src\Acme\DemoBundle\Resources\config* With that you can load yml or xml files and setup the database connection and the mappings you need.