5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
17 * @author Matthew Vita <matthewvita48@gmail.com>
18 * @link http://www.open-emr.org
21 namespace common\http
;
23 class HttpResponseHelper
{
24 public static function send($statusCode, $payload, $serializationStrategy) {
27 if (method_exists($payload, 'toSerializedObject')) {
28 $payload = $payload->toSerializedObject();
31 switch ($serializationStrategy) {
33 $messageObject = null;
34 if (is_string($payload)) {
35 $messageObject = new \
stdClass();
36 $messageObject->message
= $payload;
39 header("Content-Type: application/json; charset=utf-8");
40 if (!empty($messageObject)) {
41 $response = json_encode($messageObject);
43 $response = json_encode($payload);
49 header("Expires: on, 01 Jan 1970 00:00:00 GMT");
50 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
51 header("Cache-Control: no-store, no-cache, must-revalidate");
52 header("Cache-Control: post-check=0, pre-check=0", false);
53 header("Pragma: no-cache");
54 http_response_code($statusCode);