當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Psr7\Response類代碼示例

本文整理匯總了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;
 }
開發者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


注:本文中的GuzzleHttp\Psr7\Response類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。