| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of ResultBuilder |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace AliNext_Lite;; |
| 10 |
|
| 11 |
class ResultBuilder { |
| 12 |
|
| 13 |
public static function build($state, $message = "", $object = false, $json=false) { |
| 14 |
$result = array('state' => $state); |
| 15 |
if ($message) { |
| 16 |
$result['message'] = $message; |
| 17 |
} |
| 18 |
if ($object) { |
| 19 |
if (is_array($object)) { |
| 20 |
foreach ($object as $key => $value) { |
| 21 |
if ($key != 'state' && $key != 'message') { |
| 22 |
$result[$key] = $value; |
| 23 |
} |
| 24 |
} |
| 25 |
} else { |
| 26 |
$result['object'] = $object; |
| 27 |
} |
| 28 |
} |
| 29 |
return $json?wp_json_encode($result):$result; |
| 30 |
} |
| 31 |
|
| 32 |
public static function buildOk($object = false, $json=false) { |
| 33 |
return self::build("ok", false, $object, $json); |
| 34 |
} |
| 35 |
|
| 36 |
public static function buildError($message, $object = false, $json=false) { |
| 37 |
return self::build("error", $message, $object, $json); |
| 38 |
} |
| 39 |
|
| 40 |
public static function buildWarn($message, $object = false, $json=false) { |
| 41 |
return self::build("warn", $message, $object, $json); |
| 42 |
} |
| 43 |
|
| 44 |
} |