I'm developing a RESTful application and I want to build a factory that creates the proper ViewModel (Zend\View\Model\ViewModel, Zend\View\Model\JsonModel, my XmlModel) object dependent on the Accept (e.g. -H 'Accept: application/json') parameter in the HTTP request header. I want to implement this as a callback:
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) {
            ...
        }
    }
...
}
How can I get the Request object at this place?