本文整理汇总了PHP中Response::getBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getBody方法的具体用法?PHP Response::getBody怎么用?PHP Response::getBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::getBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleError
/**
* @throws HttpException
*/
protected function handleError()
{
$body = (string) $this->response->getBody();
$code = (int) $this->response->getStatusCode();
$content = json_decode($body);
throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
}
示例2: testConstruct
public function testConstruct()
{
$response = new Response(\Psc\Net\Service::OK, array('blubb' => 'blubb'));
$this->assertEquals(array('blubb' => 'blubb'), $response->getBody());
$this->assertEquals(\Psc\Net\Service::OK, $response->getStatus());
$this->assertInstanceOf('Psc\\Net\\ServiceResponse', $response);
}
示例3: handleError
/**
* @throws HttpException
*/
protected function handleError()
{
$body = (string) $this->response->getBody();
$code = (int) $this->response->getStatusCode();
$content = json_decode($body);
$error = $content->errors[0];
throw new HttpException(isset($error) ? $error->description : 'Request not processed.', $code);
}
示例4: testResponseValues
public function testResponseValues()
{
$resource = $this->prophesize(Resource::CLASS);
$resource->asJson()->willReturn('foobar');
$response = new Response($resource->reveal());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('application/hal+json', $response->getHeaderLine('Content-Type'));
$this->assertSame('foobar', (string) $response->getBody());
}
示例5: trim
/**
* @param Response $response
*/
function __construct(Response $response)
{
$this->response = $response;
if (($h = $response->getHeader("Content-Type", Header::class)) && $h->match("application/json", Header::MATCH_WORD) && ($failure = json_decode($response->getBody()))) {
$message = $failure->message;
if (isset($failure->errors)) {
$this->errors = (array) $failure->errors;
}
} else {
$message = trim($response->getBody()->toString());
}
if (!strlen($message)) {
$message = $response->getTransferInfo("error");
}
if (!strlen($message)) {
$message = $response->getResponseStatus();
}
parent::__construct($message, $response->getResponseCode(), null);
}
示例6: construct
/**
* Verify basic functionality of the response object.
*
* @test
* @covers ::__construct
* @covers ::getHttpCode
* @covers ::getHeaders
* @covers ::getBody
*
* @return void
*/
public function construct()
{
$httpCode = 200;
$headers = ['Content-Type' => 'text/json'];
$body = ['doesnt' => 'matter'];
$response = new Response($httpCode, $headers, $body);
$this->assertSame($httpCode, $response->getHttpCode());
$this->assertSame($headers, $response->getHeaders());
$this->assertSame($body, $response->getBody());
}
示例7: sendBody
/**
* Sends the body of the response to the client.
*
* @return void
*/
protected function sendBody()
{
$body = $this->response->getBody();
// Response::setBody() makes an is_callable check when setting the value.
// is_callable is a fairly heavy function due to the checks it has to
// perform compared to is_string, so this is a safe and fast way, though
// not necessarily intuitive way to structure the handling.
if (is_string($body)) {
echo $body;
} else {
call_user_func($body);
}
}
示例8: __construct
public function __construct(Response $parent)
{
$status = $parent->getStatus();
$convertToJson = false;
$ok = self::statusIsOK($status);
if ($ok) {
$contentType = $parent->getHeader('Content-Type');
if (!empty($contentType)) {
$convertToJson = stristr($contentType, '/json') !== false;
}
}
$bodyString = $parent->getBody();
parent::__construct($convertToJson ? json_decode($bodyString) : $bodyString, $parent->getHeaders(), $status);
$this->ok = $ok;
}
示例9: respond
public function respond(Response $response)
{
$ajaxResponse = array();
$ajaxResponse['components'] = array();
$ajaxResponse['header'] = array();
$ajaxResponse['script'] = $this->script;
$headerResponse = new HeaderResponse($response);
foreach ($this->components as $component) {
$response->clean();
$component->beforePageRender();
$component->render();
$value = $response->getBody();
$response->clean();
array_push($ajaxResponse['components'], array('id' => $component->getMarkupId(), 'value' => $value));
$this->renderComponentHeader($component, $response, $headerResponse);
$value = $response->getBody();
array_push($ajaxResponse['header'], $value);
$response->clean();
}
FeedbackModel::get()->cleanup();
header('Content-Type: application/json');
print json_encode($ajaxResponse);
}
示例10: import
/**
* Import handler for the endpoint's underlying data
*
* \seekat\Call will call this when the request will have finished.
*
* @param Response $response
* @return API self
* @throws UnexpectedValueException
* @throws RequestException
* @throws \Exception
*/
function import(Response $response) : API
{
$this->__log->info(__FUNCTION__ . ": " . $response->getInfo(), ["url" => (string) $this->__url]);
if ($response->getResponseCode() >= 400) {
$e = new RequestException($response);
$this->__log->critical(__FUNCTION__ . ": " . $e->getMessage(), ["url" => (string) $this->__url]);
throw $e;
}
if (!($type = $response->getHeader("Content-Type", Header::class))) {
$e = new RequestException($response);
$this->__log->error(__FUNCTION__ . ": Empty Content-Type -> " . $e->getMessage(), ["url" => (string) $this->__url]);
throw $e;
}
try {
$this->__type = new ContentType($type);
$this->__data = $this->__type->parseBody($response->getBody());
if ($link = $response->getHeader("Link", Header::class)) {
$this->__links = new Links($link);
}
} catch (\Exception $e) {
$this->__log->error(__FUNCTION__ . ": " . $e->getMessage(), ["url" => (string) $this->__url]);
throw $e;
}
return $this;
}
示例11: format
/**
* Convert guzzle response to data
*
* @param Response $response GuzzleHttp\Response
*
* @return string or array data
*/
public function format($response)
{
$data = (string) $response->getBody();
if ($this->option('json') === true) {
return $data;
}
return json_decode($data);
}
示例12: render
protected function render($data = null, $nested = true)
{
extract($data);
ob_start();
// Include view files
if ($nested) {
include $this->getTemplatePathname('header.php');
}
foreach ($this->getTemplates() as $tpl) {
include $tpl;
}
if ($nested) {
include $this->getTemplatePathname('footer.php');
}
$output = ob_get_clean();
Response::getBody()->write($output);
return Container::get('response');
}
示例13: getBody
/**
* Get the response body as string
*
* This method returns the body of the HTTP response (the content), as it
* should be in it's readable version - that is, after decoding it (if it
* was decoded), deflating it (if it was gzip compressed), etc.
*
* If you want to get the raw body (as transfered on wire) use
* $this->getRawBody() instead.
*
* @return string
*/
public function getBody()
{
if ($this->stream != null) {
$this->readStream();
}
return parent::getBody();
}
示例14: getResponseBody
/**
* Get the response body after the request has been sent.
* If redirects were allowed and several responses were received, the data references the last received response.
* @return string
*/
public function getResponseBody()
{
return $this->response->getBody();
}
示例15: parseSignedJSON
/**
* Parse a signed JSON response
*
* @param Response $response
* @param SignaturePublicKey $publicKey
* @return mixed
* @throws SignatureFailed
* @throws TransferException
*/
public function parseSignedJSON(Response $response, SignaturePublicKey $publicKey)
{
$code = $response->getStatusCode();
if ($code >= 200 && $code < 300) {
$body = (string) $response->getBody();
$firstNewLine = \strpos($body, "\n");
// There should be a newline immediately after the base64urlsafe-encoded signature
if ($firstNewLine !== self::ENCODED_SIGNATURE_LENGTH) {
throw new SignatureFailed(\sprintf("First newline found at position %s, expected %d.\n%s", \print_r($firstNewLine, true), \print_r(self::ENCODED_SIGNATURE_LENGTH, true), Base64::encode($body)));
}
$sig = Base64UrlSafe::decode(Binary::safeSubstr($body, 0, 88));
$msg = Binary::safeSubstr($body, 89);
if (!Asymmetric::verify($msg, $publicKey, $sig, true)) {
throw new SignatureFailed();
}
return \Airship\parseJSON($msg, true);
}
throw new TransferException();
}