本文整理汇总了PHP中Guzzle\Http\Message\Response类的典型用法代码示例。如果您正苦于以下问题:PHP Response类的具体用法?PHP Response怎么用?PHP Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getResponse
/**
* Get the response of the query.
* Will be the json decoded data if success, else the error message.
*
* @return array|string
*/
public function getResponse()
{
if (false === $this->response->isSuccessful()) {
return $this->response->getMessage();
}
return $this->response->json();
}
开发者ID:pompdelux,项目名称:kraken-bundle,代码行数:13,代码来源:KrakenResponse.php
示例2: dispatch
public function dispatch($request, $connection)
{
$response = new Response(200);
$path = $request->getPath();
if ($this->match($path)) {
echo "Found match for path: {$path}" . PHP_EOL;
if (is_callable($this->routes[$path])) {
call_user_func_array($this->routes[$path], array($request, $response, $connection));
} else {
throw new \Exception('Invalid route definition.');
}
return;
}
if (is_null($this->fileHandler)) {
throw new \Exception('No file handler configured');
}
if (false === $this->fileHandler->canHandleRequest($request)) {
$response->setStatus(404);
$response->setBody('File not found');
$connection->send($response);
$connection->close();
return;
}
$this->fileHandler->handleRequest($request, $response, $connection);
}
开发者ID:steverhoades,项目名称:async-talk-examples,代码行数:25,代码来源:Router.php
示例3: getDelay
/**
* {@inheritdoc}
*/
protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
{
if ($response && $response->isClientError()) {
$parts = $this->exceptionParser->parse($request, $response);
return isset(self::$throttlingExceptions[$parts['code']]) ? true : null;
}
}
开发者ID:ebeauchamps,项目名称:brilliantretail,代码行数:10,代码来源:ThrottlingErrorChecker.php
示例4: testProperlyValidatesWhenUsingContentEncoding
public function testProperlyValidatesWhenUsingContentEncoding()
{
$plugin = new Md5ValidatorPlugin(true);
$request = RequestFactory::getInstance()->create('GET', 'http://www.test.com/');
$request->getEventDispatcher()->addSubscriber($plugin);
// Content-MD5 is the MD5 hash of the canonical content after all
// content-encoding has been applied. Because cURL will automatically
// decompress entity bodies, we need to re-compress it to calculate.
$body = EntityBody::factory('abc');
$body->compress();
$hash = $body->getContentMd5();
$body->uncompress();
$response = new Response(200, array('Content-MD5' => $hash, 'Content-Encoding' => 'gzip'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
$this->assertEquals('abc', $response->getBody(true));
// Try again with an unknown encoding
$response = new Response(200, array('Content-MD5' => $hash, 'Content-Encoding' => 'foobar'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
// Try again with compress
$body->compress('bzip2.compress');
$response = new Response(200, array('Content-MD5' => $body->getContentMd5(), 'Content-Encoding' => 'compress'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
// Try again with encoding and disabled content-encoding checks
$request->getEventDispatcher()->removeSubscriber($plugin);
$plugin = new Md5ValidatorPlugin(false);
$request->getEventDispatcher()->addSubscriber($plugin);
$request->dispatch('request.complete', array('response' => $response));
}
开发者ID:jsnshrmn,项目名称:Suma,代码行数:28,代码来源:Md5ValidatorPluginTest.php
示例5: receiveResponseHeader
/**
* Receive a response header from curl
*
* @param resource $curl Curl handle
* @param string $header Received header
*
* @return int
*/
public function receiveResponseHeader($curl, $header)
{
static $normalize = array("\r", "\n");
$length = strlen($header);
$header = str_replace($normalize, '', $header);
if (strpos($header, 'HTTP/') === 0) {
$startLine = explode(' ', $header, 3);
$code = $startLine[1];
$status = isset($startLine[2]) ? $startLine[2] : '';
// Only download the body of the response to the specified response
// body when a successful response is received.
if ($code >= 200 && $code < 300) {
$body = $this->request->getResponseBody();
} else {
$body = EntityBody::factory();
}
$response = new Response($code, null, $body);
$response->setStatus($code, $status);
$this->request->startResponse($response);
$this->request->dispatch('request.receive.status_line', array('request' => $this, 'line' => $header, 'status_code' => $code, 'reason_phrase' => $status));
} elseif ($pos = strpos($header, ':')) {
$this->request->getResponse()->addHeader(trim(substr($header, 0, $pos)), trim(substr($header, $pos + 1)));
}
return $length;
}
开发者ID:adrianoaguiar,项目名称:magento-elasticsearch-module,代码行数:33,代码来源:RequestMediator.php
示例6: testRetrieving
public function testRetrieving()
{
$response = new Response(200);
$response->setBody(json_encode(array('status' => 1, 'complete' => 1, 'list' => array(123 => array('item_id' => 123, 'resolved_id' => 123, 'given_url' => 'http://acairns.co.uk', 'given_title' => 'Andrew Cairns', 'favorite' => 0, 'status' => 0, 'time_added' => time(), 'time_updated' => time(), 'time_read' => 0, 'time_favorited' => 0, 'sort_id' => 0, 'resolved_title' => 'Andrew Cairns', 'resolved_url' => 'http://acairns.co.uk', 'excerpt' => 'Some excerpt about something', 'is_article' => 0, 'is_index' => 0, 'has_video' => 0, 'has_image' => 0, 'word_count' => 123)))));
$this->setPocketResponse($response);
$response = $this->pockpack->retrieve();
$this->assertEquals(1, $response->status);
$this->assertEquals(1, $response->complete);
$this->assertNotEmpty($response->list);
$this->assertNotEmpty($response->list->{123});
$item = $response->list->{123};
$this->assertEquals(123, $item->item_id);
$this->assertEquals(123, $item->resolved_id);
$this->assertEquals('Andrew Cairns', $item->given_title);
$this->assertEquals('Andrew Cairns', $item->resolved_title);
$this->assertEquals('http://acairns.co.uk', $item->given_url);
$this->assertEquals('http://acairns.co.uk', $item->resolved_url);
$this->assertEquals('Some excerpt about something', $item->excerpt);
$this->assertEquals(0, $item->is_article);
$this->assertEquals(0, $item->favorite);
$this->assertEquals(0, $item->status);
$this->assertEquals(0, $item->time_read);
$this->assertEquals(0, $item->time_favorited);
$this->assertEquals(0, $item->sort_id);
$this->assertEquals(0, $item->is_index);
$this->assertEquals(0, $item->has_video);
$this->assertEquals(0, $item->has_image);
$this->assertEquals(123, $item->word_count);
}
开发者ID:duellsy,项目名称:pockpack,代码行数:29,代码来源:PockpackTest.php
示例7: determineCode
/**
* Determine an exception code from the given response, exception data and
* JSON body.
*
* @param Response $response
* @param array $data
* @param array $json
*
* @return string|null
*/
private function determineCode(Response $response, array $data, array $json)
{
if (409 === $response->getStatusCode()) {
return 'DocumentAlreadyExists';
}
return $this->determineCodeFromErrors($data['errors']);
}
开发者ID:sajari,项目名称:sajari-sdk-php,代码行数:17,代码来源:EngineExceptionParser.php
示例8: debug
public function debug()
{
$r = new Response();
var_dump($r->getReasonPhrase());
$req = new Request();
$req->getPath();
}
开发者ID:arthurwayne,项目名称:ovh-sdk-php,代码行数:7,代码来源:VoiceConsumptionException.php
示例9: getDelay
/**
* {@inheritdoc}
*/
protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
{
if ($response && $response->isClientError()) {
$parts = $this->parser->parse($response);
return $parts['code'] == 'ProvisionedThroughputExceededException' || $parts['code'] == 'ThrottlingException' ? true : null;
}
}
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:10,代码来源:ThrottlingErrorChecker.php
示例10: getApiLimit
public static function getApiLimit(Response $response)
{
$remainingCalls = $response->getHeader('X-RateLimit-Remaining');
if (null !== $remainingCalls && 1 > $remainingCalls) {
throw new ApiLimitExceedException($remainingCalls);
}
}
开发者ID:alnutile,项目名称:saucelabs_client,代码行数:7,代码来源:ResponseMediator.php
示例11: testRateReset
/**
* Tests getRateReset method
*/
public function testRateReset()
{
$response = new Response(200);
$response->setHeader('X-Rate-Reset', '100');
$client = new GenderizeClient();
$client->setLastResponse($response);
$this->assertEquals('100', $client->getRateReset());
}
开发者ID:javihgil,项目名称:genderize-io-client,代码行数:11,代码来源:GenderizeClientTest.php
示例12: onOpen
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
{
$this->log('open', $conn);
$response = new Response(200, array('Content-type' => 'text/javascript', 'Content-Length' => $this->getFilesize($request->getPath())));
$response->setBody($this->getContent($request->getPath()));
$conn->send((string) $response);
$conn->close();
}
开发者ID:codesleeve,项目名称:guard-live-reload,代码行数:8,代码来源:HttpFileProtocol.php
示例13: getRequestTime
private function getRequestTime(GuzzleResponse $response)
{
$time = $response->getInfo('total_time');
if (null === $time) {
$time = 0;
}
return (int) ($time * 1000);
}
开发者ID:aciliainternet,项目名称:guzzle-bundle,代码行数:8,代码来源:GuzzleDataCollector.php
示例14: logResponse
/**
* @param \Guzzle\Http\Message\Response $response
* @param array $extra
*/
public function logResponse($response, $extra = array())
{
!array_key_exists("serialization_time", $extra) && ($extra["serialization_time"] = "-");
!array_key_exists("deserialization_time", $extra) && ($extra["deserialization_time"] = "-");
!array_key_exists("search_time", $extra) && ($extra["search_time"] = "-");
!array_key_exists("method", $extra) && ($extra["method"] = "-");
$this->logger->debug(self::getProcessId() . ' ' . $extra["method"] . ' ' . $response->getInfo("url") . ' ' . $response->getInfo("total_time") . ' ' . $extra["deserialization_time"] . ' ' . $extra["serialization_time"] . ' ' . $extra["search_time"]);
}
开发者ID:shopping-adventure,项目名称:RiakBundle,代码行数:12,代码来源:BaseServiceClient.php
示例15: parseResponseIntoArray
/**
* Parses response into an array
*
* @param Response $response
* @return array
*/
protected function parseResponseIntoArray($response)
{
if (strpos($response->getContentType(), 'json') === false) {
parse_str($response->getBody(true), $array);
return $array;
}
return $response->json();
}
开发者ID:opdavies,项目名称:nwdrupalwebsite,代码行数:14,代码来源:MeetupResponseParser.php
示例16: parseHeaders
/**
* Parses additional exception information from the response headers
*
* @param RequestInterface $request Request that was issued
* @param Response $response The response from the request
* @param array $data The current set of exception data
*/
protected function parseHeaders(RequestInterface $request, Response $response, array &$data)
{
$data['message'] = $response->getStatusCode() . ' ' . $response->getReasonPhrase();
if ($requestId = $response->getHeader('x-amz-request-id')) {
$data['request_id'] = $requestId;
$data['message'] .= " (Request-ID: {$requestId})";
}
}
开发者ID:skinnard,项目名称:FTL-2,代码行数:15,代码来源:DefaultXmlExceptionParser.php
示例17: fromResponse
/**
* Factory method that allows for easy instantiation from a Response object.
*
* @param Response $response
* @param AbstractService $service
* @return static
*/
public static function fromResponse(Response $response, AbstractService $service)
{
$object = new static($service);
if (null !== ($headers = $response->getHeaders())) {
$object->setMetadata($headers, true);
}
return $object;
}
开发者ID:huhugon,项目名称:sso,代码行数:15,代码来源:AbstractResource.php
示例18: getResponseAsArray
/**
* Get response as an array.
*
* @return array
*/
private function getResponseAsArray()
{
$this->result = $this->response->json();
if ($this->responseHasErrors()) {
return false;
}
return $this->result;
}
开发者ID:RuslanZavacky,项目名称:JiraApiBundle,代码行数:13,代码来源:AbstractService.php
示例19: factory
/**
* Factory method to create a new Oauth exception.
*
* @param RequestInterface $request
* @param Response $response
*
* @return OauthException
*/
public static function factory(RequestInterface $request, Response $response)
{
$message = 'Client error response' . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
$e = new static($message);
$e->setResponse($response);
$e->setRequest($request);
return $e;
}
开发者ID:cpliakas,项目名称:magento-client-php,代码行数:16,代码来源:OauthException.php
示例20: handshake
/**
* @param Guzzle\Http\Message\RequestInterface
* @return Guzzle\Http\Message\Response
*/
public function handshake(RequestInterface $request)
{
$body = $this->sign($request->getHeader('Sec-WebSocket-Key1', true), $request->getHeader('Sec-WebSocket-Key2', true), (string) $request->getBody());
$headers = array('Upgrade' => 'WebSocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Origin' => $request->getHeader('Origin', true), 'Sec-WebSocket-Location' => 'ws://' . $request->getHeader('Host', true) . $request->getPath());
$response = new Response(101, $headers, $body);
$response->setStatus(101, 'WebSocket Protocol Handshake');
return $response;
}
开发者ID:unkerror,项目名称:Budabot,代码行数:12,代码来源:Hixie76.php
注:本文中的Guzzle\Http\Message\Response类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论