本文整理汇总了PHP中GuzzleHttp\ClientInterface::setDefaultOption方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::setDefaultOption方法的具体用法?PHP ClientInterface::setDefaultOption怎么用?PHP ClientInterface::setDefaultOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::setDefaultOption方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param ClientInterface $client The HTTP client.
* @param string $accessToken The Strava API access token.
* @param SportMapperInterface $sportMapper The sport mapper.
*/
public function __construct(ClientInterface $client, $accessToken, SportMapperInterface $sportMapper)
{
$this->httpClient = $client;
$this->accessToken = $accessToken;
$this->sportMapper = $sportMapper;
$this->httpClient->setDefaultOption('headers/Authorization', 'Bearer ' . $this->accessToken);
}
示例2: __construct
/**
* Constructor.
*
* @param GuzzleClientInterface $client
* @param SerializerInterface $serializer
* @param string $apiKey
*/
public function __construct(GuzzleClientInterface $client, SerializerInterface $serializer, $apiKey)
{
$this->apiKey = $apiKey;
$this->client = $client;
$this->serializer = $serializer;
$this->client->setDefaultOption('headers/User-Agent', 'Helthe-Mandrill/' . self::VERSION);
}
示例3: prepareClient
/**
* @param ClientInterface $client
* @param string $apiKey
*
* @return HTTPClient
*/
private function prepareClient(ClientInterface $client, $apiKey)
{
if ($client->getDefaultOption('timeout') === null) {
$client->setDefaultOption('timeout', 5.0);
}
$client->setDefaultOption('headers/X-Api-Key', $apiKey);
return $client;
}
示例4: __construct
/**
* Constructor
*
* @param string $token Access Token
* @param ClientInterface|null $client Client Instance
*/
public function __construct($token, ClientInterface $client = null)
{
if (version_compare(ClientInterface::VERSION, '6') === 1) {
$this->client = $client ?: new Client(['headers' => ['access_token' => $token]]);
} else {
$this->client = $client ?: new Client();
$this->client->setDefaultOption('headers/access_token', $token);
}
}
示例5: __construct
/**
* @param string $token
* @param ClientInterface|null $client
*/
public function __construct($token, ClientInterface $client = null)
{
if (version_compare(ClientInterface::VERSION, '6') === 1) {
$this->client = $client ?: new Client(['headers' => ['Authorization' => sprintf('Bearer %s', $token)]]);
} else {
$this->client = $client ?: new Client();
$this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $token));
}
}
示例6: __construct
/**
* @param string $accessToken
* @param ClientInterface $client (optional)
* @param ExceptionInterface $exception (optional)
*/
public function __construct($accessToken, ClientInterface $client = null, ExceptionInterface $exception = null)
{
$that = $this;
$this->client = $client ?: new \GuzzleHttp\Client();
$this->exception = $exception;
$this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $accessToken));
$this->client->getEmitter()->on('complete', function (CompleteEvent $e) use($that) {
$that->handleResponse($e);
$e->stopPropagation();
});
}
示例7: attachKey
public function attachKey(ClientInterface $http, $key)
{
$subscriber = new SimpleSubscriber(['key' => $key]);
$http->setDefaultOption('auth', 'simple');
$http->getEmitter()->attach($subscriber);
return $http;
}
示例8: setAuthMethod
/**
* Changes the authentication method on all the requests made by this client
* @param \Snorlax\Auth\Authorization $auth The authorizaztion method
*/
public function setAuthMethod(Authorization $auth)
{
$this->client->setDefaultOption('headers', ['Authorization' => sprintf('%s %s', $auth->getAuthType(), $auth->getCredentials())]);
}
示例9: __construct
public function __construct(ClientInterface $client)
{
$client->setDefaultOption('headers/Accept', 'application/json');
$this->http = $client;
}
示例10: __construct
/**
* Instantiate class with minimal fields to be make valid request
*
* @param ClientInterface $client
*/
public function __construct(ClientInterface $client)
{
$this->client = $client;
$this->client->setDefaultOption('headers/User-Agent', 'caseyw/ziprecruiter-php');
}
示例11: debug
/**
* Prettyprints output and uses ClientInterface debugger
*
* @author Eelke van den Bos <eelkevdbos@gmail.com>
*/
public function debug()
{
$this->setOption('prettyprint', 1);
$this->client->setDefaultOption('debug', true);
}