本文整理汇总了PHP中Guzzle\Http\Client::getConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getConfig方法的具体用法?PHP Client::getConfig怎么用?PHP Client::getConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::getConfig方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getClient
/**
* @return Guzzle\Http\Client
*/
public function getClient()
{
if (!isset($this->o_client)) {
$this->o_client = new \Guzzle\Http\Client(self::NSL_SERVICES_URL, array('request.params' => array('cache.override_ttl' => 3600, 'params.cache.revalidate' => 'skip')));
// can_cache needs to be callable
$this->o_client->addSubscriber(new CachePlugin(array('storage' => new DefaultCacheStorage(new DoctrineCacheAdapter(new FilesystemCache(caGetTempDirPath()))), 'can_cache' => function () {
// let's just cache for the above ttl
return true;
})));
$o_conf = Configuration::load();
if ($vs_proxy = $o_conf->get('web_services_proxy_url')) {
/* proxy server is configured */
$vo_config = $this->o_client->getConfig()->add('proxy', $vs_proxy);
if (($vs_proxy_user = $o_conf->get('web_services_proxy_auth_user')) && ($vs_proxy_pass = $o_conf->get('web_services_proxy_auth_pw'))) {
$vo_config->add('curl.options', array(CURLOPT_PROXYUSERPWD => "{$vs_proxy_user}:{$vs_proxy_pass}"));
}
}
}
return $this->o_client;
}
示例2: __construct
public function __construct($username, $token, $client = null, $fragment = null)
{
parent::__construct('https://push.superfeedr.com');
$this->username = $username;
$this->token = $token;
if ($client === null) {
$client = new Guzzle\Http\Client();
}
$client->getConfig()->setPath('request.options/auth', [$username, $token]);
$this->client = $client;
if ($fragment !== null) {
$this->fragment = $fragment;
}
}
示例3: getClient
/**
* @return \Guzzle\Http\Client
*/
protected function getClient()
{
if ($this->client === null) {
$this->client = new Client('https://bitbucket.org/api/1.0/');
if ($this->authentication) {
switch ($this->authentication->getType()) {
case AuthInterface::BASIC:
$this->client->getConfig()->setPath('request.options/auth', array($this->authentication->getUsername(), $this->authentication->getPassword(), 'Basic|Digest|NTLM|Any'));
break;
case AuthInterface::OAUTH:
// TODO
throw new \RuntimeException('Incomplete implementation');
break;
default:
throw new \RuntimeException(sprintf('Authentication via "%s" is not supported by bitbucket', $this->authentication->getType()));
}
}
}
return $this->client;
}
示例4: testProperlyBlocksBasedOnRequestsInScope
/**
* @covers Guzzle\Http\Curl\CurlMulti
*/
public function testProperlyBlocksBasedOnRequestsInScope()
{
$this->getServer()->flush();
$this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest1", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest2", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest3", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest4", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest5", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest6", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
$client = new Client($this->getServer()->getUrl());
$requests = array($client->get(), $client->get(), $client->get());
// Sends 2 new requests in the middle of a CurlMulti loop while other requests
// are completing. This causes the scope of the multi handle to go up.
$callback = function (Event $event) use($client) {
$client->getConfig()->set('called', $client->getConfig('called') + 1);
$request = $client->get();
if ($client->getConfig('called') <= 2) {
$request->getEventDispatcher()->addListener('request.complete', function (Event $event) use($client) {
$client->head()->send();
});
}
$request->send();
};
$requests[0]->getEventDispatcher()->addListener('request.complete', $callback);
$requests[1]->getEventDispatcher()->addListener('request.complete', $callback);
$requests[2]->getEventDispatcher()->addListener('request.complete', $callback);
$client->send($requests);
$this->assertEquals(8, count($this->getServer()->getReceivedRequests(false)));
}
示例5: testHardResetReopensMultiHandle
public function testHardResetReopensMultiHandle()
{
$this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
$stream = fopen('php://temp', 'w+');
$client = new Client($this->getServer()->getUrl());
$client->getConfig()->set('curl.CURLOPT_VERBOSE', true)->set('curl.CURLOPT_STDERR', $stream);
$request = $client->get();
$multi = new CurlMulti();
$multi->add($request);
$multi->send();
$multi->reset(true);
$multi->add($request);
$multi->send();
rewind($stream);
$this->assertNotContains('Re-using existing connection', stream_get_contents($stream));
}
示例6: testHasDefaultOptionsHelperMethods
public function testHasDefaultOptionsHelperMethods()
{
$client = new Client();
// With path
$client->setDefaultOption('headers/foo', 'bar');
$this->assertEquals('bar', $client->getDefaultOption('headers/foo'));
// With simple key
$client->setDefaultOption('allow_redirects', false);
$this->assertFalse($client->getDefaultOption('allow_redirects'));
$this->assertEquals(array('headers' => array('foo' => 'bar'), 'allow_redirects' => false), $client->getConfig('request.options'));
$request = $client->get('/');
$this->assertEquals('bar', $request->getHeader('foo'));
}
示例7: testCanSetDefaultRequestOptions
public function testCanSetDefaultRequestOptions()
{
$client = new Client();
$client->getConfig()->set('request.options', array('query' => array('test' => '123', 'other' => 'abc'), 'headers' => array('Foo' => 'Bar', 'Baz' => 'Bam')));
$request = $client->createRequest('GET', 'http://www.foo.com?test=hello', array('Foo' => 'Test'));
// Explicit options on a request should overrule default options
$this->assertEquals('Test', (string) $request->getHeader('Foo'));
$this->assertEquals('hello', $request->getQuery()->get('test'));
// Default options should still be set
$this->assertEquals('abc', $request->getQuery()->get('other'));
$this->assertEquals('Bam', (string) $request->getHeader('Baz'));
}
示例8: testCreatesRequestsWithDefaultValues
/**
* @covers Guzzle\Http\Client::createRequest
*/
public function testCreatesRequestsWithDefaultValues()
{
$client = new Client($this->getServer()->getUrl() . 'base');
// Create a GET request
$request = $client->createRequest();
$this->assertEquals('GET', $request->getMethod());
$this->assertEquals($client->getBaseUrl(), $request->getUrl());
// Create a DELETE request
$request = $client->createRequest('DELETE');
$this->assertEquals('DELETE', $request->getMethod());
$this->assertEquals($client->getBaseUrl(), $request->getUrl());
// Create a HEAD request with custom headers
$request = $client->createRequest('HEAD', 'http://www.test.com/');
$this->assertEquals('HEAD', $request->getMethod());
$this->assertEquals('http://www.test.com/', $request->getUrl());
// Create a PUT request
$request = $client->createRequest('PUT');
$this->assertEquals('PUT', $request->getMethod());
// Create a PUT request with injected config
$client->getConfig()->set('a', 1)->set('b', 2);
$request = $client->createRequest('PUT', '/path/{a}?q={b}');
$this->assertEquals($request->getUrl(), $this->getServer()->getUrl() . 'path/1?q=2');
}
示例9: getDefaultOptions
public function getDefaultOptions()
{
return $this->client->getConfig();
}
示例10: testAllowsCustomCacheFilterStrategies
public function testAllowsCustomCacheFilterStrategies()
{
$plugin = new CachePlugin($this->adapter);
$client = new Client($this->getServer()->getUrl(), array('params.cache.filter_strategy' => function ($request) {
return true;
}));
$plugin->onRequestBeforeSend(new Event(array('request' => $client->post('/'))));
$this->assertEquals(1, count($this->readAttribute($plugin, 'cached')));
$client->getConfig()->set('params.cache.filter_strategy', function ($request) {
return false;
});
$plugin->onRequestBeforeSend(new Event(array('request' => $client->get('/'))));
$this->assertEquals(1, count($this->readAttribute($plugin, 'cached')));
}
示例11: getGuzzleConfig
/**
* @param string|bool $key
* @return \Guzzle\Common\Collection|mixed
*/
public function getGuzzleConfig($key = false)
{
return $this->client->getConfig($key);
}
示例12: __construct
/**
* Create a new instance.
*
* @param string $user The transifex API user.
*
* @param string $pass The transifex API password.
*/
public function __construct($user, $pass)
{
$this->client = new Client('http://www.transifex.com/api/2/');
$this->client->getConfig()->setPath('request.options/auth', array($user, $pass, 'Basic'));
}
示例13: getClient
/**
* @return \Guzzle\Http\Client
*/
protected function getClient()
{
if ($this->client === null) {
$this->client = new Client('https://api.github.com/');
$this->client->setDefaultOption('headers/Accept', 'application/vnd.github.v3+json');
if ($this->authentication) {
switch ($this->authentication->getType()) {
case AuthInterface::BASIC:
$this->client->getConfig()->setPath('request.options/auth', array($this->authentication->getUsername(), $this->authentication->getPassword(), 'Basic|Digest|NTLM|Any'));
break;
case AuthInterface::ACCESS_TOKEN:
$this->client->setDefaultOption('headers/Authorization', 'token ' . $this->authentication->getAccessToken());
break;
default:
throw new \RuntimeException(sprintf('Authentication via "%s" is not supported by github', $this->authentication->getType()));
}
}
}
return $this->client;
}