在Zend框架2用户的相册示例性引导的模型被配置是这样的:Zend Framework 2用户指南中初始化的ServiceManager对象在哪里?
<?php
namespace Album;
// Add these import statements:
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
class Module
{
// getAutoloaderConfig() and getConfig() methods here
// Add this method:
public function getServiceConfig()
{
return array(
'factories' => array(
'Album\Model\AlbumTable' => function($sm) {
$tableGateway = $sm->get('AlbumTableGateway');
$table = new AlbumTable($tableGateway);
return $table;
},
'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
}
可变$sm
是Zend\ServiceManager\ServiceManager
对象。但是,如何/何时/何地创建/初始化?
编辑:
我想知道的是:如何/在哪里呢$sm
得到它的值(和成为的ServiceManager对象)。
我会等待来自ZF2,离散事件之一的答案,但我的假设是这条线:https://github.com/zendframework/zf2/blob/master/library/Zend/ServiceManager/ServiceManager。 PHP#L737 – Sam 2013-03-21 11:43:37
如果您正在使用的应用程序框架,它是由'应用程序初始化::实例化()'这里 - > https://github.com/zendframework/zf2/blob/master/library/Zend/Mvc/Application .php#L236 – Crisp 2013-03-21 12:29:31
谢谢你的回复!我还没有得到,它如何工作。我只是试图制定我的问题exacter,s。编辑。 – automatix 2013-03-21 12:56:04