Created
February 12, 2009 14:26
-
-
Save anonymous/62642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function generate_data_from_internet_or_somewhere(){ | |
return isset($_GET)?$_GET:array(); | |
} | |
function isError1($data){ | |
return !array_key_exists('hoge', $data); | |
} | |
function isError2($data){ | |
return !array_key_exists('piyo', $data); | |
} | |
function build_json_response($isSucceed, $data){ | |
$result = array( | |
'status' => $isSucceed, | |
'result' => $data | |
); | |
return json_encode($result); | |
} | |
function build_responce($data){ | |
if(isError1($data)){ | |
return build_json_response(false, 'error1'); | |
} | |
if(isError2($data)){ | |
return build_json_response(false, 'error2'); | |
} | |
return build_json_response(true, $data); | |
} | |
$data = generate_data_from_internet_or_somewhere(); | |
echo build_responce($data); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment