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


PHP ServerRequestInterface::getBody方法代碼示例

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


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

示例1: execute

 public function execute(Request $req, Response $res, callable $next = null)
 {
     try {
         $name = urldecode($req->getAttribute('name'));
         $collection = $this->boot()->get('store')->getCollection($name);
         $contenttype = $req->getHeader('Content-Type');
         if (false !== strpos($contenttype[0], 'json')) {
             $body = json_decode($req->getBody(), true);
         } else {
             $body = $req->getParsedBody();
         }
         if (!$body) {
             throw new \RuntimeException('no request body');
         }
         $data = $collection->save($collection->item()->setData($body))->getData();
         if (isset($body['@labels'])) {
             foreach ($body['@labels'] as $label) {
                 $this->boot()->get('store')->setLabel($data['id'], $label['_label_name'], $label['_label_group'], true);
             }
         }
         if (isset($body['@properties'])) {
             foreach ($body['@properties'] as $property) {
                 $this->boot()->get('store')->setProperty($data['id'], $property['_property_name'], $property['_property_value'], $property['_property_idx'], $property['_property_type'], $property['_property_sys_type_id'], true);
             }
         }
         $data['@labels'] = $this->boot()->get('store')->getLabels($data['id']);
         $data['@properties'] = $this->boot()->get('store')->getProperties($data['id']);
         return $next($req, new JsonResponse(['status' => 'ok', 'data' => $data]));
     } catch (\Exception $ex) {
         return new JsonResponse(['status' => 'error', 'error' => $ex->getMessage()], 500);
     }
 }
開發者ID:rostmefpoter,項目名稱:bh,代碼行數:32,代碼來源:post.php

示例2: getParsedBody

 /**
  * @inheritDoc
  */
 public function getParsedBody()
 {
     if ($this->serverRequest->getBody()->getContents() && empty($this->serverRequest->getParsedBody())) {
         $this->serverRequest = $this->serverRequest->withParsedBody(json_decode($this->serverRequest->getBody(), true));
     }
     return $this->serverRequest->getParsedBody();
 }
開發者ID:garethwi,項目名稱:yin,代碼行數:10,代碼來源:Request.php

示例3: parseJsonBody

 protected function parseJsonBody(ServerRequestInterface $request)
 {
     $bodyJson = @json_decode($request->getBody()->__toString(), true);
     if (json_last_error() != JSON_ERROR_NONE) {
         throw new \Exception(json_last_error_msg());
     }
     return $bodyJson;
 }
開發者ID:mcustiel,項目名稱:phiremock,代碼行數:8,代碼來源:AbstractRequestAction.php

示例4: createRequest

 /**
  * {@inheritdoc}
  */
 public function createRequest(ServerRequestInterface $psrRequest)
 {
     $parsedBody = $psrRequest->getParsedBody();
     $parsedBody = is_array($parsedBody) ? $parsedBody : array();
     $request = new Request($psrRequest->getQueryParams(), $parsedBody, $psrRequest->getAttributes(), $psrRequest->getCookieParams(), $this->getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString());
     $request->headers->replace($psrRequest->getHeaders());
     return $request;
 }
開發者ID:papillon-cendre,項目名稱:d8,代碼行數:11,代碼來源:HttpFoundationFactory.php

