public function add() { if (!$this->application->request->isPost()) { throw new Exception('Method not allowed', 405); } if (!$this->isAllowed()) { throw new Exception('User not authorized', 401); } $postData = $this->application->request->getJsonRawBody(); $status = Status::findFirst(array('name' => $postData->name)); if ($status) { throw new Exception('Status already created', 409); } $status = new Status(); $create = $status->create(array('name' => $postData->name)); if (!$create) { throw new Exception('Status not created', 500); } return array('code' => 201, 'content' => $status->toArray()); }