Zend\Db\TableGateway\TableGateway
的Zend Framework 2文档说:
[Zend \ Db \ TableGateway \ TableGateway]构造函数可以将 3种不同形式中的要素作为单个要素对象,作为 FeatureSet对象< / strong>,或作为数组的功能对象。
而TableGateway
构造函数实际上是checks类型。
因此,TableGateway
构造函数的第四个参数需要与Feature\AbstractFeature
或Feature\FeatureSet
兼容,或者是Feature\AbstractFeature
兼容对象的数组。
在model part of the Get Started tutorial中创建了TableGateway
类型的对象,它获得了Zend\Db\ResultSet\ResultSet
作为第四个参数:
class Module
{
// getAutoloaderConfig() and getConfig() methods here
// Add this method:
public function getServiceConfig()
{
return array(
'factories' => array(
...
'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
}
ResultSet
不是instanceof
AbstractFeature
。但它确实有效。
它是如何运作的?