| 1 |
<?php |
| 2 |
/** |
| 3 |
* Response class |
| 4 |
* |
| 5 |
* @package Calotes\Component |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Calotes\Component; |
| 9 |
|
| 10 |
/** |
| 11 |
* Responsible for managing response data. |
| 12 |
*/ |
| 13 |
class Response { |
| 14 |
|
| 15 |
/** |
| 16 |
* We will need to have a standard of returning data, frontend will base on the return for handling behavior |
| 17 |
* Behaviors: |
| 18 |
* - message: Show a floating notice using this param as content |
| 19 |
* - redirect: Redirect to the URL |
| 20 |
* - interval: As second, if this is set, then we will reload the page in period of time, if we have this with |
| 21 |
* redirect, then, redirect to the URL after period of time Data: |
| 22 |
* - data: Contains the data that return to frontend, can be empty |
| 23 |
* Response constructor. |
| 24 |
* |
| 25 |
* @param boolean $is_success Indicates if the response is a success or not. |
| 26 |
* @param mixed $data The data to be sent in the response. |
| 27 |
*/ |
| 28 |
public function __construct( $is_success, $data ) { |
| 29 |
$is_success ? wp_send_json_success( $data ) : wp_send_json_error( $data ); |
| 30 |
} |
| 31 |
} |
| 32 |
|