Created
August 19, 2011 16:30
-
-
Save callumacrae/1157262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * | |
| * @package phpBB3 | |
| * @version $Id$ | |
| * @copyright (c) 2005 phpBB Group | |
| * @license http://opensource.org/licenses/gpl-license.php GNU Public License | |
| * | |
| */ | |
| /** | |
| * @ignore | |
| */ | |
| if (!defined('IN_PHPBB')) | |
| { | |
| exit; | |
| } | |
| /** | |
| * JSON class | |
| * @package phpBB3 | |
| */ | |
| class JSON | |
| { | |
| private $data = array(); | |
| /** | |
| * Send the data to the client and exit the script. | |
| * | |
| * @param array $data Any additional data to send. | |
| * @param bool $exit Will exit the script if true. | |
| */ | |
| public static function send($data = false, $exit = true) | |
| { | |
| if ($data) | |
| { | |
| self::write($data); | |
| } | |
| header('Content-type: application/json'); | |
| echo json_encode(self::$data); | |
| if ($exit) | |
| { | |
| garbage_collection(); | |
| exit_handler(); | |
| } | |
| } | |
| /** | |
| * Saves some data to be written when JSON::send() is called. | |
| * | |
| * @param array $data Data to save to be written. | |
| */ | |
| public static function save($data) | |
| { | |
| self::$data = array_merge(self::$data, $data); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment