當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Request::getBody方法代碼示例

本文整理匯總了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);
 }
開發者ID:QualityUnit,項目名稱:swagger-codegen,代碼行數:8,代碼來源:Params.class.php

示例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);
 }
開發者ID:benconnito,項目名稱:kopper,代碼行數:11,代碼來源:Controller.php

示例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;
 }
開發者ID:dwsla,項目名稱:deal,代碼行數:31,代碼來源:BaseController.php

示例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;
 }
開發者ID:ninjanero,項目名稱:slim-skeleton,代碼行數:35,代碼來源:CommonMiddleware.php

示例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;
 }
開發者ID:giocni93,項目名稱:Apiturno,代碼行數:9,代碼來源:TipoturnosucursalControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:Apiturno,代碼行數:9,代碼來源:ServiciosEmpleadoControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:BuscaloApi,代碼行數:11,代碼來源:PromocionControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:BuscaloApi,代碼行數:18,代碼來源:UsuarioControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:BuscaloApi,代碼行數:19,代碼來源:EmpresaControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:Apiturno,代碼行數:19,代碼來源:CalificacionClienteControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:Apiturno,代碼行數:20,代碼來源:GaleriaControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:BuscaloApi,代碼行數:21,代碼來源:SucursalControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:BuscaloApi,代碼行數:22,代碼來源:OfertaControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:BuscaloApi,代碼行數:23,代碼來源:CategoriaControl.php

示例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;
 }
開發者ID:giocni93,項目名稱:Apiturno,代碼行數:84,代碼來源:TurnoControl.php


注:本文中的Slim\Http\Request::getBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。