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


PHP Response::fromString方法代碼示例

本文整理匯總了PHP中Zend\Http\Response::fromString方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::fromString方法的具體用法?PHP Response::fromString怎麽用?PHP Response::fromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Http\Response的用法示例。


在下文中一共展示了Response::fromString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testClearHeadersCharset

 public function testClearHeadersCharset()
 {
     $header = "HTTP/1.1 200 OK" . "\r\n" . "Content-Type: text/html; charset=Shift-JIS";
     $response = Response::fromString("{$header}\r\n\r\nABC");
     $c = Filter::clearHeadersCharset($response->getHeaders()->toArray());
     $this->assertEquals('text/html', $c['Content-Type']);
 }
開發者ID:bobbyshaw,項目名稱:Diggin_Http_Charset,代碼行數:7,代碼來源:FilterTest.php

示例2: testResponseFactoryFromStringCreatesValidResponse

 public function testResponseFactoryFromStringCreatesValidResponse()
 {
     $string = 'HTTP/1.0 200 OK' . "\r\n\r\n" . 'Foo Bar';
     $response = Response::fromString($string);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('Foo Bar', $response->getContent());
 }
開發者ID:alab1001101,項目名稱:zf2,代碼行數:7,代碼來源:ResponseTest.php

示例3: testGetAdapterWithConfig

 public function testGetAdapterWithConfig()
 {
     $httptest = new HttpClientTest();
     // Nirvanix adapter
     $nirvanixConfig = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/nirvanix.ini'), true);
     $nirvanixConfig = $nirvanixConfig->toArray();
     $nirvanixConfig[Nirvanix::HTTP_ADAPTER] = $httptest;
     $doc = new \DOMDocument('1.0', 'utf-8');
     $root = $doc->createElement('Response');
     $responseCode = $doc->createElement('ResponseCode', 0);
     $sessionTok = $doc->createElement('SessionToken', '54592180-7060-4D4B-BC74-2566F4B2F943');
     $root->appendChild($responseCode);
     $root->appendChild($sessionTok);
     $doc->appendChild($root);
     $body = $doc->saveXML();
     $resp = HttpResponse::fromString("HTTP/1.1 200 OK\nContent-type: text/xml;charset=UTF-8\nDate: 0\n\n" . $body);
     $httptest->setResponse($resp);
     $nirvanixAdapter = Factory::getAdapter($nirvanixConfig);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\Nirvanix', get_class($nirvanixAdapter));
     // S3 adapter
     $s3Config = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/s3.ini'), true);
     $s3Adapter = Factory::getAdapter($s3Config);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\S3', get_class($s3Adapter));
     // file system adapter
     $fileSystemConfig = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/filesystem.ini'), true);
     $fileSystemAdapter = Factory::getAdapter($fileSystemConfig);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\FileSystem', get_class($fileSystemAdapter));
     // Azure adapter
     /*
             $azureConfig    = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/windowsazure.ini'), true);
             $azureConfig    = $azureConfig->toArray();
             $azureContainer = $azureConfig[WindowsAzure::CONTAINER];
             $azureConfig[WindowsAzure::HTTP_ADAPTER] = $httptest;
             $q = "?";
     
             $doc = new \DOMDocument('1.0', 'utf-8');
             $root = $doc->createElement('EnumerationResults');
             $acctName = $doc->createAttribute('AccountName');
             $acctName->value = 'http://myaccount.blob.core.windows.net';
             $root->appendChild($acctName);
             $maxResults     = $doc->createElement('MaxResults', 1);
             $containers     = $doc->createElement('Containers');
             $container      = $doc->createElement('Container');
             $containerName  = $doc->createElement('Name', $azureContainer);
             $container->appendChild($containerName);
             $containers->appendChild($container);
             $root->appendChild($maxResults);
             $root->appendChild($containers);
             $doc->appendChild($root);
             $body = $doc->saveXML();
     
             $resp = HttpResponse::fromString("HTTP/1.1 200 OK\nContent-type: text/xml;charset=UTF-8\nx-ms-request-id: 0\n\n".$body);
     
             $httptest->setResponse($resp);
             $azureAdapter = Factory::getAdapter($azureConfig);
             $this->assertEquals('Zend\Cloud\StorageService\Adapter\WindowsAzure', get_class($azureAdapter));
     *
     */
 }
