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


PHP Request::getParsedBody方法代碼示例

本文整理匯總了PHP中Slim\Http\Request::getParsedBody方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::getParsedBody方法的具體用法?PHP Request::getParsedBody怎麽用?PHP Request::getParsedBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Slim\Http\Request的用法示例。


在下文中一共展示了Request::getParsedBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: login

 /**
  * Intermediario entre el Front-End y el servicio.
  *
  * @param Request $request
  *
  * @return []
  */
 public function login($request)
 {
     $result = [];
     $formData = $request->getParsedBody();
     $email = null;
     $password = null;
     // Verificamos que efectivamente exista una entrada de email
     if (array_key_exists("email", $formData)) {
         $email = $formData["email"];
     }
     // Verificamos que efectivamente exista una entrada de password
     if (array_key_exists("password", $formData)) {
         $password = $formData["password"];
     }
     if (isset($email, $password)) {
         $loginResult = $this->userService->login($email, $password);
         if (array_key_exists("error", $loginResult)) {
             $result["error"] = true;
         } else {
             setcookie($this->nombreCookie, true, time() + 3600);
         }
         $result["message"] = $loginResult["message"];
     } else {
         $result["error"] = true;
         $result["message"] = "Email and password can not be empty.";
     }
     return $result;
 }
開發者ID:meluk,項目名稱:UProyecto1,代碼行數:35,代碼來源:UserController.php

示例2: edit

 public function edit(Request $request, Response $response, array $args)
 {
     $input = $request->getParsedBody();
     /** @var MemberPortfolios $portfolio */
     $portfolio = $this->data(MemberPortfolios::class);
     $validator = $this->validator->rule('required', ['company_name', 'industry_id', 'start_date_y', 'work_status', 'job_title', 'job_desc']);
     if ($input['work_status'] == 'R') {
         $validator->rule('required', 'end_date_y');
     }
     if ($validator->validate()) {
         if ($input['work_status'] == 'A') {
             unset($input['end_date_y'], $input['end_date_m'], $input['end_date_d']);
         }
         try {
             $update = $portfolio->update($input, (int) $args['id']);
             $message = 'Item portfolio berhasil diperbaharui. Selamat!';
         } catch (\PDOException $e) {
             $update = false;
             $message = 'System error!<br>' . $e->getMessage();
         }
         $this->addFormAlert($update !== false ? 'success' : 'error', $message);
     } else {
         $this->addFormAlert('warning', 'Some of mandatory fields is empty!', $validator->errors());
         return $response->withRedirect($this->router->pathFor('membership-portfolios-edit', $args));
     }
     return $response->withRedirect($this->router->pathFor('membership-account'));
 }
開發者ID:aswitahidayat,項目名稱:phpindonesia.or.id-membership2,代碼行數:27,代碼來源:PortfoliosController.php

示例3: create

 /**
  * Create a new user with the data provided in the request body and return a JWT to start the User's session
  * @todo Figure out way to make exceptions more DRY, the way its currently set up each method would have all of these
  *       blocks.
  */
 public function create(Request $request, Response $response, array $args)
 {
     $logger = $this->getLogger();
     $data = $request->getParsedBody();
     $logger->addInfo('Creating new user', $data);
     $user = UserModel::create($data)->toArray();
     $jwt = ["email" => $user["email"], "id" => $user["uid"]];
     $jwt = $this->encodeJWT($jwt);
     return $response->withJson($jwt);
 }
開發者ID:folkevil,項目名稱:Skeleton-API,代碼行數:15,代碼來源:User.php

示例4: createRelationsAction

 /**
  * Save organizations relations action
  *
  * @param Request $request
  * @param Response $response
  * @param array $args
  *
  * @return Response
  */
 public function createRelationsAction(Request $request, Response $response, $args)
 {
     // TODO: add validation for content type
     // TODO: add validation for data structure
     $relations = $request->getParsedBody();
     $relations = $this->serializer->deserialize($relations);
     $relations = $this->service->saveRelations($relations);
     $relations = $this->serializer->serialize($relations, Context::AS_TREE);
     return $response->withJson($relations, 201);
 }
開發者ID:EugeneKirillov,項目名稱:organization-relationships,代碼行數:19,代碼來源:OrganizationsController.php

示例5: learningcenterPostEdit

 public function learningcenterPostEdit(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $postBody = $req->getParsedBody();
     $editParams = $this->adapterParams($postBody);
     if ($db->update("learningcenter", $editParams, ["id" => $attr["id"]]) !== false) {
         return $res->withHeader("Location", $req->getUri()->getBasePath() . "/learningcenter");
     }
     return $container->view->render($res, "learningcenter/form.twig", ["form" => $postBody]);
 }
