public static function output($statusCode, array $data = null)
{
// get output format
$allowedFormats = array('xml', 'json');
// use XML as a default
$output = 'xml';
// use the accept header if it is provided
if (isset($_SERVER['HTTP_ACCEPT'])) {
$acceptHeader = mb_strtolower($_SERVER['HTTP_ACCEPT']);
if (mb_substr_count($acceptHeader, 'text/xml') > 0) {
$output = 'xml';
}
if (mb_substr_count($acceptHeader, 'application/xml') > 0) {
$output = 'xml';
}
if (mb_substr_count($acceptHeader, 'text/json') > 0) {
$output = 'json';
}
if (mb_substr_count($acceptHeader, 'application/json') > 0) {
$output = 'json';
}
}
// format specified as a GET-parameter will overrule the one provided through the accept headers
$output = \SpoonFilter::getGetValue('format', $allowedFormats, $output);
// if the format was specified in the POST it will overrule all previous formats
$output = \SpoonFilter::getPostValue('format', $allowedFormats, $output);
// return in the requested format
switch ($output) {
// json
case 'json':
self::outputJSON($statusCode, $data);
break;
// xml
// xml
default:
self::outputXML($statusCode, $data);
}
return $statusCode === 200;
}