本文整理汇总了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']);
}
示例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());
}
示例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));
*
*/
}
示例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);
}
示例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());
}
示例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']);
}
示例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;
}
示例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();
}
示例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;
}
}
示例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;
}
示例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()));
}
示例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;
}
示例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));
}
示例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);
}
示例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();
}