開發者ID:nuiz,項目名稱:gis,代碼行數:11,代碼來源:LearningCenterController.php

示例6: updateAction

 public function updateAction(Request $request, Response $response, array $args)
 {
     $data = $request->getParsedBody();
     $task = $this->_transformer->transformToModel($data);
     if ($task === null) {
         return $this->_infoPresenter->render($response, Presenter::STATUS_UNPROCESSABLE_ENTITY, Presenter::DESCRIPTION_INVALID_STRUCTURE);
     }
     $newTask = $this->_taskService->update($args['taskId'], $task);
     if ($newTask !== null) {
         return $this->_dataPresenter->render($response, Presenter::STATUS_ACCEPTED, $newTask);
     } else {
         return $this->_infoPresenter->render($response, Presenter::STATUS_NOT_FOUND, Presenter::DESCRIPTION_NONEXISTING_KEY);
     }
 }
開發者ID:Gerschtli,項目名稱:time-manager,代碼行數:14,代碼來源:Task.php

示例7: teamAdd

 public function teamAdd(Request $request, Response $response, $args)
 {
     $data = $request->getParsedBody();
     /** @var EntityManager $em */
     $em = $this->container->entityManager;
     $team = new Team();
     $team->setName($data['name']);
     $team->setLeague($em->find('Fanta\\Entity\\League', $data['league_id']));
     $team->setUser($em->find('Fanta\\Entity\\User', $data['user_id']));
     $team->setName($data['name']);
     $em->persist($team);
     $em->flush();
     return $response->withRedirect($this->container->router->pathFor('league-detail', array('league_id' => $data['league_id'])));
 }
開發者ID:grisoni77,項目名稱:Fanta-Slim-3-,代碼行數:14,代碼來源:Admin.php

示例8: accountPostEdit

 public function accountPostEdit(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $postBody = $req->getParsedBody();
     $editParams = $this->adapterParams($postBody);
     // var_dump($editParams); exit();
     if ($db->count("account", ["AND" => ["username" => @$postBody["username"], "id[!]" => $attr["id"]]]) > 0) {
         return $container->view->render($res, "account/form.twig", ["form" => $postBody, "error_message" => "ชื่อผู้ใช้งานซ้ำกับผู้ใช้งานอื่น"]);
     }
     if ($db->update("account", $editParams, ["id" => $attr["id"]]) !== false) {
         return $res->withHeader("Location", $req->getUri()->getBasePath() . "/account");
     }
     return $container->view->render($res, "account/form.twig", ["form" => $postBody]);
 }
開發者ID:nuiz,項目名稱:gis,代碼行數:15,代碼來源:AccountController.php

示例9: login

 public function login(Request $request, $response, $args)
 {
     /** @var EntityManager $em */
     $em = $this->container->entityManager;
     $data = $request->getParsedBody();
     $user = $em->getRepository('Fanta\\Entity\\User')->findOneBy(array('name' => $data['user']));
     if (!$user) {
         return $response->withStatus(403, 'User not found');
     }
     if ($user->getPassword() != $this->container->auth->getEncryptedPassword($data['password'])) {
         return $response->withStatus(403, 'Incorrect password');
     }
     $this->container->session->createSession($user);
     return $response->withRedirect($this->container->router->pathFor('front-teams'));
 }
開發者ID:grisoni77,項目名稱:Fanta-Slim-3-,代碼行數:15,代碼來源:Front.php

示例10: product_youtubePostAdd

 public function product_youtubePostAdd(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $postBody = $req->getParsedBody();
     // $insertParams = $this->adapterParams($postBody);
     $insertParams = [];
     $insertParams["product_id"] = $attr["product_id"];
     $insertParams["type"] = "youtube";
     $insertParams["youtube_id"] = $postBody["youtube_id"];
     $insertParams["sort_order"] = $db->max("product_media", "sort_order", ["AND" => ["product_id" => $attr["product_id"]]]) + 1;
     if (!$db->insert("product_media", $insertParams)) {
         return $res->withStatus(500)->withHeader('Content-Type', 'application/json')->write(json_encode(["error" => true]));
     }
     return $res->withStatus(200)->withHeader('Content-Type', 'application/json')->write(json_encode(["success" => true]));
 }
開發者ID:icezlizz1991,項目名稱:tufftexgroup,代碼行數:16,代碼來源:ProductMediaController.php

