/** * @param Request $request */ public function handleRequest($request) { $response = null; $parts = $this->splitPathInfo($request->pathinfo); $resourceOrMethod = $parts[0]; try { if ($this->hasMethod($resourceOrMethod)) { $response = $this->handleApiMethod($resourceOrMethod, $request); } elseif ($this->hasResource($resourceOrMethod)) { $response = $this->handleApiResource($resourceOrMethod, $request); } else { $response = new ApiResponse(); $response->failure("No method or resource with name {$resourceOrMethod} found " . print_r($this->listAvailableMethods(), true)); } if ($this->beforeResponse !== null) { call_user_func($this->beforeResponse, $response); } } catch (\Exception $ex) { $response = new ApiResponse(); $response->failure($ex->getMessage() . ' @ ' . $ex->getFile() . '(' . $ex->getLine() . ') ' . $ex->getTraceAsString()); } $response->send(); }