示例5: send

 /**
  * @param  ServerRequestInterface $request
  */
 public function send(ServerRequestInterface $request)
 {
     $this->currentUri = $request->getUri();
     $this->setBase($this->currentUri);
     if (empty($this->currentUri->getHost())) {
         $this->currentUri = new Uri($this->getBase() . $this->currentUri);
     }
     $curl = curl_init();
     $options = [CURLOPT_URL => (string) $this->currentUri, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_USERAGENT => Loader::USER_AGENT, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $this->getConvertedHeaders($request->getHeaders())];
     if ($request->getBody()->getSize()) {
         $options[CURLOPT_POSTFIELDS] = (string) $request->getBody();
     }
     curl_setopt_array($curl, $options);
     $response = curl_exec($curl);
     $this->currentUri = new Uri(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
     return \GuzzleHttp\Psr7\parse_response($response);
 }
開發者ID:spiderling-php,項目名稱:curl-driver,代碼行數:20,代碼來源:Loader.php

示例6: __invoke

 /**
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     if (str_contains($request->getHeaderLine('content-type'), 'json')) {
         $input = json_decode($request->getBody(), true);
         $request = $request->withParsedBody($input ?: []);
     }
     return $out ? $out($request, $response) : $response;
 }
開發者ID:asifalimd,項目名稱:core,代碼行數:11,代碼來源:ParseJsonBody.php

示例7: getCredentials

 /**
  * @inheritDoc
  */
 public function getCredentials(ServerRequestInterface $request)
 {
     $json = json_decode($request->getBody()->getContents(), true);
     if (empty($json[$this->identifier]) || empty($json[$this->password])) {
         return null;
     }
     return new Credentials($json[$this->identifier], $json[$this->password]);
 }
開發者ID:mHz28,項目名稱:rest-scheduler-api,代碼行數:11,代碼來源:JsonExtractor.php

示例8: convertRequestFromPsr7

 /**
  * Converts a PSR-7 request into an OAuth2 request.
  *
  * @param ServerRequestInterface $psrRequest
  * @return Request
  */
 public static function convertRequestFromPsr7(ServerRequestInterface $psrRequest)
 {
     $headers = [];
     foreach ($psrRequest->getHeaders() as $header => $value) {
         $headers[$header] = implode(';', $value);
     }
     return new Request($psrRequest->getQueryParams(), is_array($psrRequest->getParsedBody()) ? $psrRequest->getParsedBody() : [], $psrRequest->getAttributes(), $psrRequest->getCookieParams(), self::getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString(), $headers);
 }
開發者ID:tonis-io,項目名稱:oauth2,代碼行數:14,代碼來源:Util.php

示例9: modify

 public function modify(ServerRequestInterface $request) : ServerRequestInterface
 {
     if (false === strpos($request->getHeaderLine('Content-Type'), 'application/json')) {
         return $request;
     }
     // TODO: Implement broken json handling
     return $request->withParsedBody(json_decode($request->getBody()->getContents(), $this->asAssociativeArray));
 }
開發者ID:ThrusterIO,項目名稱:http-modifiers,代碼行數:8,代碼來源:ParseJsonRequestBodyModifier.php

示例10: modify

 public function modify(ServerRequestInterface $request) : ServerRequestInterface
 {
     if (false === strpos($request->getHeaderLine('Content-Type'), 'application/x-www-form-urlencoded')) {
         return $request;
     }
     parse_str($request->getBody()->getContents(), $parsedBody);
     return $request->withParsedBody($parsedBody);
 }
開發者ID:ThrusterIO,項目名稱:http-modifiers,代碼行數:8,代碼來源:ParseURLEncodedBodyModifier.php

示例11: getBody

 /**
  * @return string
  */
 private function getBody()
 {
     if (isset($this->body)) {
         return $this->body;
     }
     $this->body = (string) $this->request->getBody();
     return $this->body;
 }
開發者ID:tgallice,項目名稱:fb-messenger-sdk,代碼行數:11,代碼來源:WebhookRequestHandler.php

示例12: parse

 /**
  * {@inheritDoc}
  */
 public function parse(ServerRequestInterface $request)
 {
     $rawBody = (string) $request->getBody();
     $parsedBody = json_decode($rawBody, true);
     if (json_last_error() !== JSON_ERROR_NONE) {
         throw new MalformedRequestBodyException('Error when parsing JSON request body: ' . json_last_error_msg());
     }
     return $request->withAttribute('rawBody', $rawBody)->withParsedBody($parsedBody);
 }
開發者ID:zendframework,項目名稱:zend-expressive-helpers,代碼行數:12,代碼來源:JsonStrategy.php

示例13: createRequest

 public static function createRequest(PsrServerRequestInterface $psrRequest)
 {
     $request = new Request(new Uri($psrRequest->getUri()), $psrRequest->getMethod(), $psrRequest->getHeaders(), $psrRequest->getBody());
     $attributes = $psrRequest->getAttributes();
     foreach ($attributes as $name => $value) {
         $request->setAttribute($name, $value);
     }
     return $request;
 }
開發者ID:seytar,項目名稱:psx,代碼行數:9,代碼來源:NativeFactory.php

示例14: __invoke

 /**
  * Parses request bodies based on content type
  *
  * @param  Request  $request
  * @param  Response $response
  * @param  callable $next
  * @return Response
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     $mime = strtolower($request->getHeaderLine('Content-Type'));
     if ($this->isApplicableMimeType($mime) && !$request->getParsedBody()) {
         $parsed = $this->getParsedBody((string) $request->getBody());
         $request = $request->withParsedBody($parsed);
     }
     return $next($request, $response);
 }
開發者ID:mikegreiling,項目名稱:spark,代碼行數:17,代碼來源:ContentHandler.php

示例15: enrichRequestWithParsedBody

 public function enrichRequestWithParsedBody(ServerRequestInterface $request)
 {
     if ($request->hasHeader(HeaderName::CONTENT_TYPE) && $request->getHeaderLine(HeaderName::CONTENT_TYPE) === 'application/json') {
         $parsedBody = $this->serializer->deserialize($request->getBody()->__toString(), 'array', 'json');
         return $request->withParsedBody($parsedBody);
     } else {
         return $request->withParsedBody([]);
     }
 }
開發者ID:jonasrudolph,項目名稱:php-component-web-project,代碼行數:9,代碼來源:RequestBodyParser.php


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