示例11: register

 public function register(Request $request, Response $response, array $args)
 {
     /** @var Users $users */
     $users = $this->data(Users::class);
     $input = $request->getParsedBody();
     $validator = $this->validator->rule('required', ['email', 'username', 'fullname', 'password', 'repassword', 'job_id', 'gender_id', 'province_id', 'area']);
     $validator->addRule('assertEmailNotExists', function ($field, $value, array $params) use($users) {
         return !$users->assertEmailExists($value);
     }, 'tersebut sudah terdaftar! Silahkan gunakan email lain');
     $validator->addRule('assertUsernameNotExists', function ($field, $value, array $params) use($users) {
         $protected = ['admin', 'account', 'login', 'register', 'logout', 'activate', 'reactivate', 'regionals', 'forgot-password', 'reset-password'];
         return !in_array($value, $protected) && !$users->assertUsernameExists($value);
     }, 'tersebut sudah terdaftar! Silahkan gunakan username lain');
     $validator->rules(['regex' => [['fullname', ':^[A-z\\s]+$:'], ['username', ':^[A-z\\d\\-\\_]+$:']], 'email' => 'email', 'assertEmailNotExists' => 'email', 'assertUsernameNotExists' => 'username', 'dateFormat' => [['birth_date', 'Y-m-d']], 'equals' => [['repassword', 'password']], 'notIn' => [['username', 'password']], 'lengthMax' => [['username', 32], ['fullname', 64], ['area', 64]], 'lengthMin' => [['username', 6], ['password', 6]]]);
     if ($validator->validate()) {
         $emailAddress = $input['email'];
         $activationKey = md5(uniqid(rand(), true));
         $activationExpiredDate = date('Y-m-d H:i:s', time() + 172800);
         // 48 jam
         $registerSuccessMsg = 'Haayy <strong>' . $input['fullname'] . '</strong>,<br> Submission keanggotan sudah berhasil disimpan. Akan tetapi account anda tidak langsung aktif. Demi keamanan dan validitas data, maka sistem telah mengirimkan email ke email anda, untuk melakukan aktivasi account. Segera check email anda! Terimakasih ^_^';
         try {
             $input['activation_key'] = $activationKey;
             $input['expired_date'] = $activationExpiredDate;
             $input['fullname'] = ucwords($input['fullname']);
             $input['password'] = $this->salt($input['password']);
             if ($userId = $users->create($input)) {
                 $emailSettings = $this->settings->get('email');
                 $message = \Swift_Message::newInstance('PHP Indonesia - Aktivasi Membership')->setFrom([$emailSettings['sender_email'] => $emailSettings['sender_name']])->setTo([$emailAddress => $member['fullname']])->setBody(file_get_contents(APP_DIR . 'views' . _DS_ . 'email' . _DS_ . 'activation.txt'));
                 $this->mailer->registerPlugin(new \Swift_Plugins_DecoratorPlugin([$emailAddress => ['{email_address}' => $emailAddress, '{fullname}' => $input['fullname'], '{registration_date}' => date('d-m-Y H:i:s'), '{activation_path}' => $this->router->pathFor('membership-activation', ['uid' => $userId, 'activation_key' => $activationKey]), '{activation_expired_date}' => $activationExpiredDate, '{base_url}' => $request->getUri()->getBaseUrl()]]));
                 $this->mailer->send($message);
                 // Update email sent status
                 $this->data(UsersActivations::class)->update(['email_sent' => 'Y'], ['user_id' => $userId, 'activation_key' => $activationKey]);
             }
         } catch (\Swift_TransportException $e) {
             $registerSuccessMsg .= '<br><br><strong>Kemungkinan email akan sampai agak terlambat, karena email server kami sedang mengalami sedikit kendala teknis. Jika anda belum juga mendapatkan email, maka jangan ragu untuk laporkan kepada kami melalu email: report@phpindonesia.or.id</strong>';
         } catch (\PDOException $e) {
             $this->addFormAlert('error', 'System failed<br>' . $e->getMessage());
             return $response->withRedirect($this->router->pathFor('membership-register'));
         }
         $this->addFormAlert('success', $registerSuccessMsg);
     } else {
         $this->addFormAlert('warning', 'Some of mandatory fields is empty!', $validator->errors());
         return $response->withRedirect($this->router->pathFor('membership-register'));
     }
     return $response->withRedirect($this->router->pathFor('membership-index'));
 }
開發者ID:phpindonesia,項目名稱:phpindonesia.or.id-membership2,代碼行數:46,代碼來源:HomeController.php

