I have a symfony web site that can be browsed in two different contexts. I mean contexts, not applications (I use ysfDimensionsPlugin). In the first context, I authenticate the users using sfGuard bound to a database db1; in the second context, I authenticate the users using sfGuard but bound to a database db2.
Those 2 connections are defined in databases.yml as standard sfDoctrineDatabase objects. In schema.yml, I bind the sfGuard components to the db1 connection. So in my sfGuard base classes, I have this:
Doctrine_Manager::getInstance()->bindComponent('sfGuardUser', 'db1');
What I try to do is to dynamically bind the sfGuard components to the db2 connection if I am in the second context. So in a global preExecute method, I do this:
Doctrine_Manager::getInstance()->bindComponent('sfGuardUser', 'db2');
Doctrine_Manager::getInstance()->bindComponent('sfGuardGroup', 'db2');
The binding is made, but it is immediately overwritten when a query is made: sfAutoload loads the sfGuard classes, including the base classes, calling this:
Doctrine_Manager::getInstance()->bindComponent('sfGuardUser', 'db1');
So I'm asking: how would you implement that to work it out?