ongoing internationalization of date widget
[openemr.git] / common / http / HttpResponseHelper.php
blob119830524f984339ff4e6ea683343f2bb7db8ae4
1 <?php
2 /**
3 * HttpResponseHelper
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>;.
16 * @package OpenEMR
17 * @author Matthew Vita <matthewvita48@gmail.com>
18 * @link http://www.open-emr.org
21 namespace OpenEMR\Common\Http;
23 class HttpResponseHelper
25 public static function send($statusCode, $payload, $serializationStrategy)
27 $response = null;
29 if (method_exists($payload, 'toSerializedObject')) {
30 $payload = $payload->toSerializedObject();
33 switch ($serializationStrategy) {
34 case 'JSON':
35 $messageObject = null;
36 if (is_string($payload)) {
37 $messageObject = new \stdClass();
38 $messageObject->message = $payload;
41 header("Content-Type: application/json; charset=utf-8");
42 if (!empty($messageObject)) {
43 $response = json_encode($messageObject);
44 } else {
45 $response = json_encode($payload);
47 break;
50 header("Expires: on, 01 Jan 1970 00:00:00 GMT");
51 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
52 header("Cache-Control: no-store, no-cache, must-revalidate");
53 header("Cache-Control: post-check=0, pre-check=0", false);
54 header("Pragma: no-cache");
55 http_response_code($statusCode);
57 echo $response;