/** * @param \Knid\Http\Request $request * @return array */ public function route(\Knid\Http\Request $request) { $requestUri = $request->getServer('REQUEST_URI'); $requestUri = substr($requestUri, mb_strlen(dirname($request->getServer('SCRIPT_NAME')))); foreach ($this->routes as $route) { if ($routeParams = $route->match($requestUri)) { return $routeParams; } } throw new Exception(); }
private function postAction(Http\Request $request, Http\Response $response) { $response->addHeader(new Http\Header('Content-Type', 'application/json; charset=utf-8')); try { $person = new Model\Person(); $person->setName($request->getPost('name')); /* @var $personMapper \Foodalizr\Mapper\PersonMapper */ $personMapper = $this->getMapper('\\Foodalizr\\Mapper\\PersonMapper'); $personMapper->save($person); $response->setContent(new \Knid\Json\Model($person)); } catch (\OutOfBoundsException $e) { $reponse->setContent(json_encode($e)); } return $response; }