public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $args) { $reponse = array(); try { $contenu = $request->getBody()->getContents(); $jsonObject = SiloManager::jsonDecode($contenu); $this->getSiloManager()->addSilos($jsonObject); $reponse['message'] = "Entité ajoutée."; $reponse['code'] = 42; // Je sais, c'est pas très pro. :D return Reponse::postSuccess($response, $reponse); } catch (\Exception $ex) { return Reponse::postError($response, $ex); } }
public function __construct() { parent::__construct(); $this['errorHandler'] = function ($container) { return function (RequestInterface $request, $response, $exception) use($container) { switch ($request->getMethod()) { case "POST": return Reponse::postError($response, $exception); break; case "GET": return Reponse::getError($response, $exception); break; default: return Reponse::error($response, $exception); break; } }; }; }