ZF2 Launch Service Manager

I have a database adapter that is stored in my service manager called "dbAdapter". I am looking for a way to disconnect and then reconnect to this adapter using a slightly different configuration, perhaps several times.

The reason is that I have many clients whose database structure is 100% the same. I am writing a cron job that will perform maintance in each database, but it should connect to the first, do everything, delete the connection and connect to the next ... until it is out of the databases.

I was looking through the source, but I could only find one protected method in Zend \ ServiceManager \ ServiceManager.php called unregisterService, which looks like it will do what I want, but it is a protected method, and therefore I can’t call this is from my controller.

Is it possible to "expire" the key of the service manager and force it to re-create it on the next call?

+2
source share
1 answer

You can set $allowOverrideto truein ServiceManagerand then register the value nullunder the name dbAdapter.

$serviceManager->setAllowOverride(true)
               ->setService('dbAdapter', null)
               ->setAllowOverride(false);
+4
source

All Articles