dolibarr 24.0.0-beta
jsonResponse.class.php
1<?php
2/* Copyright (C) 2024 John BOTELLA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
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 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18
24{
25
31 public $result = 0;
32
38 public $data;
39
45 public $debug;
46
52 public $msg = '';
53
59 public $newToken = '';
60
64 public function __construct()
65 {
66 $this->newToken = newToken();
67 }
68
74 public function getResponse()
75 {
76
77 if (!$this->result && !headers_sent()) {
78 http_response_code(400);
79 }
80
81 $jsonResponse = new stdClass();
82 $jsonResponse->result = $this->result;
83 $jsonResponse->msg = $this->msg;
84 $jsonResponse->newToken = $this->newToken;
85 $jsonResponse->data = $this->data;
86 $jsonResponse->debug = $this->debug;
87
88 return json_encode($jsonResponse, JSON_PRETTY_PRINT);
89 }
90}
Class JsonResponse used for ajax responses in Dolibarr.
__construct()
JsonResponse constructor.
$msg
returned message used usually as set event message
getResponse()
return json encoded of object