PublicRecord 함수 수정, json_encode, json_deocde를 Json로 통합

This commit is contained in:
2018-04-01 19:16:00 +09:00
parent 1f5f7e3591
commit 6ee8066c80
15 changed files with 47 additions and 38 deletions
+18 -9
View File
@@ -2,29 +2,38 @@
namespace sammo;
class Json{
public static function encode($value, $pretty = false){
if($pretty){
$flag = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;
const PRETTY = 1;
const DELETE_NULL = 2;
const NO_CACHE = 4;
public static function encode($value, $flag = 0){
$rawFlag = JSON_UNESCAPED_UNICODE;
if($flag & static::PRETTY){
$rawFlag |= JSON_PRETTY_PRINT;
}
else{
$flag = JSON_UNESCAPED_UNICODE;
if($flag & static::DELETE_NULL){
$value = Util::eraseNullValue($value);
}
return json_encode($value, $flag);
return json_encode($value, $rawFlag);
}
public static function encodePack($value, $pretty = false){
}
public static function decode($value){
return json_decode($value, true);
}
public static function die($value, $noCache = true, $pretty = false, $die = true){
public static function die($value, $flag = NO_CACHE){
//NOTE: REST 형식에 맞게, ok(), fail()로 쪼개는게 낫지 않을까 생각해봄.
if($noCache){
if($flag & static::NO_CACHE){
WebUtil::setHeaderNoCache();
}
header('Content-Type: application/json');
echo Json::encode($value, $pretty);
echo Json::encode($value, $flag);
if($die){
die();
}
+1 -1
View File
@@ -28,7 +28,7 @@ class WebUtil{
$content = trim(file_get_contents("php://input"));
//Attempt to decode the incoming RAW post data from JSON.
$decoded = json_decode($content, true);
$decoded = Json::decode($content);
$jsonError = json_last_error();