You are here

function _restful_get_json_from_menu_status in RESTful 7

Convert a menu status response to a valid JSON.

Parameters

int $var: The integer value of the menu status, passed by reference.

1 call to _restful_get_json_from_menu_status()
restful_delivery in ./restful.module
Returns data in JSON format.

File

./restful.module, line 697

Code

function _restful_get_json_from_menu_status(&$var) {
  switch ($var) {
    case MENU_NOT_FOUND:
      $class_name = 'RestfulNotFoundException';
      $message = 'Invalid URL path.';
      break;
    case MENU_ACCESS_DENIED:
      $class_name = 'RestfulForbiddenException';
      $message = 'Access denied.';
      break;
    case MENU_SITE_OFFLINE:
      $class_name = 'RestfulServiceUnavailable';
      $message = 'Site is offline.';
      break;
  }
  $e = new $class_name($message);
  $var = array(
    'type' => $e
      ->getType(),
    'title' => $e
      ->getMessage(),
    'status' => $e
      ->getCode(),
    'detail' => $e
      ->getDescription(),
  );
  if ($instance = $e
    ->getInstance()) {
    $var['instance'] = $instance;
  }
  if ($errors = $e
    ->getFieldErrors()) {
    $var['errors'] = $errors;
  }
}