当前位置: 首页>>代码示例>>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;未经允许,请勿转载。