開發者ID:robertodormepoco,項目名稱:zf2,代碼行數:59,代碼來源:FactoryTest.php

示例4: restGet

 /**
  * Mock the actual rest call
  */
 public function restGet($path, array $query = null)
 {
     /**
      * We could simulate a connection failure by supplyng
      * $responseText = file_get_contents(ROOT_PATH . "/test/HotelTest/connectionError.txt");
      * or simulate invalid json coming from API ... etc
      * But its getting late .. :)
      */
     $responseText = file_get_contents(ROOT_PATH . "/test/HotelTest/hotels.txt");
     return Response::fromString($responseText);
 }
開發者ID:breaktherules,項目名稱:rest-hotel-client,代碼行數:14,代碼來源:ZendRestMock.php

示例5: testZF2

    public function testZF2()
    {
        $header = "HTTP/1.1 200 OK" . "\r\n" . "Content-Type: text/html; charset=Shift-JIS";
        $html = <<<EOF
            <html lang="ja" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml">
            <head><meta content="text/html; charset=Shift-JIS" http-equiv="Content-Type" /></head>
            <body><!--① ㈱① ㈱-->ああ</body>
EOF;
        $sjis = mb_convert_encoding($html, 'SJIS-win', 'UTF-8');
        $response = \Zend\Http\Response::fromString("{$header}\r\n\r\n{$sjis}");
        $response = WrapperFactory::factory($response);
        $this->assertInstanceOf('Zend\\Http\\Response', $response);
        $this->assertInstanceOf('Diggin\\Http\\Charset\\Wrapper\\ZF2Wrapper', $response);
        $this->assertEquals($html, $response->getBody());
    }
開發者ID:bobbyshaw,項目名稱:Diggin_Http_Charset,代碼行數:15,代碼來源:WrapperFactoryTest.php

示例6: testAcceptEncodingHeaderWorksProperly

 public function testAcceptEncodingHeaderWorksProperly()
 {
     $method = new \ReflectionMethod('\\Zend\\Http\\Client', 'prepareHeaders');
     $method->setAccessible(true);
     $requestString = "GET http://www.domain.com/index.php HTTP/1.1\r\nHost: domain.com\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20100101 Firefox/16.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n";
     $request = Request::fromString($requestString);
     $adapter = new \Zend\Http\Client\Adapter\Test();
     $client = new \Zend\Http\Client('http://www.domain.com/');
     $client->setAdapter($adapter);
     $client->setRequest($request);
     $rawHeaders = "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Encoding: gzip, deflate\r\nContent-Type: application/javascript\r\nDate: Sun, 18 Nov 2012 16:16:08 GMT\r\nServer: nginx/1.1.19\r\nVary: Accept-Encoding\r\nX-Powered-By: PHP/5.3.10-1ubuntu3.4\r\nConnection: keep-alive\r\n";
     $response = Response::fromString($rawHeaders);
     $client->getAdapter()->setResponse($response);
     $headers = $method->invoke($client, $requestString, $client->getUri());
     $this->assertEquals('gzip, deflate', $headers['Accept-Encoding']);
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:16,代碼來源:ClientTest.php

示例7: createConnector

 /**
  * Create connector with fixture file.
  *
  * @param string $fixture Fixture file
  *
  * @return Connector
  *
  * @throws InvalidArgumentException Fixture file does not exist
  */
 protected function createConnector($fixture = null)
 {
     $adapter = new TestAdapter();
     if ($fixture) {
         $file = realpath(__DIR__ . '/../../../../../../tests/fixtures/resolver/response/' . $fixture);
         if (!is_string($file) || !file_exists($file) || !is_readable($file)) {
             throw new InvalidArgumentException(sprintf('Unable to load fixture file: %s ', $file));
         }
         $response = file_get_contents($file);
         $responseObj = HttpResponse::fromString($response);
         $adapter->setResponse($responseObj);
     }
     $client = new \Zend\Http\Client();
     $client->setAdapter($adapter);
     $conn = new Redi($this->openUrlConfig['OpenURL']['url'], $client);
     return $conn;
 }
開發者ID:bbeckman,項目名稱:NDL-VuFind2,代碼行數:26,代碼來源:RediTest.php

示例8: _doRequest

 /**
  * Do request proxy method.
  *
  * @param  CommonClient $client   Actual SOAP client.
  * @param  string       $request  The request body.
  * @param  string       $location The SOAP URI.
  * @param  string       $action   The SOAP action to call.
  * @param  integer      $version  The SOAP version to use.
  * @param  integer      $one_way  (Optional) The number 1 if a response is not expected.
  * @return string The XML SOAP response.
  */
 public function _doRequest(CommonClient $client, $request, $location, $action, $version, $one_way = null)
 {
     if (!$this->useNtlm) {
         return parent::_doRequest($client, $request, $location, $action, $version, $one_way);
     }
     $curlClient = $this->getCurlClient();
     $headers = array('Content-Type' => 'text/xml; charset=utf-8', 'Method' => 'POST', 'SOAPAction' => '"' . $action . '"', 'User-Agent' => 'PHP-SOAP-CURL');
     $uri = new HttpUri($location);
     $curlClient->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_NTLM)->setCurlOption(CURLOPT_SSL_VERIFYHOST, false)->setCurlOption(CURLOPT_SSL_VERIFYPEER, false)->setCurlOption(CURLOPT_USERPWD, $this->options['login'] . ':' . $this->options['password']);
     // Perform the cURL request and get the response
     $curlClient->connect($uri->getHost(), $uri->getPort());
     $curlClient->write('POST', $uri, 1.1, $headers, $request);
     $response = HttpResponse::fromString($curlClient->read());
     $curlClient->close();
     // Save headers
     $this->lastRequestHeaders = $this->flattenHeaders($headers);
     $this->lastResponseHeaders = $response->getHeaders()->toString();
     // Return only the XML body
     return $response->getBody();
 }
