My app uses the data mapper pattern, so I have a number of mapper classes, which each needs an instance of the database adapter. So the factories
section of my service config is filled with entries like this:
'UserMapper' => function($sm) {
$mapper = new UserMapper();
$adapter = $sm->get('Zend\Db\Adapter\Adapter');
$mapper->setAdapter($adapter);
return $mapper;
},
'GroupMapper' => function($sm) {
$mapper = new GroupMapper();
$adapter = $sm->get('Zend\Db\Adapter\Adapter');
$mapper->setAdapter($adapter);
return $mapper;
},
I would like to remove some of this boiler plate code. Is it possible for me to define a custom service locator class just for these mappers, which could instantiate any mapper class by suppliyng the DB adapter, unless a definition exists with some custom factory configuration?