public function handle()
{
$this->url = $this->getPath();
$this->method = $this->getMethod();
$this->format = $this->getFormat();
if ($this->method == 'PUT' || $this->method == 'POST' || $this->method == 'PATCH') {
$this->data = $this->getData();
}
list($obj, $method, $params, $this->params, $noAuth) = $this->findUrl();
if ($obj) {
if (is_string($obj)) {
if (class_exists($obj)) {
$obj = new $obj();
} else {
throw new Exception("Class {$obj} does not exist");
}
}
$obj->server = $this;
try {
if (method_exists($obj, 'init')) {
$obj->init();
}
if (!$noAuth && method_exists($obj, 'authorize')) {
if (!$obj->authorize()) {
$this->sendData($this->unauthorized(true));
//@todo unauthorized returns void
exit;
}
}
$result = call_user_func_array(array($obj, $method), $params);
if ($result !== null) {
$this->sendData($result);
}
} catch (RestException $e) {
$this->handleError($e->getCode(), $e->getMessage());
}
} else {
$this->handleError(404);
}
}