本文整理汇总了PHP中HTTP_Request2::setAdapter方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request2::setAdapter方法的具体用法?PHP HTTP_Request2::setAdapter怎么用?PHP HTTP_Request2::setAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request2
的用法示例。
在下文中一共展示了HTTP_Request2::setAdapter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequest
/**
* @param string $user
* @param string $apiKey
*
* @return Request2
*/
public function getRequest($user, $apiKey)
{
if ($this->req === null) {
$this->req = new Request2();
$this->req->setAdapter('curl')->setHeader('user-agent', 'Services_Librato');
}
$this->req->setAuth($user, $apiKey);
return $this->req;
}
示例2: testSetRequest
public function testSetRequest()
{
$newswire = new Newswire('apikey');
$req = new \HTTP_Request2();
$req->setAdapter('mock');
$this->assertInstanceOf('PEAR2\\Services\\NYTimes\\Newswire', $newswire->accept($req));
}
示例3: setUp
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
protected function setUp()
{
$this->mock = new HTTP_Request2_Adapter_Mock();
$request = new HTTP_Request2();
$request->setAdapter($this->mock);
$this->validator = new Services_W3C_CSSValidator($request);
}
示例4: request
private function request($method, $path, $params = array())
{
$url = $this->api . rtrim($path, '/') . '/';
if (!strcmp($method, "POST")) {
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
$req->setHeader('Content-type: application/json');
if ($params) {
$req->setBody(json_encode($params));
}
} else {
if (!strcmp($method, "GET")) {
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
$url = $req->getUrl();
$url->setQueryVariables($params);
} else {
if (!strcmp($method, "DELETE")) {
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_DELETE);
$url = $req->getUrl();
$url->setQueryVariables($params);
}
}
}
$req->setAdapter('curl');
$req->setConfig(array('timeout' => 30));
$req->setAuth($this->auth_id, $this->auth_token, HTTP_Request2::AUTH_BASIC);
$req->setHeader(array('Connection' => 'close', 'User-Agent' => 'PHPPlivo'));
$r = $req->send();
$status = $r->getStatus();
$body = $r->getbody();
$response = json_decode($body, true);
return array("status" => $status, "response" => $response);
}
示例5: addHttpMock
protected function addHttpMock(Net_WebFinger $wf)
{
$this->adapter = new HTTP_Request2_Adapter_LogMock();
$req = new HTTP_Request2();
$req->setAdapter($this->adapter);
$wf->setHttpClient($req);
return $this;
}
示例6: testGetException
/**
* @expectedException Services_Yadis_Exception
* @expectedExceptionMessage Invalid response to Yadis protocol received: A test error
*/
public function testGetException()
{
$httpMock = new HTTP_Request2_Adapter_Mock();
$httpMock->addResponse(new HTTP_Request2_Exception('A test error', 500));
$http = new HTTP_Request2();
$http->setAdapter($httpMock);
$sy = new Services_Yadis('http://example.org/openid');
$sy->setHttpRequest($http);
$xrds = $sy->discover();
}
示例7: getContents
function getContents($url, $start = 0, $userAgent = null)
{
if ($start > 0) {
$url .= "&start={$start}";
}
$http = new HTTP_Request2($url);
$http->setAdapter('curl');
if ($userAgent !== null) {
$http->setHeader('User-Agent', $userAgent);
}
return $http->send();
}
示例8: setUp
public function setUp()
{
parent::setUp();
Yii::configure(Yii::$app, ['components' => ['user' => ['class' => 'yii\\web\\User', 'identityClass' => 'common\\models\\User'], 'p24' => ['class' => \merigold\przelewy24\src\Przelewy24Component::className(), 'merchant_id' => $this->merchant_id, 'pos_id' => $this->merchant_id, 'CRC' => $this->CRC]]]);
Yii::$container->set('HTTP_Request2', function () {
$response = new HTTP_Request2_Response("HTTP/1.1 200 OK", true);
$response->appendBody($this->succesresponse);
$mockAdapter = new HTTP_Request2_Adapter_Mock();
$mockAdapter->addResponse($response);
$stub = new HTTP_Request2(\merigold\przelewy24\src\Przelewy24Component::TEST_URL, HTTP_Request2::METHOD_POST);
$stub->setAdapter($mockAdapter);
return $stub;
});
}
示例9: testShouldCompleteTransaction
public function testShouldCompleteTransaction()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse('HTTP/1.1 200 OK');
$request = new HTTP_Request2();
$request->setAdapter($mock);
$object = Payment_Process2::factory('Dummy');
$object->login = 'unit';
$object->password = 'test';
$object->action = Payment_Process2::ACTION_NORMAL;
$object->amount = 1;
$object->setRequest($request);
$object->setPayment($this->aValidPayment());
$result = $object->process();
$this->assertTrue($result instanceof Payment_Process2_Result_Dummy);
}
示例10: http2_request
private function http2_request($method, $path, $params)
{
$url = $this->api . $path;
$http_method = \HTTP_Request2::METHOD_POST;
if (!strcmp($method, "GET")) {
$http_method = \HTTP_Request2::METHOD_GET;
} else {
if (!strcmp($method, "DELETE")) {
$http_method = \HTTP_Request2::METHOD_DELETE;
}
}
$req = new \HTTP_Request2($url, $http_method);
if ($http_method === \HTTP_Request2::METHOD_POST && $params) {
$req->setBody(json_encode($params));
}
$req->setAdapter('curl');
$req->setConfig(array('timeout' => 30, 'ssl_verify_peer' => FALSE));
$req->setHeader(array('Authorization' => $this->auth_token, 'Connection' => 'close', 'User-Agent' => 'CheckMobi/http2_request', 'Content-type' => 'application/json'));
$r = $req->send();
$status = $r->getStatus();
$body = $r->getbody();
$response = json_decode($body, true);
return array("status" => $status, "response" => $response);
}
示例11: mockDataProviderHelper
public static function mockDataProviderHelper($file)
{
$process = self::aProcessor();
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(self::aResponse($file));
$request = new HTTP_Request2();
$request->setAdapter($mock);
$process->setRequest($request);
return array($process);
}
示例12: testResponseException
public function testResponseException()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(new HTTP_Request2_Exception('Shit happens'));
$req = new HTTP_Request2('http://www.example.com/');
$req->setAdapter($mock);
try {
$req->send();
} catch (Exception $e) {
$this->assertEquals('Shit happens', $e->getMessage());
return;
}
$this->fail('Expected HTTP_Request2_Exception was not thrown');
}
示例13: getHTTPRequest2Instance
/**
* Instantiates HTTP_Request2. Abstracted for testing.
*
* @see directRequest()
* @return HTTP_Request2_Response
*/
protected function getHTTPRequest2Instance()
{
// @codeCoverageIgnoreStart
$request = new HTTP_Request2();
$request->setAdapter('curl');
return $request;
// @codeCoverageIgnoreEnd
}
示例14: send
/**
* The actual method for sending requests
*
* @param string $url
* @param array $headers
* @param array $params
* @return HTTP_Request2_Response
*/
protected function send($method, $url, array $params = array(), array $headers = array())
{
$headers['GData-Version'] = '2';
$headers['User-Agent'] = 'Vivvo/' . VIVVO_VERSION . ' (' . self::$request_adapter . ') PHP/' . PHP_VERSION;
$request = new HTTP_Request2($url);
$request->setAdapter(self::$request_adapter);
$request->setConfig('ssl_verify_peer', false);
$request->setConfig('follow_redirects', true);
$request->setHeader($headers);
$request->setMethod($method);
if ($method == HTTP_Request2::METHOD_POST) {
$request->addPostParameter($params);
}
return $request->send();
}
示例15: testShouldFailGracefullyOnFailedTransaction
public function testShouldFailGracefullyOnFailedTransaction()
{
$response = new HTTP_Request2_Response('HTTP/1.1 200 OK');
$response->appendBody(file_get_contents(dirname(__FILE__) . '/data/TrustCommerce/error.html'));
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse($response);
$request = new HTTP_Request2();
$request->setAdapter($mock);
$object = Payment_Process2::factory('TrustCommerce');
$object->setPayment($this->aValidPayment());
$object->login = 'unit';
$object->password = 'test';
$object->amount = 1;
$object->action = Payment_Process2::ACTION_NORMAL;
$object->setRequest($request);
$result = $object->process();
$this->assertTrue($result instanceof Payment_Process2_Result_TrustCommerce);
$this->assertSame(Payment_Process2::RESULT_OTHER, $result->getCode(), $result->getMessage());
}