|
dolibarr 25.0.0-alpha
|
Class JsonResponse used for ajax responses in Dolibarr. More...

Public Member Functions | |
| __construct () | |
| JsonResponse constructor. | |
| getResponse () | |
| return json encoded of object and send the HTTP response code if headers are not already sent | |
| getHttpResponseCode () | |
| Get the HTTP response code that will be sent. | |
| setError ($msg='', $httpCode=self::HTTP_OK) | |
| Set the current response as an error response. | |
| setSuccess ($msg='', $httpCode=self::HTTP_OK) | |
| Set the response as a success. | |
| setHttpResponseCode ($httpCode) | |
| Define the HTTP response code used when sending the JSON response. | |
| output () | |
| Send the JSON response to the client (JSON content-type header, HTTP response code and payload) and stop the script. | |
Private Member Functions | |
| isValidHttpErrorCode ($code) | |
| Check if HTTP code is a valid error code (4xx or 5xx). | |
| isValidHttpSuccessCode ($code) | |
| Check if HTTP code is a valid success code (2xx). | |
Class JsonResponse used for ajax responses in Dolibarr.
Definition at line 23 of file jsonResponse.class.php.
| JsonResponse::getHttpResponseCode | ( | ) |
Get the HTTP response code that will be sent.
If no code was explicitly set, keep the historical behavior: 200 on success, 400 on error.
Definition at line 187 of file jsonResponse.class.php.
References isValidHttpSuccessCode().
Referenced by getResponse().
| JsonResponse::getResponse | ( | ) |
return json encoded of object and send the HTTP response code if headers are not already sent
Definition at line 158 of file jsonResponse.class.php.
References $msg, and getHttpResponseCode().
Referenced by output().
|
private |
Check if HTTP code is a valid error code (4xx or 5xx).
| int | $code | HTTP code |
Definition at line 263 of file jsonResponse.class.php.
Referenced by setError(), and setHttpResponseCode().
|
private |
Check if HTTP code is a valid success code (2xx).
| int | $code | HTTP code |
Definition at line 284 of file jsonResponse.class.php.
Referenced by getHttpResponseCode(), setHttpResponseCode(), and setSuccess().
| JsonResponse::output | ( | ) |
Send the JSON response to the client (JSON content-type header, HTTP response code and payload) and stop the script.
The database handler is closed by dol_shutdown().
Definition at line 299 of file jsonResponse.class.php.
References getResponse(), and top_httphead().
| JsonResponse::setError | ( | $msg = '', | |
| $httpCode = self::HTTP_OK ) |
Set the current response as an error response.
| string | $msg | Error message returned in the JSON response. |
| int | $httpCode | HTTP response code. Defaults to 200 for application errors, as the JSON response already contains the error status and message through the "result" and "msg" fields. Use 4xx/5xx codes when the error must also be reported at the HTTP protocol level (permissions, invalid requests, server failures...). |
Definition at line 211 of file jsonResponse.class.php.
References $msg, isValidHttpErrorCode(), and setHttpResponseCode().
| JsonResponse::setHttpResponseCode | ( | $httpCode | ) |
Define the HTTP response code used when sending the JSON response.
Allowed codes are the HTTP_* constants of this class.
| int | $httpCode | HTTP response code. |
Definition at line 247 of file jsonResponse.class.php.
References isValidHttpErrorCode(), and isValidHttpSuccessCode().
Referenced by setError(), and setSuccess().
| JsonResponse::setSuccess | ( | $msg = '', | |
| $httpCode = self::HTTP_OK ) |
Set the response as a success.
| string | $msg | Success message to return. |
| int | $httpCode | HTTP status code (2xx only, default: 200). |
Definition at line 229 of file jsonResponse.class.php.
References $msg, isValidHttpSuccessCode(), and setHttpResponseCode().