我正在开发一个 RESTful 应用程序,我想构建一个工厂,它根据HTTP 请求标头中的(eg ) 参数创建正确的ViewModel
( Zend\View\Model\ViewModel
, Zend\View\Model\JsonModel
, my XmlModel
) 对象。我想将此实现为回调:Accept
-H 'Accept: application/json'
class Module implements ServiceProviderInterface
{
...
public function getServiceConfig() {
try {
return array (
'factories' => array(
'RestViewModel' => function($serviceManager) {
// Here I need the the Request object.
$requestHeadAccept = $requestObject->getHeaders()->get('Accept')->toString();
$return = null;
if (strpos($requestHeadAccept, 'application/json') != -1) {
$return = new JsonModel(array('data' => $data));
} elseif (strpos($requestHeadAccept, 'application/xml') != -1) {
...
} else {
...
}
return $return;
}
)
);
} catch (\Exception $e) {
...
}
}
...
}
我怎样才能Request
在这个地方得到对象?