Exemplo n.º 1
0
 /**
  * Uses stdClass objects to create a complete 
  * object hierarchy for the provided value. The
  * result will still need to go through a call
  * to json_encode before being sent.
  * 
  * Most notably this method handles creating the
  * appropriate classes and filling in the data 
  * fields.
  *
  * @param varies $value
  * @return stdClass
  */
 public static function serialize($value)
 {
     $returnValue = new stdClass();
     if (is_object($value)) {
         $returnValue = $value;
         $returnValue->__class__ = get_class($value);
     } elseif (is_array($value)) {
         foreach ($value as $key => $data) {
             $returnValue->{$key} = JSONSerializer::serialize($data);
         }
     } else {
         $returnValue = $value;
     }
     return $returnValue;
 }
Exemplo n.º 2
0
        }
        break;
    default:
        if (isset($action_map[$request->action])) {
            if (is_array($action_map[$request->action])) {
                if (class_exists($action_map[$request->action][0])) {
                    $class = new $action_map[$request->action][0]();
                    if (method_exists($class, $action_map[$request->action][1])) {
                        $result = call_user_func_array(array($class, $action_map[$request->action][1]), $params);
                        if ($result === false) {
                            $output['error'] = $class->getLastError();
                        } else {
                            $output['result'] = $result;
                        }
                    } else {
                        $output['error'] = "Method {$action_map[$request->action][1]} does not exist in class {$action_map[$request->action][0]} for action {$action}";
                    }
                } else {
                    $output['error'] = "Could not load class {$action_map[$request->action][0]} for action {$request->action}";
                }
            } else {
                //TODO Deal with global methods later
            }
        } else {
            $output['error'] = "Invalid action ({$request->action}) provided";
        }
}
$output['session_id'] = session_id();
log_message(print_r($output, true));
echo json_encode(JSONSerializer::serialize($output));