Our next step will be to migrate existing code blocks to make use of ServiceManager. Some of the key factories that can be moved into ServiceManager are as follows:
Database connections
Models and table gateways
Forms and filters
Authentication service
If you review the existing code, you will be able to figure out that all the database connections are already using the Zend Framework 2 ServiceManager model for storing credentials. We will take one step forward and move the rest of the factories into ServiceManager using the following steps:
Modify
Module.php
and add a new function to load the ServiceManager configuration:public function getServiceConfig() { return array( 'abstract_factories' => array(), 'aliases' => array(), 'factories' => array( // DB 'UserTable' => function($sm) { $tableGateway = $sm->get('UserTableGateway'); $table = new UserTable($tableGateway); ...