本文整理汇总了PHP中Slim\Http\Request::getBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getBody方法的具体用法?PHP Request::getBody怎么用?PHP Request::getBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Request
的用法示例。
在下文中一共展示了Request::getBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBody
public function getBody()
{
$body = $this->request->getBody();
if ($body == '') {
return array();
}
return json_decode($body, true);
}
示例2: buildParams
private function buildParams(array $params = array())
{
$body = $this->request->getBody();
if (is_array($body) === false) {
$body = array();
}
if (array_key_exists(0, $body) === true) {
$body = array(self::PARAM_REQUEST_BODY => $body);
}
return array_replace($this->request->params(), $body, $params);
}
示例3: getPayload
public function getPayload()
{
$payload = json_decode($this->request->getBody(), true);
$exception = null;
switch (json_last_error()) {
case JSON_ERROR_NONE:
break;
case JSON_ERROR_DEPTH:
$exception = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$exception = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
$exception = 'Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
$exception = 'Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
$exception = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$exception = 'Unknown error';
break;
}
if ($exception) {
throw new \Exception('Error decoding payload: ' . $exception);
}
return $payload;
}
示例4: __invoke
/**
* Execute the middleware.
*
* @param \Slim\Http\Request $req
* @param \Slim\Http\Response $res
* @param callable $next
* @return \Slim\Http\Response
*/
public function __invoke(Request $req, Response $res, callable $next)
{
$uri = $req->getUri();
$path = $this->filterTrailingSlash($uri);
if ($uri->getPath() !== $path) {
return $res->withStatus(301)->withHeader('Location', $path)->withBody($req->getBody());
}
// if ($this->filterBaseurl($uri)) {
// return $res->withStatus(301)
// ->withHeader('Location', (string) $uri)
// ->withBody($req->getBody());
// }
$server = $req->getServerParams();
if (!isset($server['REQUEST_TIME_FLOAT'])) {
$server['REQUEST_TIME_FLOAT'] = microtime(true);
}
$uri = $uri->withPath($path);
$req = $this->filterRequestMethod($req->withUri($uri));
$res = $next($req, $res);
$res = $this->filterPrivateRoutes($uri, $res);
// Only provide response calculation time in non-production env, tho.
if ($this->settings['mode'] !== 'production') {
$time = (microtime(true) - $server['REQUEST_TIME_FLOAT']) * 1000;
$res = $res->withHeader('X-Response-Time', sprintf('%2.3fms', $time));
}
return $res;
}
示例5: borrartipoturnosucursal
function borrartipoturnosucursal(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
$id = $request->getAttribute("id");
$tipo = Tipoturnosucursal::select("*")->where("idsucursal", "=", $id)->delete();
$response->getBody()->write($tipo);
return $response;
}
示例6: eliminarservicios
function eliminarservicios(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
$id = $request->getAttribute("idempleado");
$tipo = ServiciosEmpleado::select("*")->where("idEmpleado", "=", $id)->delete();
$response->getBody()->write($tipo);
return $response;
}
示例7: promocionesByCategorias
function promocionesByCategorias(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
$data = Promocion::select("promocion.*")->join("categoriaspromocion", "categoriaspromocion.idPromocion", "=", "promocion.id")->whereIn("categoriaspromocion.idCategoria", $data['categorias'])->distinct()->get();
if (count($data) == 0) {
$response = $response->withStatus(404);
}
$response->getBody()->write($data);
return $response;
}
示例8: putIdPushByUsuario
function putIdPushByUsuario(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$id = $request->getAttribute('id');
$data = json_decode($request->getBody(), true);
try {
$usuario = Usuario::where('id', '=', $id)->first();
$usuario->idPush = $data['idPush'];
$usuario->save();
$respuesta = json_encode(array('msg' => "Modificado correctamente", "std" => 1, "obj" => $cliente));
$response = $response->withStatus(200);
} catch (Exception $err) {
$respuesta = json_encode(array('msg' => "Error al modificar", "std" => 0, "err" => $err->getMessage()));
$response = $response->withStatus(404);
}
$response->getBody()->write($respuesta);
return $response;
}
示例9: postCalificacion
function postCalificacion(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$idEmpresa = $request->getAttribute('email');
$data = json_decode($request->getBody(), true);
try {
$ce = new CalificacionEmpresa();
$ce->calificacion = $data['calificacion'];
$ce->idEmpresa = $idEmpresa;
$ce->save();
$respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data));
$response = $response->withStatus(200);
} catch (Exception $err) {
$respuesta = json_encode(array('msg' => "erro al calificar", "std" => 0, "err" => $err->getMessage()));
$response = $response->withStatus(404);
}
$response->getBody()->write($respuesta);
return $response;
}
示例10: post
function post(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
try {
$calificacion = new CalificacionCliente();
$calificacion->idCliente = $data['idCliente'];
$calificacion->idEmpleado = $data['idEmpleado'];
$calificacion->calificacion = $data['calificacion'];
$calificacion->save();
$respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1));
$response = $response->withStatus(200);
} catch (Exception $err) {
$respuesta = json_encode(array('msg' => "error", "std" => 0, "err" => $err->getMessage()));
$response = $response->withStatus(404);
}
$response->getBody()->write($respuesta);
return $response;
}
示例11: addgaleria
function addgaleria(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
try {
$id = $request->getAttribute("id");
$galeria = new Galeria();
$galeria->logo = $data['logo'];
$galeria->idSucursal = $data['idsucursal'];
$galeria->fecha = fechaHoraActual();
$galeria->save();
$respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1));
$response = $response->withStatus(200);
} catch (Exception $err) {
$respuesta = json_encode(array('msg' => "error", "std" => 0, "err" => $err->getMessage()));
$response = $response->withStatus(404);
}
$response->getBody()->write($respuesta);
return $response;
}
示例12: postSucursales
function postSucursales(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
try {
$sucursal = new Sucursal();
$sucursal->nombre = $data['nombre'];
$sucursal->direccion = $data['direccion'];
$sucursal->latitud = $data['latitud'];
$sucursal->longitud = $data['longitud'];
$sucursal->idEmpresa = $data['idEmpresa'];
$sucursal->save();
$respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data));
$response = $response->withStatus(200);
} catch (Exception $err) {
$respuesta = json_encode(array('msg' => "La sucursal ya existe", "std" => 0, "err" => $err->getMessage()));
$response = $response->withStatus(404);
}
$response->getBody()->write($respuesta);
return $response;
}
示例13: putFoto
function putFoto(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$idOferta = $request->getAttribute('id');
$data = $request->getBody();
try {
$fp = fopen($idOferta . '.jpg', 'wb');
fwrite($fp, $data);
fclose($fp);
$fo = new FotosOferta();
$fo->foto = $rutaServidor . "fotos/" . $idOferta . ".jpg";
$fo->idOferta = $idOferta;
$fo->save();
$respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data));
$response = $response->withStatus(200);
} catch (Exception $err) {
$respuesta = json_encode(array('msg' => "Error al guardar foto oferta", "std" => 0, "err" => $err->getMessage()));
$response = $response->withStatus(404);
}
$response->getBody()->write($respuesta);
return $response;
}
示例14: postCategoriasSucursal
function postCategoriasSucursal(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$id = $request->getAttribute('id');
$data = json_decode($request->getBody(), true);
try {
$cc = CategoriasSucursal::where('id', '=', $id)->first();
$cc->delete();
for ($i = 0; $i < count($data['categorias']); $i++) {
$cc = new CategoriasSucursal();
$cc->idCategoria = $data['categorias'][$i];
$cc->idSucursal = $id;
$cc->save();
}
$respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data));
$response = $response->withStatus(200);
} catch (Exception $err) {
$respuesta = json_encode(array('msg' => "La empresa ya existe", "std" => 0, "err" => $err->getMessage()));
$response = $response->withStatus(404);
}
$response->getBody()->write($respuesta);
return $response;
}
示例15: postTurnoRecurrente
public function postTurnoRecurrente(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
$fechaReserva = $data['fechaReserva'];
$rango = $data["rango"];
$meses = $data["meses"];
$fechaFinal = strtotime("+{$meses} month", strtotime($fechaReserva));
$fechaFinal = date('Y/m/d', $fechaFinal);
$datetime1 = new DateTime($fechaReserva);
$datetime2 = new DateTime($fechaFinal);
$interval = $datetime1->diff($datetime2);
$minutosServicio = ServiciosSucursal::select("minutos")->where("idServicio", "=", $data["idServicio"])->where("idSucursal", "=", $data["idSucursal"])->first();
/*
Valores de Rangos
diario = 1
semanal = 2
mensual = 3
*/
switch ($rango) {
case '1':
$tiempo = floor($interval->format('%a'));
break;
case '2':
$tiempo = floor($interval->format('%a') / 7);
break;
default:
$tiempo = $meses;
break;
}
//echo $tiempo;
$fecha = $fechaReserva;
for ($i = 0; $i <= $tiempo; $i++) {
switch ($rango) {
case '1':
$fechaReservaFinal = strtotime("+1 day", strtotime($fecha));
$fechaReservaFinal = date('Y/m/d', $fechaReservaFinal);
break;
case '2':
$fechaReservaFinal = strtotime("+7 day", strtotime($fecha));
$fechaReservaFinal = date('Y/m/d', $fechaReservaFinal);
break;
default:
$fechaReservaFinal = strtotime("+1 month", strtotime($fecha));
$fechaReservaFinal = date('Y/m/d', $fechaReservaFinal);
break;
}
$respuesta = null;
try {
$turno = new Turno();
$turno->idCliente = $data['idCliente'];
$turno->idEmpleado = $data['idEmpleado'];
$turno->idSucursal = $data['idSucursal'];
$turno->idServicio = $data['idServicio'];
$turno->tiempo = 0;
$turno->turno = 0;
$turno->turnoReal = 0;
$turno->tipoTurno = 1;
$turno->estadoTurno = "SOLICITADO";
$turno->estado = "ACTIVO";
$turno->reserva = "A";
$turno->fechaReserva = $fecha;
$turno->horaReserva = $data['horaReserva'];
$horaInicial = $data['horaReserva'];
for ($j = 0; $j < $data["cupos"]; $j++) {
$segundos_horaInicial = strtotime($horaInicial);
$segundos_minutoAnadir = $minutosServicio->minutos * 60;
$nuevaHora = date("H:i", $segundos_horaInicial + $segundos_minutoAnadir);
$horaInicial = $nuevaHora;
}
$turno->horaFinalReserva = $nuevaHora;
$turno->save();
$fecha = $fechaReservaFinal;
$respuesta = json_encode(array('msg' => "Su turno ha sido asignado satisfactoriamente.", "std" => 1, 'idTurno' => $turno->id));
$response = $response->withStatus(200);
} catch (Exception $err) {
$respuesta = json_encode(array('msg' => "error al pedir el turno", "std" => 0, "err" => $err->getMessage()));
$response = $response->withStatus(404);
}
}
$response->getBody()->write($respuesta);
return $response;
}