Created
March 14, 2014 00:00
-
-
Save Diastro/9539653 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| class HTTP{ | |
| const GET = "GET"; | |
| const PUT = "PUT"; | |
| const POST = "POST"; | |
| const DELETE = "DELETE"; | |
| } | |
| class Protocol{ | |
| public static function successResponse($operationType, $type, $data){ | |
| if($operationType == HTTP::GET || $operationType == HTTP::DELETE) | |
| $code = 200; | |
| elseif($operationType == HTTP::PUT || $operationType == HTTP::POST) | |
| $code = 204; | |
| $response = array( | |
| "success" => true, | |
| "status_code" => $code, | |
| "status_message" => "OK", | |
| "payload_type" => $type, | |
| "payload_data" => $data | |
| ); | |
| return json_encode($response); | |
| } | |
| public static function errorResponse($code, $message){ | |
| $response = array( | |
| "success" => false, | |
| "status_code" => $code, | |
| "status_message" => $message, | |
| "payload_type" => null, | |
| "payload_data" => null | |
| ); | |
| return json_encode($response); | |
| } | |
| public static function failureResponse($message){ | |
| $response = array( | |
| "success" => false, | |
| "status_code" => 9999, | |
| "status_message" => $message, | |
| "payload_type" => null, | |
| "payload_data" => null | |
| ); | |
| return json_encode($response); | |
| } | |
| public static function genericResponse($success, $message, $code, $type, $data){ | |
| $response = array( | |
| "success" => $success, | |
| "status_code" => $code, | |
| "status_message" => $message, | |
| "payload_type" => $type, | |
| "payload_data" => $data | |
| ); | |
| return json_encode($response); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment