I use an approach that utilizes both methods. I use a Instance::setOptions method to inject configuration and dependencies into an object.
If a class implements OptionsAwareInterface, an Options Manager is used in the Options Aware Inititalizer. This Options Manager looks in configuration for an Options Class defined for the FQCN or Service Manager Alias of the instance being initialized. An Options Object is created and populated with data matching the Options Objects configuration key definition. The Options Manager calls OptionsClass::createOptions with the Service Manager as an argument. The Options Object can then use the Service Manager to set dependencies as properties of the Options Object. If the Options Object has child Options Classes, those are created and the process repeated recursively. The Options Manager calls Instance::setOptions which then sets the Instance Object up as desired. The benefits of this approach IMHO are vastly cleaner Configuration files, and potentially well documented Options Classes with several levels of error handling available. The Options Class is in essence a type of Factory invoked via an Initializer. -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Fundamental-question-Why-isn-t-the-service-manager-super-global-tp4659184p4659451.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
