Using Symfony 4 or 5, im trying to have a single app that talks to doctrine through the entity manager transparently using the default EM but changing connection based on locale.
The idea is to some how check the locale on run time and decide for the correct db connection to use for the entire request. That is, $doctrine->getEntityManager()
should return a manager with the correct connection both for use on the repositories but also by the firewall handling auth and any other service that connects to DB.
BONUS should be possible when running commands to specify what connection to use.
Details:
- Symfony 4 or greater.
- PHP 7>.
- The same model is used for every country.
- For http requests the locale is in the url.
- The url to all databases are in the env files
My own attempt at this:
If tried extending Doctrine\DBAL\Connection
to make a wrapper using doctrines config but have failed to find a way to change all connection settings. (change the URL to master and slave DBs) For both requests and console.
Any help is greatly appreciated