/** * @param Manager $manager * @param Request $request * @return Response * @throws Exception */ function handle(Manager $manager, Request $request) { $response = $request->generateResponse(); if (isset($this->responses[$request->getTid()])) { return $this->responses[$request->getTid()]; } try { if (!isset($this->classes[$request->getAction()])) { throw new Exception(sprintf("Action %s not found", $request->getAction())); } foreach ($this->actions[$request->getAction()] as $info) { if ($request->getMethod() == $info['name']) { $response->setType($request->getType()); $response->setResult($manager->call($this->classes[$request->getAction()], $request->getMethod(), $request->getData())); break; } } if (!$response->getType()) { throw new Exception(sprintf("Method %s not found", $response->getMethod())); } } catch (Exception $e) { $response->setType('exception'); $response->setResult($e->getMessage()); $response->setFile($e->getFile()); $response->setLine($e->getLine()); } return $this->responses[$response->getTid()] = $response; }