Skip to content

Instantly share code, notes, and snippets.

@joshuaadickerson
Last active December 17, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuaadickerson/5566246 to your computer and use it in GitHub Desktop.
Save joshuaadickerson/5566246 to your computer and use it in GitHub Desktop.
<?php
function viewExit(array $context, $status_code = 200, $template = false)
{
call_integration_hook('integrate_pre_view_exit', array(&$context, &$status_code, &$template));
switch ($GLOBALS['output_strategy'])
{
case 'json':
$content_type = 'text/json';
$output = empty($template) ? json_encode($context) : loadJSONTemplate($template, $context);
break;
case 'xml':
$content_type = 'text/xml';
// This obviously requires another function to create a XML map
$output = empty($template) ? xml_encode($context) : loadXMLTemplate($template, $context));
break;
case 'debug':
$content_type = 'text/text';
$output = print_r($context, true);
default:
$content_type = 'text/text';
$output = 'No view strategy selected';
trigger_error($output);
}
call_integration_hook('integrate_view_exit', array(&$context, &$status_code, &$template, &$output);
header('Content-Type: ' . $content_type . '; charset=UTF-8');
http_status_code((int) $status_code);
die($output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment