本文整理汇总了PHP中GuzzleHttp\Psr7\Response类的典型用法代码示例。如果您正苦于以下问题:PHP Response类的具体用法?PHP Response怎么用?PHP Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:plescanicolai,项目名称:billingSdk,代码行数:12,代码来源:Auth.php
示例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;
}
}
开发者ID:narrowspark,项目名称:testing-helper,代码行数:39,代码来源:CallableMiddleware.php
示例3: getJsonResponse
public static function getJsonResponse(GuzzleHttp\Psr7\Response $res)
{
if ($res->getStatusCode() == 200) {
return json_decode($res->getBody()->getContents(), true);
}
return [];
}
开发者ID:jrm2k6,项目名称:laradit,代码行数:7,代码来源:APIRequestHelper.php
示例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);
}
开发者ID:webmakersteve,项目名称:instagram-php,代码行数:25,代码来源:Response.php
示例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);
}
}
开发者ID:BuycraftPlugin,项目名称:Plugin-API-PHP,代码行数:11,代码来源:PlayerCommandsResponse.php
示例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);
}
}
开发者ID:BuycraftPlugin,项目名称:Plugin-API-PHP,代码行数:11,代码来源:ListingResponse.php
示例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);
}
}
开发者ID:BuycraftPlugin,项目名称:Plugin-API-PHP,代码行数:11,代码来源:PaymentsResponse.php
示例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);
}
开发者ID:rupertjeff,项目名称:ascension-card-db,代码行数:10,代码来源:ApiContext.php
示例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;
}
开发者ID:callcolor,项目名称:PHRETS,代码行数:33,代码来源:System.php
示例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);
}
开发者ID:RobertWang,项目名称:Codeception,代码行数:41,代码来源:Guzzle6.php
示例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;
}
开发者ID:callcolor,项目名称:PHRETS,代码行数:26,代码来源:OneX.php
示例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;
}
}
开发者ID:keboola,项目名称:orchestrator-bundle,代码行数:44,代码来源:Client.php
示例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);
}
开发者ID:gsdevme,项目名称:jumpcloud,代码行数:11,代码来源:AuthorizationResponseFactory.php
示例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;
}
开发者ID:andig,项目名称:spotify-web-api-extensions,代码行数:27,代码来源:GuzzleClientFactory.php
示例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();
}
开发者ID:haridarshan,项目名称:instagram-php,代码行数:13,代码来源:InstagramResponse.php
示例16: shouldRetry
/**
* Indicates if there should be a retry or not.
*
* @param integer $retryCount The retry count.
* @param \GuzzleHttp\Psr7\Response $response The HTTP response object.
*
* @return boolean
*/
public function shouldRetry($retryCount, $response)
{
if ($retryCount >= $this->_maximumAttempts || array_search($response->getStatusCode(), $this->_retryableStatusCodes) || is_null($response)) {
return false;
} else {
return true;
}
}
开发者ID:Azure,项目名称:azure-storage-php,代码行数:16,代码来源:ExponentialRetryPolicy.php
示例17:
function it_should_throw_exception_if_response_is_not_correct_for_finishing_the_verification_process(Response $response, StreamInterface $stream)
{
$response->getStatusCode()->willReturn(500);
$response->getBody()->willReturn($stream);
$stream->getContents()->willReturn('Error');
$this->client->sendRequest(Argument::type(Request::class))->shouldBeCalledTimes(1)->willReturn($response);
$this->shouldThrow(PactException::class)->during('finishProviderVerificationProcess');
}
开发者ID:madkom,项目名称:pact-php-client,代码行数:8,代码来源:HttpMockServiceCollaboratorSpec.php
示例18: prepareResponse
/**
* Convert response to object
* @param Response $response
* @return \SimpleXMLElement
*/
public function prepareResponse(Response $response)
{
$responseBody = (string) $response->getBody();
if ($responseBody) {
return simplexml_load_string($responseBody);
}
return null;
}
开发者ID:desher,项目名称:expertsender-api,代码行数:13,代码来源:ExpertSenderApiConnection.php
示例19: __construct
/**
* DuePlayersResponse constructor.
* @param Response $response
*/
public function __construct(Response $response)
{
$object = json_decode($response->getBody());
$this->meta = ["execute_offline" => $object->meta->execute_offline, "next_check" => $object->meta->next_check, "more" => $object->meta->more];
foreach ($object->players as $player) {
$this->players[] = new Player($player);
}
}
开发者ID:BuycraftPlugin,项目名称:Plugin-API-PHP,代码行数:12,代码来源:DuePlayersResponse.php
示例20: Response
function it_should_encode_a_responses_collection()
{
$response = new Response(200);
$responses = array($response);
$format = ['code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()];
$formatted = json_encode(array($format), JSON_PRETTY_PRINT);
$this->encodeResponsesCollection($responses)->shouldEqual($formatted);
}
开发者ID:ikwattro,项目名称:guzzle-stereo,代码行数:8,代码来源:ResponseFormatterSpec.php
注:本文中的GuzzleHttp\Psr7\Response类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论