Example #1
0
 /**
  * Run a specific method from a class and process the response data.
  * If the method contains ":args" the URI segments (except the first one) will be passed as an
  * argument to the method. For example, /hello/world would in this case result in a parameter
  * with a value of "world" being sent to the method.
  *
  * @author Yorick Peterse
  * @param  object $object The object to call the method on.
  * @param  string $method The method to call.
  * @return array
  */
 private static function run_method($object, $method)
 {
     $args = explode('/', Request::uri());
     unset($args[0], $args[1]);
     $body = call_user_func_array(array($object, $method), $args);
     $status = 200;
     $content = 'text/html';
     // A custom content type/status code can be set by returning
     // an array in your method. The first item is the content, the second the
     // status code and the third the content type
     if (is_array($body)) {
         $status = isset($body[1]) ? $body[1] : 200;
         $content = isset($body[2]) ? $body[2] : 'text/html';
         $body = isset($body[0]) ? $body[0] : NULL;
     }
     $status = Request::server_protocol() . ' ' . self::$http_messages[$status];
     return array('body' => $body, 'status' => $status, 'content_type' => $content);
 }