当前位置: 首页>>代码示例>>PHP>>正文


PHP ServerRequestInterface::withParsedBody方法代码示例

本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::withParsedBody方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::withParsedBody方法的具体用法?PHP ServerRequestInterface::withParsedBody怎么用?PHP ServerRequestInterface::withParsedBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Psr\Http\Message\ServerRequestInterface的用法示例。


在下文中一共展示了ServerRequestInterface::withParsedBody方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: parse

 /**
  * @inheritDoc
  */
 public function parse(ServerRequestInterface $request) : ServerRequestInterface
 {
     if (false === strpos($request->getHeaderLine('Content-Type'), 'application/json')) {
         return $request;
     }
     $body = $request->getBody()->getContents();
     $parsedBody = json_decode($body, true);
     // TODO: Implement broken json handling
     return $request->withParsedBody($parsedBody);
 }
开发者ID:aurimasniekis,项目名称:http,代码行数:13,代码来源:JsonBodyParser.php

示例5: handlePayload

 /**
  * Handle the payload.
  *
  * @param ServerRequestInterface $request
  *
  * @return ServerRequestInterface
  */
 protected function handlePayload(ServerRequestInterface $request)
 {
     if ($request->getParsedBody() || !in_array($request->getMethod(), ['POST', 'PUT', 'DELETE'], true)) {
         return $request;
     }
     $contentType = trim($request->getHeaderLine('Content-Type'));
     //json
     if (stripos($contentType, 'application/json') === 0) {
         return $request->withParsedBody($this->parseJson($request->getBody()))->withBody(Middleware::createStream());
     }
     //urlencoded
     if (stripos($contentType, 'application/x-www-form-urlencoded') === 0) {
         return $request->withParsedBody($this->parseUrlEncoded($request->getBody()))->withBody(Middleware::createStream());
     }
     //csv
     if (stripos($contentType, 'text/csv') === 0) {
         return $request->withParsedBody($this->parseCsv($request->getBody()))->withBody(Middleware::createStream());
     }
     return $request;
 }
开发者ID:jordiwes,项目名称:psr7-middlewares,代码行数:27,代码来源:Payload.php

示例6: parse

 /**
  * {@inheritDoc}
  */
 public function parse(ServerRequestInterface $request)
 {
     $parsedBody = $request->getParsedBody();
     if (!empty($parsedBody)) {
         return $request;
     }
     $rawBody = (string) $request->getBody();
     if (empty($rawBody)) {
         return $request;
     }
     parse_str($rawBody, $parsedBody);
     return $request->withParsedBody($parsedBody);
 }
开发者ID:zendframework,项目名称:zend-expressive-helpers,代码行数:16,代码来源:FormUrlEncodedStrategy.php

示例7: csv

 /**
  * Parses csv strings.
  * 
  * @param ServerRequestInterface $request
  * 
  * @return ServerRequestInterface
  */
 public function csv(ServerRequestInterface $request)
 {
     $body = $request->getBody();
     if ($body->isSeekable()) {
         $body->rewind();
     }
     $stream = $body->detach();
     $data = [];
     while (($row = fgetcsv($stream)) !== false) {
         $data[] = $row;
     }
     fclose($stream);
     return $request->withParsedBody($data);
 }
开发者ID:basz,项目名称:psr7-middlewares,代码行数:21,代码来源:BodyParser.php

示例8: modify

 public function modify(ServerRequestInterface $request) : ServerRequestInterface
 {
     $headerLine = $request->getHeaderLine('Content-Type');
     if (false === strpos($headerLine, 'multipart/')) {
         return $request;
     }
     $boundary = null;
     if (preg_match("/boundary=\"?(.*)\"?\$/", $headerLine, $matches)) {
         $boundary = $matches[1];
     }
     $variables = [];
     $files = [];
     $body = $request->getBody()->detach();
     $partInfo = null;
     while (false !== ($lineN = fgets($body))) {
         if (0 === strpos($lineN, '--')) {
             if (null === $boundary) {
                 $boundary = rtrim($lineN);
             }
             continue;
         }
         $line = rtrim($lineN);
         if ('' === $line) {
             if (isset($partInfo['Content-Disposition']) && true !== empty($partInfo['Content-Disposition']['filename'])) {
                 $this->parseFile($body, $boundary, $partInfo, $files);
             } elseif ($partInfo !== null) {
                 $this->parseVariable($body, $boundary, $partInfo['Content-Disposition']['name'], $variables);
             }
             $partInfo = null;
             continue;
         }
         list($key, $value) = explode(':', $line, 2);
         $partInfo[$key] = $this->parseHeader($value, $key);
     }
     return $request->withParsedBody($variables)->withUploadedFiles($files);
 }
开发者ID:ThrusterIO,项目名称:http-modifiers,代码行数:36,代码来源:ParseMultiPartBodyModifier.php

示例9: withParsedBody

 /**
  * {@inheritdoc}
  */
 public function withParsedBody($data)
 {
     return new static($this->wrapped->withParsedBody($data));
 }
开发者ID:Mosaic,项目名称:Mosaic,代码行数:7,代码来源:Request.php

示例10: withParsedBody

 /**
  * {@inheritDoc}
  */
 public function withParsedBody($data)
 {
     return new self($this->app, $this->psrRequest->withParsedBody($data));
 }
开发者ID:tonis-io,项目名称:tonis,代码行数:7,代码来源:Request.php

示例11: withParsedBody

 /**
  * Proxy to ServerRequestInterface::withParsedBody()
  *
  * {@inheritdoc}
  */
 public function withParsedBody($params)
 {
     $new = $this->psrRequest->withParsedBody($params);
     return new self($new, $this->originalRequest);
 }
开发者ID:michaelmoussa,项目名称:zend-stratigility,代码行数:10,代码来源:Request.php

示例12: withParsedBody

 /**
  * @inheritDoc
  */
 public function withParsedBody($data)
 {
     $self = clone $this;
     $self->serverRequest = $this->serverRequest->withParsedBody($data);
     return $self;
 }
开发者ID:superbull,项目名称:super,代码行数:9,代码来源:Request.php

示例13: parseFromUrlEncoded

 /**
  * @param Request $request
  * @return Request
  */
 protected function parseFromUrlEncoded(Request $request)
 {
     $rawBody = (string) $request->getBody();
     if (empty($rawBody)) {
         return $request;
     }
     $parsedBody = [];
     parse_str($rawBody, $parsedBody);
     return $request->withParsedBody($parsedBody);
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:14,代码来源:BodyParserMiddleware.php


注:本文中的Psr\Http\Message\ServerRequestInterface::withParsedBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。