開發者ID:razvansividra,項目名稱:pnlzf2-1,代碼行數:31,代碼來源:DotNet.php

示例9: init

 public function init(ModuleManager $moduleManager)
 {
     $config = $this->getConfig();
     $cache = StorageFactory::factory($config['page-cache']['cache']);
     if (filter_input(INPUT_GET, 'clear-cache')) {
         if ($cache instanceof ClearByNamespaceInterface) {
             $cache->clearByNameSpace($config['page-cache']['cache']['adapter']['options']['namespace']);
         }
     }
     if (filter_input(INPUT_GET, 'clear-expired')) {
         if ($cache instanceof ClearExpiredInterface) {
             $cache->clearExpired();
         }
     }
     $responseStr = $cache->getItem($this->getKey(), $success);
     if ($success) {
         $response = Response::fromString($responseStr);
         foreach ($response->getHeaders() as $header) {
             header($header->toString());
         }
         echo $response->getBody();
         exit;
     }
 }
開發者ID:RRcom,項目名稱:PageCache,代碼行數:24,代碼來源:Module.php

示例10: createConnector

 /**
  * Create connector with fixture file.
  *
  * @param string $fixture Fixture file
  *
  * @return Connector
  *
  * @throws InvalidArgumentException Fixture file does not exist
  */
 protected function createConnector($fixture = null)
 {
     $adapter = new TestAdapter();
     if ($fixture) {
         $file = realpath(__DIR__ . '/../../../../../../tests/fixtures/daia/response/' . $fixture);
         if (!is_string($file) || !file_exists($file) || !is_readable($file)) {
             throw new InvalidArgumentException(sprintf('Unable to load fixture file: %s ', $file));
         }
         $response = file_get_contents($file);
         $responseObj = HttpResponse::fromString($response);
         $adapter->setResponse($responseObj);
     }
     $service = new \VuFindHttp\HttpService();
     $service->setDefaultAdapter($adapter);
     $conn = new DAIA(new \VuFind\Date\Converter());
     $conn->setHttpService($service);
     return $conn;
 }
開發者ID:steenlibrary,項目名稱:vufind,代碼行數:27,代碼來源:DAIATest.php

示例11: testMultibyteChunkedResponse

 /**
  * Test that parsing a multibyte-encoded chunked response works.
  *
  * This can potentially fail on different PHP environments - for example
  * when mbstring.func_overload is set to overload strlen().
  *
  */
 public function testMultibyteChunkedResponse()
 {
     $this->markTestSkipped('Looks like the headers are split with \\n and the body with \\r\\n');
     $md5 = 'ab952f1617d0e28724932401f2d3c6ae';
     $response = Response::fromString($this->readResponse('response_multibyte_body'));
     $this->assertEquals($md5, md5($response->getBody()));
 }
開發者ID:haoyanfei,項目名稱:zf2,代碼行數:14,代碼來源:ResponseTest.php

示例12: createMockConnector

 /**
  * Create connector with fixture file.
  *
  * @param string $fixture Fixture file
  *
  * @return Connector
  *
  * @throws InvalidArgumentException Fixture file does not exist
  */
 protected function createMockConnector($fixture = null)
 {
     $adapter = new TestAdapter();
     if ($fixture) {
         $file = realpath(__DIR__ . '/../../../../../../tests/fixtures/paia/response/' . $fixture);
         if (!is_string($file) || !file_exists($file) || !is_readable($file)) {
             throw new InvalidArgumentException(sprintf('Unable to load fixture file: %s ', $file));
         }
         $response = file_get_contents($file);
         $responseObj = HttpResponse::fromString($response);
         $adapter->setResponse($responseObj);
     }
     $service = new \VuFindHttp\HttpService();
     $service->setDefaultAdapter($adapter);
     $conn = $this->getMockBuilder('VuFind\\ILS\\Driver\\PAIA')->setConstructorArgs([new \VuFind\Date\Converter(), new \Zend\Session\SessionManager()])->setMethods(['getScope'])->getMock();
     $conn->expects($this->any())->method('getScope')->will($this->returnValue(['write_items']));
     $conn->setHttpService($service);
     $conn->setConfig($this->validConfig);
     $conn->init();
     return $conn;
 }
開發者ID:bbeckman,項目名稱:NDL-VuFind2,代碼行數:30,代碼來源:PAIATest.php

示例13: loadResponse

 /**
  * Load a SOLR response as fixture.
  *
  * @param string $fixture Fixture file
  *
  * @return Zend\Http\Response
  *
  * @throws InvalidArgumentException Fixture files does not exist
  */
 protected function loadResponse($fixture)
 {
     $file = realpath(sprintf('%s/solr/response/%s', PHPUNIT_SEARCH_FIXTURES, $fixture));
     if (!is_string($file) || !file_exists($file) || !is_readable($file)) {
         throw new InvalidArgumentException(sprintf('Unable to load fixture file: %s', $file));
     }
     return Response::fromString(file_get_contents($file));
 }
開發者ID:grharry,項目名稱:vufind,代碼行數:17,代碼來源:BackendTest.php

示例14: toZend

 /**
  * Convert a PSR-7 response in a Zend\Http\Response
  *
  * @param  ResponseInterface $psr7Response
  * @return ZendResponse
  */
 public static function toZend(ResponseInterface $psr7Response)
 {
     $response = sprintf("HTTP/%s %d %s\r\n%s\r\n%s", $psr7Response->getProtocolVersion(), $psr7Response->getStatusCode(), $psr7Response->getReasonPhrase(), self::psr7HeadersToString($psr7Response), (string) $psr7Response->getBody());
     return ZendResponse::fromString($response);
 }
開發者ID:MidnightDesign,項目名稱:zend-psr7bridge,代碼行數:11,代碼來源:Psr7Response.php

示例15: readHandshakeResponse

 private function readHandshakeResponse($data)
 {
     $response = Response::fromString($data);
     $this->setResponse($response);
     $handshake = new Handshake($this->request, $response);
     $this->emit("handshake", array($handshake));
     if ($handshake->isAborted()) {
         $this->close();
         return '';
     }
     $this->connected = true;
     $this->emit("connect");
     return $response->getContent();
 }
開發者ID:rb-cohen,項目名稱:phpws,代碼行數:14,代碼來源:WebSocketTransportHybi.php


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