function main() { try { session_start(); $this->user = $_SESSION['user']; $method = @$_REQUEST['method']; $global = new GlobalCalls($this); if (empty($method)) { throw new Error('No method parameter specified'); } else { if (preg_match('/^(\\w+)\\.(.+)$/', $method, $matches)) { list(, $target, $submethod) = $matches; $class = ucfirst("{$target}"); $relay = new $class($this); if (!method_exists($relay, $submethod)) { throw new Error("Method '{$method}' not defined.", $target); } $response = $relay->{$submethod}(); } else { if (method_exists($global, $method)) { $response = $global->{$method}(); } else { throw new Error("Method '{$method}' not defined."); } } } $_SESSION['user'] = $this->user; } catch (Error $e) { $response = Response::currentResponse(); $response->handleError($e); } header('Content-type: text/plain'); echo $response; }