示例12: createGame

 /**
  *
  * @param Request $request
  *
  * @return []
  */
 public function createGame($request)
 {
     $result = [];
     /**
      *The content of `POST`
      *I get calling `getParsedBody`.
      */
     $formData = $request->getParsedBody();
     $title = null;
     $developer = null;
     $description = null;
     $console = null;
     $releaseDate = null;
     $rate = null;
     $url = null;
     // Verified that excites title
     if (array_key_exists("title", $formData)) {
         $title = $formData["title"];
     }
     // Verified that excites developer
     if (array_key_exists("developer", $formData)) {
         $developer = $formData["developer"];
     }
     // Verified that excites description
     if (array_key_exists("description", $formData)) {
         $description = $formData["description"];
     }
     // Verified that excites console
     if (array_key_exists("console", $formData)) {
         $console = $formData["console"];
     }
     // Verified that excites releaseDate
     if (array_key_exists("releaseDate", $formData)) {
         $releaseDate = $formData["releaseDate"];
     }
     // Verified that excites rate
     if (array_key_exists("rate", $formData)) {
         $rate = $formData["rate"];
     }
     // Verified that excites url
     if (array_key_exists("url", $formData)) {
         $url = $formData["url"];
     }
     return $this->gameService->createGame($title, $developer, $description, $console, $releaseDate, $rate, $url);
 }
開發者ID:meluk,項目名稱:UProyecto1,代碼行數:51,代碼來源:gameController.php

示例13: sanitizeRequestBody

 /**
  * @param \Slim\Http\Request  $request
  * @param \Slim\Http\Response $response
  * @param callable            $next
  * @return mixed
  */
 public function sanitizeRequestBody(Request $request, Response $response, callable $next)
 {
     if ($inputs = $request->getParsedBody()) {
         $inputs = array_filter($inputs, function (&$value) {
             if (is_string($value)) {
                 $value = filter_var(trim($value), FILTER_SANITIZE_STRING);
             }
             return $value ?: null;
         });
         if (isset($inputs['_METHOD']) && $request->getMethod() == $inputs['_METHOD']) {
             unset($inputs['_METHOD']);
         }
         $request = $request->withParsedBody($inputs);
     }
     if ($request->getHeaderLine('Accept') == 'application/json') {
         $request = $request->withHeader('X-Requested-With', 'XMLHttpRequest');
     }
     return $next($request, $response);
 }
開發者ID:aswitahidayat,項目名稱:phpindonesia.or.id-membership2,代碼行數:25,代碼來源:Middleware.php

示例14: add

 public function add(Request $request, Response $response, array $args)
 {
     $input = $request->getParsedBody();
     $requiredFields = ['skill_parent_id', 'skill_self_assesment'];
     if (isset($input['skill_id'])) {
         $requiredFields[] = 'skill_id';
     }
     $validator = $this->validator->rule('required', $requiredFields);
     if ($validator->validate()) {
         $users = $this->data(Users::class);
         $skills = $this->data(MemberSkills::class);
         $skills->create(['user_id' => $this->session->get('user_id'), 'skill_id' => $input['skill_id'] ?: $input['skill_parent_id'], 'skill_parent_id' => $input['skill_parent_id'], 'skill_self_assesment' => $input['skill_self_assesment']]);
         $this->addFormAlert('success', 'Item skill baru berhasil ditambahkan. Selamat!.  Silahkan tambahkan lagi item skill anda.');
     } else {
         $this->addFormAlert('warning', 'Some of mandatory fields is empty!', $validator->errors());
         return $response->withRedirect($this->router->pathFor('membership-skills-add'));
     }
     return $response->withRedirect($this->router->pathFor('membership-account'));
 }
開發者ID:tirta-keniten,項目名稱:phpindonesia.or.id-membership2,代碼行數:19,代碼來源:SkillsController.php

示例15: login

 public function login(Request $request, Response $response, array $arguments)
 {
     $body = $request->getParsedBody();
     $user = User::where('email', $body['email'])->first();
     if (!$user) {
         return $response->withJson(['message' => 'no_such_email'], 400);
     }
     if (!password_verify($body['password'], $user->password)) {
         return $response->withJson(['message' => 'incorrect_password'], 400);
     }
     $factory = new Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $tokenValue = $generator->generateString(128, Generator::CHAR_ALNUM);
     $token = new UserToken();
     $token->value = $tokenValue;
     $user->user_tokens()->save($token);
     $output = ['user' => $user, 'token' => $token->value];
     return $response->withJson($output, 200);
 }
開發者ID:joppuyo,項目名稱:Dullahan,代碼行數:19,代碼來源:UserController.php


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