Skip to content

Instantly share code, notes, and snippets.

@Diastro
Created March 14, 2014 00:00
Show Gist options
  • Select an option

  • Save Diastro/9539653 to your computer and use it in GitHub Desktop.

Select an option

Save Diastro/9539653 to your computer and use it in GitHub Desktop.
<?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