本文整理汇总了PHP中GuzzleHttp\Psr7\Response类的典型用法代码示例。如果您正苦于以下问题:PHP Response类的具体用法?PHP Response怎么用?PHP Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setLastLogs
/**
* Set last logs
*
* @param Response|ResponseInterface $response
*/
public function setLastLogs($response)
{
$this->statusCode = $response->getStatusCode();
$content = json_decode($response->getBody()->getContents());
$this->message = isset($content->message) ? $content->message : null;
$this->errors = isset($content->errors) ? $content->errors : null;
}
示例2: execute
/**
* Execute the callable.
*
* @param callable $callable
* @param array $arguments
*
* @return ResponseInterface
*/
private function execute($callable, array $arguments = [])
{
ob_start();
$level = ob_get_level();
try {
$return = call_user_func_array($callable, $arguments);
if ($return instanceof ResponseInterface) {
$response = $return;
$return = '';
} else {
if (class_exists(ResponseFactory::class)) {
$response = (new ResponseFactory())->createResponse();
} else {
$response = new Response();
}
}
while (ob_get_level() >= $level) {
$return = ob_get_clean() . $return;
}
$body = $response->getBody();
if ($return !== '' && $body->isWritable()) {
$body->write($return);
}
return $response;
} catch (Throwable $exception) {
while (ob_get_level() >= $level) {
ob_end_clean();
}
throw $exception;
}
}
示例3: getJsonResponse
public static function getJsonResponse(GuzzleHttp\Psr7\Response $res)
{
if ($res->getStatusCode() == 200) {
return json_decode($res->getBody()->getContents(), true);
}
return [];
}
示例4: __construct
public function __construct(\GuzzleHttp\Psr7\Response $response)
{
$json = false;
$data = $response->getBody();
$this->rawData = $data;
$this->response = $response;
if ($response->hasHeader('Content-Type')) {
// Let's see if it is JSON
$contentType = $response->getHeader('Content-Type');
if (strstr($contentType[0], 'json')) {
$json = true;
$data = json_decode($data);
}
}
if (!$json) {
// We can do another test here
$decoded = json_decode($response->getBody());
if ($decoded) {
$json = true;
$data = $decoded;
}
}
$this->setData($data);
$this->setIsJson($json);
}
示例5: __construct
/**
* PlayerCommandsResponse constructor.
* @param Response $response
*/
public function __construct(Response $response)
{
$object = json_decode($response->getBody());
foreach ($object->commands as $command) {
$this->commands[] = new Command($command);
}
}
示例6: __construct
/**
* ListingResponse constructor.
* @param Response $response
*/
public function __construct(Response $response)
{
$objects = json_decode($response->getBody())->categories;
foreach ($objects as $object) {
$this->categories[] = new Category($object);
}
}
示例7: __construct
/**
* PaymentsResponse constructor.
* @param Response $response
*/
public function __construct(Response $response)
{
$objects = json_decode($response->getBody());
foreach ($objects as $object) {
$this->payments[] = new Payment($object);
}
}
示例8: theResponseIsJson
/**
* @Then the response is JSON
*/
public function theResponseIsJson()
{
$this->responseData = json_decode($this->response->getBody());
$expectedType = 'object';
$actualObject = $this->responseData;
PHPUnit::assertInternalType($expectedType, $actualObject);
}
示例9: parse
public function parse(Session $rets, Response $response)
{
$xml = simplexml_load_string($response->getBody());
$base = $xml->METADATA->{'METADATA-SYSTEM'};
$metadata = new \PHRETS\Models\Metadata\System();
$metadata->setSession($rets);
$configuration = $rets->getConfiguration();
if ($configuration->getRetsVersion()->is1_5()) {
if (isset($base->System->SystemID)) {
$metadata->setSystemId((string) $base->System->SystemID);
}
if (isset($base->System->SystemDescription)) {
$metadata->setSystemDescription((string) $base->System->SystemDescription);
}
} else {
if (isset($base->SYSTEM->attributes()->SystemID)) {
$metadata->setSystemId((string) $base->SYSTEM->attributes()->SystemID);
}
if (isset($base->SYSTEM->attributes()->SystemDescription)) {
$metadata->setSystemDescription((string) $base->SYSTEM->attributes()->SystemDescription);
}
if (isset($base->SYSTEM->attributes()->TimeZoneOffset)) {
$metadata->setTimezoneOffset((string) $base->SYSTEM->attributes()->TimeZoneOffset);
}
}
if (isset($base->SYSTEM->Comments)) {
$metadata->setComments((string) $base->SYSTEM->Comments);
}
if (isset($base->attributes()->Version)) {
$metadata->setVersion((string) $xml->METADATA->{'METADATA-SYSTEM'}->attributes()->Version);
}
return $metadata;
}
示例10: createResponse
/**
* Taken from Mink\BrowserKitDriver
*
* @param Response $response
*
* @return \Symfony\Component\BrowserKit\Response
*/
protected function createResponse(Psr7Response $response)
{
$body = (string) $response->getBody();
$headers = $response->getHeaders();
$contentType = null;
if (isset($headers['Content-Type'])) {
$contentType = reset($headers['Content-Type']);
}
if (!$contentType) {
$contentType = 'text/html';
}
if (strpos($contentType, 'charset=') === false) {
if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
$contentType .= ';charset=' . $matches[1];
}
$headers['Content-Type'] = [$contentType];
}
$status = $response->getStatusCode();
$matches = [];
$matchesMeta = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $body, $matches);
if (!$matchesMeta && isset($headers['Refresh'])) {
// match by header
preg_match('~(\\d*);?url=(.*)~', (string) reset($headers['Refresh']), $matches);
}
if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
$uri = new Psr7Uri($this->getAbsoluteUri($matches[2]));
$currentUri = new Psr7Uri($this->getHistory()->current()->getUri());
if ($uri->withFragment('') != $currentUri->withFragment('')) {
$status = 302;
$headers['Location'] = (string) $uri;
}
}
return new BrowserKitResponse($body, $status, $headers);
}
示例11: parse
public function parse(Session $rets, Response $response, $parameters)
{
$xml = simplexml_load_string($response->getBody());
$rs = new Results();
$rs->setSession($rets)->setResource($parameters['SearchType'])->setClass($parameters['Class']);
if ($this->getRestrictedIndicator($rets, $xml, $parameters)) {
$rs->setRestrictedIndicator($this->getRestrictedIndicator($rets, $xml, $parameters));
}
$rs->setHeaders($this->getColumnNames($rets, $xml, $parameters));
$rets->debug(count($rs->getHeaders()) . ' column headers/fields given');
$this->parseRecords($rets, $xml, $parameters, $rs);
if ($this->getTotalCount($rets, $xml, $parameters) !== null) {
$rs->setTotalResultsCount($this->getTotalCount($rets, $xml, $parameters));
$rets->debug($rs->getTotalResultsCount() . ' total results found');
}
$rets->debug($rs->getReturnedResultsCount() . ' results given');
if ($this->foundMaxRows($rets, $xml, $parameters)) {
// MAXROWS tag found. the RETS server withheld records.
// if the server supports Offset, more requests can be sent to page through results
// until this tag isn't found anymore.
$rs->setMaxRowsReached();
$rets->debug('Maximum rows returned in response');
}
unset($xml);
return $rs;
}
示例12: sendOrchestratorPollRequest
/**
* Send poll request from task response
*
* If response is not from async task, return null
*
* @param Elasticsearch\Job $job
* @param \GuzzleHttp\Psr7\Response $response
* @param Encryptor $encryptor
* @param int $retriesCount
* @return \GuzzleHttp\Psr7\Response|null
*/
public function sendOrchestratorPollRequest(Elasticsearch\Job $job, \GuzzleHttp\Psr7\Response $response, Encryptor $encryptor, $retriesCount)
{
if ($response->getStatusCode() != 202) {
return null;
}
try {
$data = ResponseDecoder::decode($response);
if (!is_array($data)) {
throw new \Exception('Not json reponse');
}
if (empty($data['url'])) {
return null;
}
} catch (\Exception $e) {
//@TODO log error with debug priority
return null;
}
$timeout = 2;
try {
return $this->get($data['url'], array('config' => array('curl' => array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0)), 'headers' => array('X-StorageApi-Token' => $encryptor->decrypt($job->getToken()), 'X-KBC-RunId' => $job->getRunId(), 'X-User-Agent', KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME . " - JobExecutor", 'X-Orchestrator-Poll', (int) $retriesCount), 'timeout' => 60 * $timeout));
} catch (RequestException $e) {
$handlerContext = $e->getHandlerContext();
if (is_array($handlerContext)) {
if (array_key_exists('errno', $handlerContext)) {
if ($handlerContext['errno'] == CURLE_OPERATION_TIMEOUTED) {
$this->logger->debug('curl.debug', array('handlerContext' => $e->getHandlerContext()));
throw new Exception\CurlException(sprintf('Task polling timeout after %d minutes', $timeout), $e->getRequest(), $e->getResponse(), $e);
}
}
}
throw $e;
}
}
示例13: create
/**
* @param Response $response
* @return AuthorizationResponse
*/
public function create(Response $response)
{
if ($response->getStatusCode() === 200) {
return new AuthorizationResponse($response, AuthorizationResponse::AUTHORISED);
}
return new AuthorizationResponse($response, AuthorizationResponse::UNAUTHORISED);
}
示例14: retryDecider
static function retryDecider($retries, Request $request, Response $response = null, RequestException $exception = null)
{
// Limit the number of retries to 5
if ($retries >= 5) {
return false;
}
// Retry connection exceptions
if ($exception instanceof ConnectException) {
return true;
}
if ($response) {
// Retry on server errors
if ($response->getStatusCode() >= 500) {
return true;
}
// Retry on rate limits
if ($response->getStatusCode() == 429) {
$retryDelay = $response->getHeaderLine('Retry-After');
if (strlen($retryDelay)) {
printf(" retry delay: %d secs\n", (int) $retryDelay);
sleep((int) $retryDelay);
return true;
}
}
}
return false;
}
示例15: setParams
/**
* Set Values to the class members
*
* @param Response $response
*/
private function setParams(Response $response)
{
$this->protocol = $response->getProtocolVersion();
$this->statusCode = (int) $response->getStatusCode();
$this->headers = $response->getHeaders();
$this->body = json_decode($response->getBody()->getContents());
$this->extractBodyParts();
}