/** * Return response with JSON header and status. * * @param PsrResponseInterface|ResponseInterface $response * @param int $status * @return mixed */ public function response($response, $status = 200) { return $response->withStatus($status)->withHeader('Content-Type', 'application/json;charset=utf-8'); }
/** * Ping action. * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return string */ public function ping(ServerRequestInterface $request, ResponseInterface $response) { $data = ['ack' => time(), 'target' => __METHOD__]; $response->write($this->json->render($data)); return $this->json->response($response); }
/** * Show user. * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return \Psr\Http\Message\MessageInterface */ public function user(ServerRequestInterface $request, ResponseInterface $response) { $response->write($this->json->render($this->user->toArray())); return $this->json->response($response); }
/** * Index action. * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return int */ public function home(ServerRequestInterface $request, ResponseInterface $response) { $data = ['routerName' => 'FastRoute', 'routerDocs' => 'https://github.com/nikic/FastRoute', 'templateName' => 'Twig', 'templateDocs' => 'http://twig.sensiolabs.org/documentation']; $response->write($this->template->render('app::index', $data)); return $response; }