本文整理汇总了PHP中Buzz\Message\Response类的典型用法代码示例。如果您正苦于以下问题:PHP Response类的具体用法?PHP Response怎么用?PHP Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createResponse
protected function createResponse($content = '')
{
$response = new Buzz\Message\Response();
$response->addHeader('1.0 200 OK');
$response->setContent($content);
return $response;
}
示例2: createResponse
private function createResponse($content, $statusCode = 200)
{
$response = new Response();
$response->setContent($content);
$response->setHeaders(array('HTTP/1.1 ' . $statusCode . ' REASON'));
return $response;
}
示例3: testAddHeadersResetsStatusLine
public function testAddHeadersResetsStatusLine()
{
$response = new Response();
$this->assertNull($response->getStatusCode());
$response->addHeaders(array('1.0 200 OK'));
$this->assertEquals(200, $response->getStatusCode());
}
示例4: __construct
public function __construct(TransportResponse $response)
{
if (!$response->isSuccessful()) {
throw new TransportException($response);
}
$this->response = $response;
}
示例5: verifyResult
/**
* Verifies the last request.
* If the last request was not successful, it will be throw an exception.
*
* @param \Buzz\Message\Response $response The response object from the last reques
* @param string $url The url which was requested
* @return \Buzz\Message\Response
* @throws \Exception
*/
protected function verifyResult(\Buzz\Message\Response $response, $url)
{
if ($response->getStatusCode() !== 200) {
throw new \Exception('Request to "' . $url . '" failed', 1364061673);
}
return $response;
}
示例6: parse
/**
* @param Response $curlResponse
*
* @throws HttpStatusParserException
*/
public function parse(Response $curlResponse)
{
$statusCode = $curlResponse->getStatusCode();
if ($this->shouldThrowException($statusCode)) {
throw new HttpStatusParserException($curlResponse->getContent(), $statusCode);
}
}
示例7: rev
public function rev(Response $response)
{
if ($response->isSuccessful()) {
return $this->decode($response->getHeader('Etag'));
}
throw new RugException('not_found', 'The specified document or revision cannot be found or has been deleted');
}
示例8: handleResponseAuthHeader
/**
* @param \Buzz\Message\Response $response
*/
private function handleResponseAuthHeader(\Buzz\Message\Response $response)
{
$token = $response->getHeader('Update-Client-Auth');
if ($token) {
$this->client->setAuthToken($token);
$this->setTokenToCache($token);
}
}
示例9: send
/**
* @see Client\ClientInterface
*/
public function send(Message\Request $request, Message\Response $response)
{
if (!($queued = $this->receiveFromQueue())) {
throw new \LogicException('There are no queued responses.');
}
$response->setHeaders($queued->getHeaders());
$response->setContent($queued->getContent());
}
示例10: 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');
}
示例11: testGetDomReturnsADomDocument
public function testGetDomReturnsADomDocument()
{
$response = new Message\Response();
$response->setContent('<html><head></head><body></body></html>');
$this->browser->getClient()->sendToQueue($response);
$this->browser->get('http://www.google.com');
$this->assertTrue($this->browser->getDom() instanceof \DOMDocument);
}
示例12: assertHttpResponseHasHeader
protected function assertHttpResponseHasHeader(HttpResponse $response, $header, $expectedValue = null)
{
$headerValue = $response->getHeader($header);
self::assertNotNull($headerValue, "Failed asserting that response has a {$header} header");
if ($expectedValue !== null) {
self::assertEquals($expectedValue, $headerValue);
}
}
示例13: _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;
}
示例14: processSetCookieHeaders
/**
* Processes Set-Cookie headers from a request/response pair.
*
* @param Message\Request $request A request object
* @param Message\Response $response A response object
*/
public function processSetCookieHeaders(Message\Request $request, Message\Response $response)
{
foreach ($response->getHeader('Set-Cookie', false) as $header) {
$cookie = new Cookie();
$cookie->fromSetCookieHeader($header, parse_url($request->getHost(), PHP_URL_HOST));
$this->addCookie($cookie);
}
}
示例15: 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];
}