ZF2 Re-starting service manager key

你离开我真会死。 提交于 2019-12-10 11:14:49

问题


I have a database adapter stored in my service manager called "dbAdapter". I am looking for a way to disconnect and then re-connect to this adapter using a slightly different configuration, possibly several times.

The reason is that I have many customers who's database structure is 100% is the same. I am writing a cron job that will do maintance on each database but it has to connect to the first one, do its thing, drop the connection and connect to the next one...until it is out of databases.

I was looking through the source but I could only find a single protected method in Zend\ServiceManager\ServiceManager.php called unregisterService which looks like it would do what I want but it is a protected method and thus I can't call it from my controller.

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


回答1:


You could set $allowOverride to true in the ServiceManager and then register a null value under the name dbAdapter.

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


来源:https://stackoverflow.com/questions/17814122/zf2-re-starting-service-manager-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!