doctrine2 - zf2 + Doctrine a different database for each member -


each connected member of site has database. here doctrine config "user_1":

return array( 'doctrine' => array(     'connection' => array(         'orm_default' => array(             'driverclass' => 'doctrine\dbal\driver\pdomysql\driver',             'params' => array(                 'host'     => 'localhost',                 'port'     => '3306',                 'user'     => 'user_1',                 'password' => 'psswd_user_1',                 'dbname'   => 'database_user_1',                 'charset' => 'utf8',                 'driveroptions' => array (1002 => 'set names utf8'),             )),),),); 

is there way replace : 'user_1', 'psswd_user_1' , 'database_user_1' 'user_x', 'psswd_user_x' , 'database_user_x' user_x ?

i don't know how ! i'd avoid copying same code each user ...

thank help

the proper way might inject configuration need when connection created. couldn't find event hook that, have find right service manager key override.

with little bit of source code digging, found these options sent doctrineormmodule\options\dbalconnection instance , instance created doctrineormmodule\service\dbalconnectionfactory

you need override factory this:

<?php namespace mymodule\service; use doctrineormmodule\service\dbalconnectionfactory; use zend\servicemanager\servicelocatorinterface;  class mydbalconnectionfactory extends dbalconnectionfactory {      public function getoptions(servicelocatorinterface $sl, $key, $name = null)     {         $options = parent::getoptions($sl, $key, $name);          // override needs dbalconnection         if ($this->getoptionclass() === 'doctrineormmodule\options\dbalconnection') {               // set custom parameters here              // maybe fetch current user $sl->get('...')              $params = [/* ... */];              $options->setparams($params);         }          return $options;     } } 

and tell service manager it:

<?php  return [     ...     'doctrine' => [         'doctrine_factories' => [             'connection' => 'mymodule\service\dbalconnectionfactory',         ]     ]     ... ]; 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -