本文整理汇总了PHP中Guzzle\Http\ClientInterface::setConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::setConfig方法的具体用法?PHP ClientInterface::setConfig怎么用?PHP ClientInterface::setConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::setConfig方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param ClientInterface $httpClient
* @param array $options
* @param LoggerInterface $logger
*/
public function __construct(ClientInterface $httpClient, array $options, LoggerInterface $logger = null)
{
$this->httpClient = $httpClient;
$scheme = isset($options['scheme']) ? $options['scheme'] : static::DEFAULT_SCHEME;
$host = isset($options['host']) ? $options['host'] : static::DEFAULT_HOST;
$port = isset($options['port']) ? $options['port'] : static::DEFAULT_PORT;
$pathPrefix = isset($options['path_prefix']) ? $options['path_prefix'] : static::DEFAULT_PATH_PREFIX;
$accessKey = isset($options['access_key']) ? $options['access_key'] : null;
$secretKey = isset($options['secret_key']) ? $options['secret_key'] : null;
$this->scheme = $scheme;
$this->host = $host;
$this->port = $port;
$this->pathPrefix = $pathPrefix;
$this->accessKey = $accessKey;
$this->secretKey = $secretKey;
$this->companyName = isset($options['company']) ? $options['company'] : null;
$this->collectionName = isset($options['collection']) ? $options['collection'] : null;
$this->options = $options;
$this->logger = $logger;
$exceptionFactory = new NamespaceExceptionFactory(new EngineExceptionParser(), 'Sajari\\Engine\\Exception', 'Sajari\\Engine\\Exception\\EngineException');
$this->httpClient->addSubscriber(new StatusCodeListener());
$this->httpClient->addSubscriber(new ExceptionListener($exceptionFactory));
$connectTimeout = 10;
$timeout = 10;
if (isset($this->options['curl.options']['CURLOPT_CONNECTTIMEOUT'])) {
$connectTimeout = (int) $this->options['curl.options']['CURLOPT_CONNECTTIMEOUT'];
}
if (isset($this->options['curl.options']['CURLOPT_TIMEOUT'])) {
$timeout = (int) $this->options['curl.options']['CURLOPT_TIMEOUT'];
}
$this->httpClient->setBaseUrl(sprintf('%s://%s', $this->scheme, $this->host));
$this->httpClient->setConfig(array(HttpClient::SSL_CERT_AUTHORITY => false, HttpClient::CURL_OPTIONS => array(CURLOPT_CONNECTTIMEOUT => $connectTimeout, CURLOPT_TIMEOUT => $timeout)));
}
示例2: call
/**
* Perform an HTTP request on MusicBrainz
*
* @param string $path
* @param array $params
* @param string $options
* @param boolean $isAuthRequred
* @return array
*/
public function call($path, array $params = array(), array $options = array(), $isAuthRequred = false)
{
if ($options['user-agent'] == '') {
throw new Exception('You must set a valid User Agent before accessing the MusicBrainz API');
}
$this->client->setBaseUrl(MbClient::URL);
$this->client->setConfig(array('data' => $params));
$request = $this->client->get($path . '{?data*}');
$request->setHeader('Accept', 'application/json');
$request->setHeader('User-Agent', $options['user-agent']);
if ($isAuthRequred) {
if ($options['user'] != null && $options['password'] != null) {
$request->setAuth($options['user'], $options['password'], CURLAUTH_DIGEST);
} else {
throw new Exception('Authentication is required');
}
}
$request->getQuery()->useUrlEncoding(false);
return $request->send()->json();
}