本文整理汇总了PHP中Slim\Http\Response::getBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getBody方法的具体用法?PHP Response::getBody怎么用?PHP Response::getBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Response
的用法示例。
在下文中一共展示了Response::getBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
public function send()
{
foreach ($this->response->headers() as $name => $value) {
header("{$name}: {$value}", true, $this->response->getStatus());
}
echo $this->response->getBody();
}
示例2: request
protected function request($method, $url, array $requestParameters = [])
{
$request = $this->prepareRequest($method, $url, $requestParameters);
$response = new Response();
$app = $this->app;
$this->response = $app($request, $response);
$this->jsonResponseData = json_decode((string) $this->response->getBody(), true);
}
示例3: request
private function request($method, $path, $data = array(), $optionalHeaders = array())
{
//Make method uppercase
$method = strtoupper($method);
$options = array('REQUEST_METHOD' => $method, 'REQUEST_URI' => $path);
if ($method === 'GET') {
$options['QUERY_STRING'] = http_build_query($data);
} else {
$params = json_encode($data);
}
// Prepare a mock environment
$env = Environment::mock(array_merge($options, $optionalHeaders));
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = $this->cookies;
$serverParams = $env->all();
$body = new RequestBody();
// Attach JSON request
if (isset($params)) {
$headers->set('Content-Type', 'application/json;charset=utf8');
$body->write($params);
}
$this->request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
$response = new Response();
// Invoke request
$app = $this->app;
$this->response = $app($this->request, $response);
// Return the application output.
return (string) $this->response->getBody();
}
示例4: setReactResponse
/**
* It performs the setup of a reactPHP response from a SlimpPHP response
* object and finishes the communication
*
* @param \React\Http\Response $reactResp ReactPHP native response object
* @param \Slim\Http\Response $slimResponse SlimPHP native response object
* @param boolean $endRequest If true, response flush will be finished
*
* @return void
*/
static function setReactResponse(\React\Http\Response $reactResp, \Slim\Http\Response $slimResponse, $endRequest = false)
{
$headers = static::reduceHeaders($slimResponse->getHeaders());
$reactResp->writeHead($slimResponse->getStatusCode(), $headers);
$reactResp->write($slimResponse->getBody());
if ($endRequest === true) {
$reactResp->end();
}
}
示例5: withJson
/**
* withJson
* support JSONP
*
* @return void
*/
public static function withJson(Response $response, $data, $status = 200, $encodingOptions = 0)
{
$body = $response->getBody();
$body->rewind();
$s = json_encode($data, $encodingOptions);
$type = "application/json";
// check jsonp callback
if (!empty($_GET) && !empty($_GET['callback'])) {
$s = $_GET['callback'] . "({$s});";
$type = "text/javascript";
}
$body->write($s);
return $response->withStatus($status)->withHeader('Content-Type', $type . ';charset=utf-8');
}
示例6: __invoke
public function __invoke(Request $request, Response $response)
{
$this->logger->info('log info');
$response->getBody()->write('Hello world');
return $response;
}
示例7: getEmpleadosAll
public function getEmpleadosAll(Request $request, Response $response)
{
$idEmpleado = $request->getAttribute("idEmpleado");
$idServicio = $request->getAttribute("idServicio");
$query = "SELECT DISTINCT " . "emp.id as idEmpleado," . "ser.id as idServicio," . "CONCAT(emp.nombres, ' ', emp.apellidos) AS empleado," . "ser.nombre as servicio, " . "'' as tiempoEstimado, " . "'' as cliente, " . "'' as turnoActual, " . "su.nombre as sucursal, " . "em.razonSocial as Empresa, " . "su.id as idSucursal " . "FROM " . "empleado emp " . "INNER JOIN " . "serviciosempleado seremp " . "ON(seremp.idEmpleado = emp.id) " . "INNER JOIN servicio ser " . "ON(ser.id = seremp.idServicio) " . "INNER JOIN sucursal su " . "ON(su.id = emp.idSucursal) " . "INNER JOIN empresa em " . "ON(em.id = su.idEmpresa) " . "WHERE emp.id = {$idEmpleado} AND " . "ser.id = {$idServicio} AND " . "emp.estadoOnline = 'ACTIVO' AND " . "ser.estado = 'ACTIVO'";
$data = DB::select(DB::raw($query));
for ($i = 0; $i < count($data); $i++) {
//CALCULAR TIEMPO
$query = "SELECT " . "((COALESCE(AVG(TIMESTAMPDIFF(SECOND,fechaInicio,fechaFinal)),0) * turnosFaltantes.faltantes)) as tiempoEstimado, " . "turnosFaltantes.faltantes as turnFaltantes " . "FROM " . "( " . " SELECT " . " count(t.id) as faltantes " . " FROM " . " turno as t " . " WHERE " . " t.idEmpleado = " . $data[$i]->idEmpleado . " AND " . " t.idServicio = " . $data[$i]->idServicio . " AND " . " t.estadoTurno <> 'TERMINADO' AND t.estadoTurno <> 'CANCELADO'" . ") as turnosFaltantes, " . "turno " . "WHERE idEmpleado = " . $data[$i]->idEmpleado . " AND " . "idServicio = " . $data[$i]->idServicio . " AND " . "estadoTurno = 'TERMINADO' " . "LIMIT 1";
$dataTiempo = DB::select(DB::raw($query));
$query = "SELECT " . "tu.turno as turnoActual, " . "CONCAT(cl.nombres,' ',cl.apellidos) as cliente " . "FROM turno as tu " . "INNER JOIN " . "cliente as cl " . "ON(cl.id = tu.idCliente) " . "WHERE tu.idEmpleado = " . $data[$i]->idEmpleado . " AND " . "tu.idServicio = " . $data[$i]->idServicio . " AND " . "(tu.estadoTurno = 'ATENDIENDO' OR " . "tu.estadoTurno = 'CONFIRMADO' OR tu.estadoTurno = 'SOLICITADO') " . "ORDER BY " . "tu.fechaSolicitud DESC " . "LIMIT 1";
$dataCliente = DB::select(DB::raw($query));
if (count($dataTiempo) > 0) {
$val = ceil($dataTiempo[0]->tiempoEstimado / 60);
$str = " minuto";
if ($val == 0) {
//5 min
$val = ceil(5 * $dataTiempo[0]->turnFaltantes);
}
if ($val != 1) {
$str .= "s";
}
$data[$i]->tiempoEstimado = strval($val) . $str;
} else {
$data[$i]->tiempoEstimado = "0 minutos";
}
$data[$i]->turnoActual = 0;
$data[$i]->cliente = "";
if (count($dataCliente) > 0) {
$data[$i]->turnoActual = $dataCliente[0]->turnoActual;
$data[$i]->cliente = $dataCliente[0]->cliente;
}
}
$response->getBody()->write(json_encode($data));
return $response;
}
示例8: testFinalize
public function testFinalize()
{
$method = new \ReflectionMethod('Slim\\App', 'finalize');
$method->setAccessible(true);
$response = new Response();
$response->getBody()->write('foo');
$response = $method->invoke(new App(), $response);
$this->assertTrue($response->hasHeader('Content-Length'));
$this->assertEquals('3', $response->getHeaderLine('Content-Length'));
}
示例9: responseData
protected function responseData()
{
return json_decode((string) $this->response->getBody(), true);
}
示例10: render
public function render(Response $response, $template, $args)
{
$response->getBody()->write($this->fetch($template, $args));
return $response;
}
示例11: redirect
/**
* Redirect to video file.
*
* @param Request $request PSR-7 request
* @param Response $response PSR-7 response
*
* @return Response HTTP response
*/
public function redirect(Request $request, Response $response)
{
$params = $request->getQueryParams();
if (isset($params['url'])) {
try {
$url = $this->download->getURL($params['url'], $params['format']);
return $response->withRedirect($url);
} catch (\Exception $e) {
$response->getBody()->write($e->getMessage());
return $response->withHeader('Content-Type', 'text/plain');
}
}
}
示例12: getResponse
/**
* Returns response body as a string
*
* @return string
*/
public function getResponse()
{
return (string) $this->response->getBody();
}
示例13: getJsonBody
protected function getJsonBody(Response $response)
{
return json_decode((string) $response->getBody(), true);
}
示例14: render_json
function render_json(\Slim\Http\Response $r, $object)
{
$r->getBody()->write(json_encode($object));
return $r;
}
示例15: getReservaByCliente
public function getReservaByCliente(Request $request, Response $response)
{
$idCliente = $request->getAttribute("idCliente");
$fecha_actual = date("Y/m/d");
$query = "SELECT s.nombre AS nombreSucursal, se.nombre AS nombreServicio, t . *, e.nombres as nombreEmpleado, e.apellidos as apellidoEmpleado, em.razonSocial AS nombreEmpresa\n FROM turno t\n INNER JOIN sucursal s ON s.id = t.idSucursal\n INNER JOIN servicio se ON se.id = t.idServicio\n INNER JOIN empleado e ON e.id = t.idEmpleado\n INNER JOIN empresa em ON em.id = s.idEmpresa\n WHERE t.idCliente ='{$idCliente}'\n AND t.fechaReserva >= '{$fecha_actual}'\n AND t.reserva = 'A'\n ";
$data = DB::select(DB::raw($query));
$response->getBody()->write(json_encode($data));
return $response;
}