私のモジュール構成ファイルには、ライブラリとモデルを ServiceManager にロードして、コントローラーで取得できるようにするこれらの行があります。すべてのモデルが同じ依存関係を必要とすることがわかります。これらの反復的なコード ブロックを使用せずに、どうすればそれらを挿入できますか? これは私には間違っているように見えますが、異なるライブラリに対して同じコード行を実行する方法がわかりません。それとも、工場をまったく使用する必要がありますか? ありがとうございました!
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
'factories' => array(
// Models
'Application\Model\Photo' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\Photo($coreLibrary, $io);
return $class;
},
'Application\Model\Album' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\Album($coreLibrary, $io);
return $class;
},
'Application\Model\Tag' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\Tag($coreLibrary, $io);
return $class;
},
'Application\Model\User' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\User($coreLibrary, $io);
return $class;
},
'Application\Model\Message' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\Message($coreLibrary, $io);
return $class;
},
),
),