当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setBody方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Response::setBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setBody方法的具体用法?PHP Response::setBody怎么用?PHP Response::setBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::setBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateEbaySuccessResponse

 /**
  * @param $xml
  * @return Response
  */
 public function generateEbaySuccessResponse($xml)
 {
     $mockReponse = new Response(200);
     if (file_exists($xml)) {
         $mockReponse->setBody(EntityBody::factory(file_get_contents($xml)));
     } else {
         $mockReponse->setBody(EntityBody::factory($xml));
     }
     return $mockReponse;
 }
开发者ID:netoholic,项目名称:store-integrator,代码行数:14,代码来源:TestCase.php

示例2: 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

示例3: 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

示例4: 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

示例5: testReceivingAccessTokenAndUsername

 public function testReceivingAccessTokenAndUsername()
 {
     $response = new Response(200);
     $response->setBody(json_encode(array('access_token' => 'fake_access_token', 'username' => 'acairns')));
     $this->setPocketResponse($response);
     $data = $this->pockpack_auth->receiveTokenAndUsername('fake_consumer_key', 'fake_access_token');
     $this->assertEquals('fake_access_token', $data['access_token']);
     $this->assertEquals('acairns', $data['username']);
 }
开发者ID:duellsy,项目名称:pockpack,代码行数:9,代码来源:PockpackAuthTest.php

示例6: testCanCreateApiRateLimitErrorException

 public function testCanCreateApiRateLimitErrorException()
 {
     $command = $this->getMock('Guzzle\\Service\\Command\\CommandInterface');
     $request = $this->getMock('Guzzle\\Http\\Message\\Request', [], [], '', false);
     $command->expects($this->once())->method('getRequest')->will($this->returnValue($request));
     $response = new Response(400);
     $response->setBody(json_encode(['error' => ['type' => 'invalid_request_error', 'code' => 'rate_limit']]));
     $exception = BadRequestException::fromCommand($command, $response);
     $this->assertInstanceOf('ZfrStripe\\Exception\\ApiRateLimitException', $exception);
 }
开发者ID:netglue,项目名称:zfr-stripe,代码行数:10,代码来源:ExceptionTest.php

示例7: it_can_create_the_exception

 /** @test */
 public function it_can_create_the_exception()
 {
     $command = $this->getMock('Guzzle\\Service\\Command\\CommandInterface');
     $command->expects($this->once())->method('getRequest')->will($this->returnValue($this->getMock('Guzzle\\Http\\Message\\Request', [], [], '', false)));
     $response = new Response(400);
     $response->setBody('');
     /** @noinspection PhpParamsInspection */
     $exception = BadRequestException::fromCommand($command, $response);
     $this->assertInstanceOf('Apache\\Usergrid\\Api\\Exception\\BadRequestException', $exception);
 }
开发者ID:rodsimpson,项目名称:incubator-usergrid,代码行数:11,代码来源:BadRequestExceptionTest.php

示例8: setUp

 /**
  * Setup
  */
 public function setUp()
 {
     $plugin = new MockPlugin();
     $response = new GuzzleResponse(200);
     $response->setBody(file_get_contents(__DIR__ . '/Fixtures/response_projects.json'));
     $plugin->addResponse($response);
     $client = new VersionEyeClient('foo');
     $client->addSubscriber($plugin);
     $this->object = new VersionEyeApi($client, 'foo');
 }
开发者ID:digitalkaoz,项目名称:VersionEyeBundle,代码行数:13,代码来源:VersionEyeApiTest.php

示例9: onOpen

 public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
 {
     $this->emit('open', array($conn, $request));
     try {
         $this->router->dispatch($request, $conn);
     } catch (Exception $e) {
         $response = new Response(500);
         $response->setBody("Server error.");
         $conn->send($response);
         $conn->close();
     }
 }
开发者ID:steverhoades,项目名称:async-talk-examples,代码行数:12,代码来源:Server.php

示例10: getClient

 protected function getClient($fixtureFilePath = null)
 {
     if (null === $fixtureFilePath) {
         return $this->getMock('Guzzle\\Http\\Client');
     }
     $response = new Response(200);
     $response->setBody(file_get_contents($fixtureFilePath));
     $mock = new MockPlugin();
     $mock->addResponse($response);
     $client = new Client();
     $client->addSubscriber($mock);
     return $client;
 }
开发者ID:lyrixx,项目名称:lifestream,代码行数:13,代码来源:AbstractTest.php

示例11: setUp

 public function setUp()
 {
     $this->fixtureFilePath = __DIR__ . '/fixture';
     $httpClient = $this->getMockBuilder('Guzzle\\Http\\Client')->setMethods(array('send'))->getMock();
     // This client mock returns always a response object which body is a json-encoded array
     // containing the url and the method of the request.
     $httpClient->expects($this->any())->method('send')->will($this->returnCallback(function ($request) {
         $response = new Response(200);
         $response->setBody(json_encode(array('url' => $request->getUrl(), 'method' => $request->getMethod(), 'mime-type' => $request->getHeader('Content-Type', true))));
         return $response;
     }));
     $this->client = new Client('test', 'user', 'pswd', $httpClient);
     $this->client->setApiConfig($this->apiConfig);
 }
开发者ID:nicmart,项目名称:getlocalization,代码行数:14,代码来源:ClientTest.php

示例12: testGetAllProjects

 /**
  * @covers \Wordsmith\Project::all
  */
 public function testGetAllProjects()
 {
     $mockResponse = new Response(200);
     $mockResponseBody = EntityBody::factory(fopen(__DIR__ . '/mock/bodies/projects.txt', 'r+'));
     $mockResponse->setBody($mockResponseBody);
     $mockResponse->setHeaders(array("Host" => "httpbin.org", "User-Agent" => "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3", "Accept" => "application/json", "Content-Type" => "application/json"));
     $plugin = new MockPlugin();
     $plugin->addResponse($mockResponse);
     $client = new HttpClient();
     $client->addSubscriber($plugin);
     $request = $client->get('https://api.automatedinsights.com/v1/projects');
     $response = $request->send();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertTrue(in_array('Host', array_keys($response->getHeaders()->toArray())));
     $this->assertTrue($response->hasHeader("User-Agent"));
     $this->assertCount(4, $response->getHeaders());
     $this->assertSame($mockResponseBody->getSize(), $response->getBody()->getSize());
     $this->assertSame(1, count(json_decode($response->getBody(true))->data));
 }
开发者ID:sumoheavy,项目名称:wordsmith-php,代码行数:22,代码来源:ProjectTest.php

示例13: testDeserializeContextConfiguration

 public function testDeserializeContextConfiguration()
 {
     $expectedContext = DeserializationContext::create();
     $expectedContext->setGroups('group');
     $expectedContext->setVersion(1);
     $expectedContext->enableMaxDepthChecks();
     $operation = $this->getMock('Guzzle\\Service\\Description\\OperationInterface');
     $operation->expects($this->any())->method('getResponseType')->will($this->returnValue(OperationInterface::TYPE_CLASS));
     $operation->expects($this->any())->method('getResponseClass')->will($this->returnValue('ResponseClass'));
     $dataMap = array(array('jms_serializer.groups', 'group'), array('jms_serializer.version', 1), array('jms_serializer.max_depth_checks', true));
     $operation->expects($this->any())->method('getData')->will($this->returnValueMap($dataMap));
     $command = $this->getMock('Guzzle\\Service\\Command\\CommandInterface');
     $command->expects($this->any())->method('getOperation')->will($this->returnValue($operation));
     $response = new Response(200);
     $response->setBody('body');
     $serializer = $this->getMock('JMS\\Serializer\\SerializerInterface');
     $serializer->expects($this->once())->method('deserialize')->with('body', 'ResponseClass', 'json', $this->equalTo($expectedContext));
     $parser = new JMSSerializerResponseParser($serializer, $this->getMock('Guzzle\\Service\\Command\\ResponseParserInterface'));
     $ref = new \ReflectionMethod($parser, 'deserialize');
     $ref->setAccessible(true);
     return $ref->invoke($parser, $command, $response, 'json');
 }
开发者ID:aciliainternet,项目名称:guzzle-bundle,代码行数:22,代码来源:JMSSerializerResponseParserTest.php

示例14: fetch

 public function fetch(RequestInterface $request)
 {
     $key = $this->getCacheKey($request);
     if (!($entries = $this->cache->fetch($key))) {
         return null;
     }
     $match = null;
     $headers = $this->persistHeaders($request);
     $entries = unserialize($entries);
     foreach ($entries as $index => $entry) {
         if ($this->requestsMatch(isset($entry[1]['vary']) ? $entry[1]['vary'] : '', $headers, $entry[0])) {
             $match = $entry;
             break;
         }
     }
     if (!$match) {
         return null;
     }
     // Ensure that the response is not expired
     $response = null;
     if ($match[4] < time()) {
         $response = -1;
     } else {
         $response = new Response($match[2], $match[1]);
         if ($match[3]) {
             if ($body = $this->cache->fetch($match[3])) {
                 $response->setBody($body);
             } else {
                 // The response is not valid because the body was somehow deleted
                 $response = -1;
             }
         }
     }
     if ($response === -1) {
         // Remove the entry from the metadata and update the cache
         unset($entries[$index]);
         if ($entries) {
             $this->cache->save($key, serialize($entries));
         } else {
             $this->cache->delete($key);
         }
         return null;
     }
     return $response;
 }
开发者ID:diandianxiyu,项目名称:Yii2Api,代码行数:45,代码来源:DefaultCacheStorage.php

示例15: createGuzzleMockPlugin

 /**
  * @return MockPlugin
  */
 private function createGuzzleMockPlugin()
 {
     $terytPageFixturesPath = $this->fixturesPath . '/TerytPage';
     $mock = new MockPlugin();
     $downloadPageResponse = new Response(200);
     $downloadPageResponse->setBody(file_get_contents($terytPageFixturesPath . DIRECTORY_SEPARATOR . 'listTerytFiles.html'));
     $mock->addResponse($downloadPageResponse);
     return $mock;
 }
开发者ID:jacdobro,项目名称:teryt-database-bundle,代码行数:12,代码来源:CommandContext.php


注:本文中的Guzzle\Http\Message\Response::setBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。