public function encode($data, $options = 0, $depth = 512)
    {
        $server   = $this->getServer();
        $response = $server->getResponse(false);
        $json     = json_encode($data, $options, $depth);
        if (false === $json) {
            throw new RuntimeException(
                json_last_error_msg(),
                json_last_error()
            );
        }
        $response->getBody()->write($json);
        $result = $response->withHeader(
            'Content-Type',
            'application/json;charset=utf-8'
        );

        return $result;
    }