public function dispatch(Request $request, Response $response, $args) { if ($request->isPost()) { $speaker = new Speaker($request->getParam('first_name'), $request->getParam('last_name'), new Email($request->getParam('email')), new Twitter($request->getParam('twitter'))); $msg = []; try { $this->speakersRepository->save($speaker); $msg['id'] = $speaker->id; } catch (\Exception $e) { $this->logger->debug($e->getMessage()); return $response->withStatus(200)->withHeader('Content-Type', 'application/json')->write(json_encode(['error' => $e->getMessage()])); } return $response->withStatus(201)->withHeader('Content-Type', 'application/json')->write(json_encode($msg)); } }
/** * @param $speakerID * @return Speaker */ public function getSpeakerById($speakerID) { return $this->speakersRepo->getBySpeakerID($speakerID); }