本文整理汇总了PHP中Psr\Http\Message\RequestInterface::withBody方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::withBody方法的具体用法?PHP RequestInterface::withBody怎么用?PHP RequestInterface::withBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::withBody方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signRequest
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
$params = Psr7\parse_query($request->getBody());
$params['Timestamp'] = gmdate('c');
$params['SignatureVersion'] = '2';
$params['SignatureMethod'] = 'HmacSHA256';
$params['AWSAccessKeyId'] = $credentials->getAccessKeyId();
if ($token = $credentials->getSecurityToken()) {
$params['SecurityToken'] = $token;
}
// build string to sign
$sign = $request->getMethod() . "\n" . $request->getHeaderLine('Host') . "\n" . '/' . "\n" . $this->getCanonicalizedParameterString($params);
$params['Signature'] = base64_encode(hash_hmac('sha256', $sign, $credentials->getSecretKey(), true));
return $request->withBody(Psr7\stream_for(http_build_query($params)));
}
示例2:
function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest, StreamableInterface $body)
{
$body->__toString()->willReturn('{}');
$body->rewind()->shouldBeCalled();
$body->isSeekable()->willReturn(true);
$body->isWritable()->willReturn(true);
$body->write(json_encode(['email' => 'john.doe@domain.com', 'password' => 'secret']))->shouldBeCalled();
$request->getBody()->willReturn($body);
$request->withBody(Argument::type('Psr\\Http\\Message\\StreamableInterface'))->willReturn($newRequest);
$request = $this->authenticateRequest($request);
$request->shouldBe($newRequest);
}
示例3: authenticateRequest
/**
* {@inheritdoc}
*/
public function authenticateRequest(RequestInterface $request)
{
$requestBody = $request->getBody();
$this->ensureBodyRewritable($requestBody);
$body = (string) $requestBody;
$body = json_decode($body, true);
$this->ensureJsonDecodedCorrectly();
$body['email'] = $this->email;
$body['password'] = $this->password;
$requestBody->rewind();
$requestBody->write(json_encode($body));
return $request->withBody($requestBody);
}
示例4: withBody
/**
* @param StreamInterface $body
* @return $this|Request
*/
public function withBody(StreamInterface $body)
{
$this->request = $this->request->withBody($body);
return $this;
}
示例5: withBody
public function withBody(StreamInterface $body)
{
$new = clone $this;
$new->request = $this->request->withBody($body);
return $new;
}
示例6: setBody
/**
* @param string $body The raw request body.
*
* @return void
* @author Mario Mueller
*/
public function setBody($body)
{
$this->guzzleRequest = $this->guzzleRequest->withBody(\GuzzleHttp\Psr7\stream_for($body));
}
示例7: getCopyOfRequestWithEmptyBody
private function getCopyOfRequestWithEmptyBody(RequestInterface $request) : RequestInterface
{
$emptyStream = new Stream(fopen('php://temp', 'r+'));
return $request->withBody($emptyStream);
}