protected static function _handle($handler, $data, &$response)
{
$params = array('response' => &$response) + compact('handler', 'data');
return static::_filter(__FUNCTION__, $params, function ($self, $params) {
$response = $params['response'];
$handler = $params['handler'];
$data = $params['data'];
$options = $handler;
if (isset($options['request'])) {
$options += $options['request']->params;
unset($options['request']);
}
switch (true) {
case $handler['encode']:
return $self::encode($handler, $data, $response);
case $handler['template'] === false && is_string($data):
return $data;
case $handler['view']:
unset($options['view']);
$instance = $self::view($handler, $data, $response, $options);
return $instance->render('all', (array) $data, $options);
default:
throw new MediaException("Could not interpret type settings for handler.");
}
});
}