本文整理汇总了PHP中Buzz\Message\Response::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getContent方法的具体用法?PHP Response::getContent怎么用?PHP Response::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Buzz\Message\Response
的用法示例。
在下文中一共展示了Response::getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processResponse
private function processResponse(Response $response)
{
if (null !== $this->logger) {
$this->logger->info(sprintf('Status Code %s', $response->getStatusCode()));
$this->logger->debug(var_export($response->getContent(), true));
}
if (500 <= $response->getStatusCode()) {
throw new ApiServerException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders());
}
if (400 <= $response->getStatusCode()) {
try {
$error = $this->parser->parse($response->getContent());
$error = $error instanceof Model\Error ? $error : new Model\Error();
} catch (ApiParserException $e) {
throw new ApiClientException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders(), null, $e);
}
throw new ApiClientException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders(), $error);
}
if (204 === $response->getStatusCode()) {
return true;
}
$content = trim($response->getContent());
if (empty($content)) {
return true;
}
$object = $this->parser->parse($content);
$object->setApi($this);
return $object;
}
示例2: assertHttpResponseCodeEquals
protected function assertHttpResponseCodeEquals(HttpResponse $response, $expected)
{
$responseCode = $response->getStatusCode();
if ($responseCode != $expected) {
$errorMessageString = '';
if ($response->getHeader('Content-Type') == 'application/vnd.ez.api.ErrorMessage+xml') {
$body = \simplexml_load_string($response->getContent());
$errorMessageString = $body->errorDescription;
} elseif ($response->getHeader('Content-Type') == 'application/vnd.ez.api.ErrorMessage+json') {
$body = json_decode($response->getContent());
$errorMessageString = "Error message: {$body->ErrorMessage->errorDescription}";
}
self::assertEquals($expected, $responseCode, $errorMessageString);
}
}
示例3: assertHttpResponseCodeEquals
protected function assertHttpResponseCodeEquals(HttpResponse $response, $expected)
{
$responseCode = $response->getStatusCode();
if ($responseCode != $expected) {
$errorMessageString = '';
if (strpos($response->getHeader('Content-Type'), 'application/vnd.ez.api.ErrorMessage+xml') !== false) {
$body = \simplexml_load_string($response->getContent());
$errorMessageString = $this->getHttpResponseCodeErrorMessage($body);
} elseif (strpos($response->getHeader('Content-Type'), 'application/vnd.ez.api.ErrorMessage+json') !== false) {
$body = json_decode($response->getContent());
$errorMessageString = $this->getHttpResponseCodeErrorMessage($body->ErrorMessage);
}
self::assertEquals($expected, $responseCode, $errorMessageString);
}
}
示例4: getResponse
/**
* Parse a response.
*
* @return \Tev\Bs\Contracts\ResponseInterface
*
* @throws \Exception
* @throws \Tev\Bs\Exception\ErrorResponseException
*/
public function getResponse()
{
$content = json_decode($this->response->getContent());
if ($content === null) {
throw new Exception('Failed to get response from server');
}
if (isset($content->error) && $content->error) {
$excp = new ErrorResponseException($content->message, $this->response->getStatusCode());
$excp->setResponse(new Response($content, $this->endpoint));
throw $excp;
}
if (isset($content->per_page)) {
return new PaginatedResponse($content, $this->endpoint);
}
return new Response($content, $this->endpoint);
}
示例5: parse
/**
* @param Response $curlResponse
*
* @throws HttpStatusParserException
*/
public function parse(Response $curlResponse)
{
$statusCode = $curlResponse->getStatusCode();
if ($this->shouldThrowException($statusCode)) {
throw new HttpStatusParserException($curlResponse->getContent(), $statusCode);
}
}
示例6: processResponse
/**
* This public method is also for other context(s) to process REST API call and inject response into this context.
*
* @param \Buzz\Message\Response $response
* @param boolean $asJson Process the response as JSON or not.
* @return void
*/
public function processResponse(\Buzz\Message\Response $response = null, $asJson = true)
{
if (!empty($response)) {
$this->response = $response;
}
return $this->processResponseBody($this->response->getContent(), $asJson);
}
示例7: it_can_search_with__query
public function it_can_search_with__query(Browser $client, Response $response)
{
$response->getContent()->shouldBeCalled();
$client->get(sprintf('%s/search?%s', 'http://endpoint', http_build_query(['q' => 'pilkington avenue, birmingham', 'format' => 'json'])), ['User-Agent' => 'Nomatim PHP Library (https://github.com/nixilla/nominatim-consumer); email: not set'])->shouldBeCalled()->willReturn($response);
$query = new Query();
$query->setQuery('pilkington avenue, birmingham');
$this->search($query)->shouldReturnAnInstanceOf('Nominatim\\Result\\Collection');
}
示例8: _parse
public function _parse(Response $response, $mime = null)
{
$data = $this->decode($response->getContent(), $mime);
if (isset($data->error)) {
throw new RugException($data->error, $this->_error($data));
}
return $data;
}
示例9: getContent
/**
* {@inheritDoc}
*/
public function getContent()
{
$response = parent::getContent();
$content = json_decode($response, true);
if (JSON_ERROR_NONE !== json_last_error()) {
return $response;
}
return $content;
}
示例10: processResponse
/**
* @param Response $response
*
* @return string
*/
private function processResponse(Response $response)
{
$matches = [];
preg_match('/<input.*value="(.*)"/U', $response->getContent(), $matches);
if (!isset($matches[1])) {
throw new \RuntimeException('Screenshot upload failed');
}
return $matches[1];
}
示例11: handleException
/**
* Lets us know if something went wrong
*
* @param Response $response
* @throws \Twitter\Exception\TwitterApiException
* @throws \Exception
*/
protected function handleException(Response $response)
{
$json_string = $response->getContent();
$output = json_decode($json_string, true);
if (count($output['errors'])) {
throw new TwitterApiException($output['errors'][0]['message'], $output['errors'][0]['code']);
} else {
throw new \Exception(sprintf('Unknown error: %s', $json_string));
}
}
示例12: getContent
/**
* @return mixed
*/
public function getContent()
{
$response = parent::getContent();
if ($this->getHeader('Content-Type') === 'application/json') {
$content = json_decode($response, true);
if (JSON_ERROR_NONE !== json_last_error()) {
return $response;
}
return $content;
}
return $response;
}
示例13: processResponse
private function processResponse(Response $response)
{
if (null !== $this->logger) {
$this->logger->info(sprintf('Status Code %s', $response->getStatusCode()));
$this->logger->debug(var_export($response->getContent(), true));
}
if (500 <= $response->getStatusCode()) {
throw new ApiServerException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders());
}
if (400 <= $response->getStatusCode()) {
throw new ApiClientException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders());
}
if (204 === $response->getStatusCode()) {
return true;
}
if (null !== $response->getContent()) {
$object = $this->parser->parse($response->getContent());
$object->setApi($this);
return $object;
}
}
示例14: validateResponse
/**
* {@inheritdoc}
*/
protected function validateResponse(Response $response)
{
$content = $response->getContent();
$success = false;
$xml = new \DOMDocument();
if ($xml->loadXML($content)) {
foreach ($xml->firstChild->childNodes as $child) {
if ($child->nodeName === 'cas:authenticationSuccess') {
$root = $child;
$success = true;
break;
} elseif ($child->nodeName === 'cas:authenticationFailure') {
$root = $child;
$success = false;
break;
}
}
if ($success) {
foreach ($root->childNodes as $child) {
switch ($child->nodeName) {
case 'cas:user':
$this->username = $child->textContent;
break;
case 'cas:attributes':
foreach ($child->childNodes as $attr) {
if ($attr->nodeName != '#text') {
$this->attributes[$attr->nodeName] = $attr->textContent;
}
}
break;
case 'cas:attribute':
$name = $child->attributes->getNamedItem('name')->value;
$value = $child->attributes->getNamedItem('value')->value;
if ($name && $value) {
$this->attributes[$name] = $value;
}
break;
case '#text':
break;
default:
$this->attributes[substr($child->nodeName, 4)] = $child->textContent;
}
}
} else {
$this->error = (string) $root->textContent;
}
} else {
$success = false;
$this->error = 'Invalid response';
}
return $success;
}
示例15: validateResponse
/**
* {@inheritdoc}
*/
protected function validateResponse(Response $response)
{
$content = $response->getContent();
$data = explode("\n", str_replace("\n\n", "\n", str_replace("\r", "\n", $content)));
$success = strtolower($data[0]) === 'yes';
$message = count($data) > 1 && $data[1] ? $data[1] : null;
if ($success) {
$this->username = $message;
} else {
$this->error = $message;
}
return $success;
}