本文整理汇总了PHP中GuzzleHttp\Client::getDefaultOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getDefaultOption方法的具体用法?PHP Client::getDefaultOption怎么用?PHP Client::getDefaultOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Client
的用法示例。
在下文中一共展示了Client::getDefaultOption方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getClient
/**
* Get a configured client, creating one if one hasn't been set by
* setClient().
*
* @return Client
*/
public function getClient()
{
if (!$this->client) {
$this->client = new Client();
$headers = $this->client->getDefaultOption('headers');
$headers['User-Agent'] = 'PkpPlnBot 1.0; http://pkp.sfu.ca';
$this->client->setDefaultOption('headers', $headers);
}
return $this->client;
}
示例2: wait
/**
* Wait for a container to finish
*
* @param \Docker\Container $container
* @param integer|null $timeout
*
* @throws \Docker\Exception\UnexpectedStatusCodeException
*
* @return \Docker\Manager\ContainerManager
*/
public function wait(Container $container, $timeout = null)
{
$response = $this->client->post(['/containers/{id}/wait', ['id' => $container->getId()]], ['timeout' => null === $timeout ? $this->client->getDefaultOption('timeout') : $timeout]);
if ($response->getStatusCode() !== "200") {
throw UnexpectedStatusCodeException::fromResponse($response);
}
$container->setExitCode($response->json()['StatusCode']);
$this->inspect($container);
return $this;
}
示例3: testAuthenticateClient
/**
* @param array $credentials
* @dataProvider credentialsProvider
*/
public function testAuthenticateClient($credentials)
{
$client = new Client();
$auth = new Basic($credentials);
$auth->authenticateClient(new RestClient($client));
self::assertEquals(['test', 'pass'], $client->getDefaultOption('auth'));
$request = $client->createRequest('GET', '/');
self::assertArrayHasKey('Authorization', $request->getHeaders());
self::assertEquals(['Basic dGVzdDpwYXNz'], $request->getHeaders()['Authorization']);
}
示例4: request
/**
* @param $capability
* @param array $options
* @throws Exceptions\CapabilityUnavailable
* @throws Exceptions\RETSException
* @return \GuzzleHttp\Message\ResponseInterface
*/
protected function request($capability, $options = [])
{
$url = $this->capabilities->get($capability);
if (!$url) {
throw new CapabilityUnavailable("'{$capability}' tried but no valid endpoint was found. Did you forget to Login()?");
}
if (!array_key_exists('headers', $options)) {
$options['headers'] = [];
}
// Guzzle 5 changed the order that headers are added to the request, so we'll do this manually
$options['headers'] = array_merge($this->client->getDefaultOption('headers'), $options['headers']);
// user-agent authentication
if ($this->configuration->getUserAgentPassword()) {
$ua_digest = $this->configuration->userAgentDigestHash($this);
$options['headers'] = array_merge($options['headers'], ['RETS-UA-Authorization' => 'Digest ' . $ua_digest]);
}
$options = array_merge($options, ['cookies' => $this->cookie_jar]);
$this->debug("Sending HTTP Request for {$url} ({$capability})", $options);
if (array_key_exists('query', $options)) {
$this->last_request_url = $url . '?' . \http_build_query($options['query']);
} else {
$this->last_request_url = $url;
}
/** @var \GuzzleHttp\Message\ResponseInterface $response */
if ($this->configuration->readOption('use_post_method')) {
$this->debug('Using POST method per use_post_method option');
$query = array_key_exists('query', $options) ? $options['query'] : null;
$response = $this->client->post($url, array_merge($options, ['body' => $query]));
} else {
$response = $this->client->get($url, $options);
}
$this->last_response = $response;
$cookie = $response->getHeader('Set-Cookie');
if ($cookie) {
if (preg_match('/RETS-Session-ID\\=(.*?)(\\;|\\s+|$)/', $cookie, $matches)) {
$this->rets_session_id = $matches[1];
}
}
if ($response->getHeader('Content-Type') == 'text/xml' and $capability != 'GetObject') {
$xml = $response->xml();
if ($xml and isset($xml['ReplyCode'])) {
$rc = (string) $xml['ReplyCode'];
// 20201 - No records found - not exception worthy in my mind
if ($rc != "0" and $rc != "20201") {
throw new RETSException($xml['ReplyText'], (int) $xml['ReplyCode']);
}
}
}
$this->debug('Response: HTTP ' . $response->getStatusCode());
return $response;
}
示例5: testAuthenticateClient
public function testAuthenticateClient()
{
$client = new Client();
$restClient = new RestClient($client);
$auth = new OAuth10(['oauth_api' => ['credentials' => ['#data' => '{"oauth_token": "token", "oauth_token_secret": "token_secret"}', 'appKey' => 'aaa', '#appSecret' => 'bbb']]]);
$auth->authenticateClient($restClient);
self::assertEquals('oauth', $client->getDefaultOption('auth'));
$request = $restClient->createRequest(['endpoint' => '/']);
$mock = new Mock([new Response(200, [], Stream::factory('{}'))]);
$client->getEmitter()->attach($mock);
$history = new History();
$client->getEmitter()->attach($history);
$restClient->download($request);
$authHeader = $history->getLastRequest()->getHeaders()['Authorization'][0];
self::assertRegexp('/^OAuth oauth_consumer_key="aaa", oauth_nonce="([0-9a-zA-Z]*)", oauth_signature="([0-9a-zA-Z%]*)", oauth_signature_method="HMAC-SHA1", oauth_timestamp="([0-9]{10})", oauth_token="token", oauth_version="1.0"$/', $authHeader);
}
示例6: testUsesProxyEnvironmentVariables
public function testUsesProxyEnvironmentVariables()
{
$client = new Client();
$this->assertNull($client->getDefaultOption('proxy'));
putenv('HTTP_PROXY=127.0.0.1');
$client = new Client();
$this->assertEquals(['http' => '127.0.0.1'], $client->getDefaultOption('proxy'));
putenv('HTTPS_PROXY=127.0.0.2');
$client = new Client();
$this->assertEquals(['http' => '127.0.0.1', 'https' => '127.0.0.2'], $client->getDefaultOption('proxy'));
putenv('HTTP_PROXY=');
putenv('HTTPS_PROXY=');
}
示例7: removeToken
/**
* Remove the token for the given user in storage.
*
* @return void
*/
public function removeToken()
{
$this->client->getDefaultOption('cookies')->clear();
}
示例8: getRequestOption
/**
* Returns the specified request option or all options if none specified.
*
* @param null $keyOrPath
*
* @return array|mixed|null
*/
public function getRequestOption($keyOrPath = null)
{
return $this->guzzleClient->getDefaultOption($keyOrPath);
}
示例9: testUsesProxyEnvironmentVariables
public function testUsesProxyEnvironmentVariables()
{
$http = isset($_SERVER['HTTP_PROXY']) ? $_SERVER['HTTP_PROXY'] : null;
$https = isset($_SERVER['HTTPS_PROXY']) ? $_SERVER['HTTPS_PROXY'] : null;
unset($_SERVER['HTTP_PROXY']);
unset($_SERVER['HTTPS_PROXY']);
$client = new Client();
$this->assertNull($client->getDefaultOption('proxy'));
$_SERVER['HTTP_PROXY'] = '127.0.0.1';
$client = new Client();
$this->assertEquals(['http' => '127.0.0.1'], $client->getDefaultOption('proxy'));
$_SERVER['HTTPS_PROXY'] = '127.0.0.2';
$client = new Client();
$this->assertEquals(['http' => '127.0.0.1', 'https' => '127.0.0.2'], $client->getDefaultOption('proxy'));
$_SERVER['HTTP_PROXY'] = $http;
$_SERVER['HTTPS_PROXY'] = $https;
}
示例10: getDefaultOptions
public function getDefaultOptions()
{
return $this->client->getDefaultOption();
}
示例11: copyClientDefaults
/**
* @param Client $client
*/
protected function copyClientDefaults(Client $client)
{
$this->request->setUrl($client->getBaseUrl() . $this->request->getUrl());
$this->request->addHeaders($client->getDefaultOption('headers'));
}
示例12: prepareQuery
/**
* Prepares the query with the default parameters
*
* @param array $options
*
* @return array
*/
private function prepareQuery($options = [])
{
return array_merge($this->client->getDefaultOption('query'), $options);
}
示例13: testAuthHeaderSet
public function testAuthHeaderSet()
{
$api = new API('1234', '4321', $this->client);
$headers = $this->client->getDefaultOption('headers');
$this->assertEquals('Bearer 1234 4321', $headers['Auth']);
}