git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3750 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
/** DomFramework
|
|
@package domframework
|
|
@author Dominique Fournier <dominique@fournier38.fr> */
|
|
|
|
require_once ("domframework/output.php");
|
|
/** Display in JSON the data provided
|
|
* The data must NOT be binary !
|
|
*/
|
|
class outputjson extends output
|
|
{
|
|
/** Don't allow to output in JSON if the functions are not available in PHP */
|
|
function __construct ()
|
|
{
|
|
if (!function_exists ("json_encode"))
|
|
throw new Exception ("JSON support not available in PHP ! apt-get ".
|
|
"install php5-json", 500);
|
|
}
|
|
|
|
/** Display in JSOn the data provided
|
|
@param mixed $data The data to be displayed */
|
|
public function out ($data)
|
|
{
|
|
@header("Cache-Control: no-store, no-cache, must-revalidate");
|
|
@header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
|
|
@header('Last-Modified: '.gmdate ('D, d M Y H:i:s').' GMT');
|
|
@header('Cache-Control: post-check=0, pre-check=0', false);
|
|
@header('Pragma: no-cache');
|
|
@header ("Content-Type: application/json");
|
|
$content = json_encode ($data);
|
|
if (json_last_error () !== 0)
|
|
printf (dgettext("domframework", "Can't send in JSON invalid data : %s"),
|
|
json_last_error_msg ());
|
|
echo $content;
|
|
if (!defined ("PHPUNIT"))
|
|
exit;
|
|
}
|
|
}
|