本文整理汇总了PHP中Guzzle\Http\Client::setConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setConfig方法的具体用法?PHP Client::setConfig怎么用?PHP Client::setConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::setConfig方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lookupAddress
/**
* @param string $postalCode
* @param string $houseNumber
* @return array
*/
public function lookupAddress($postalCode, $houseNumber)
{
$this->client->setConfig(['curl.options' => ['CURLOPT_CONNECTTIMEOUT_MS' => '2000', 'CURLOPT_RETURNTRANSFER' => true]]);
$url = sprintf($this->baseUrl . '/%s/%s', $postalCode, $houseNumber);
$request = $this->client->get($url)->setAuth($this->apiKey, $this->apiSecret);
return $request->send()->json();
}
示例2: accessTokenRequest
/**
*
* @param array $p
* @return bool|TokenResponse
*/
protected function accessTokenRequest(array $p)
{
$this->c->setConfig(array(\Guzzle\Http\Client::REQUEST_OPTIONS => array('allow_redirects' => false, 'exceptions' => false, 'verify' => false)));
if ($this->clientConfig->getCredentialsInRequestBody()) {
// provide credentials in the POST body
$p['client_id'] = $this->clientConfig->getClientId();
$p['client_secret'] = $this->clientConfig->getClientSecret();
} else {
// use basic authentication
$curlAuth = new \Guzzle\Plugin\CurlAuth\CurlAuthPlugin($this->clientConfig->getClientId(), $this->clientConfig->getClientSecret());
$this->c->addSubscriber($curlAuth);
}
try {
$request = $this->c->post($this->clientConfig->getTokenEndpoint());
$request->addPostFields($p);
$request->addHeader('Accept', 'application/json');
$responseData = $request->send()->json();
// some servers do not provide token_type, so we allow for setting
// a default
// issue: https://github.com/fkooman/php-oauth-client/issues/13
if (null !== $this->clientConfig->getDefaultTokenType()) {
if (is_array($responseData) && !isset($responseData['token_type'])) {
$responseData['token_type'] = $this->clientConfig->getDefaultTokenType();
}
}
// if the field "expires_in" has the value null, remove it
// issue: https://github.com/fkooman/php-oauth-client/issues/17
if ($this->clientConfig->getAllowNullExpiresIn()) {
if (is_array($responseData) && array_key_exists("expires_in", $responseData)) {
if (null === $responseData['expires_in']) {
unset($responseData['expires_in']);
}
}
}
// if the field "scope" is empty string a default can be set
// through the client configuration
// issue: https://github.com/fkooman/php-oauth-client/issues/20
if (null !== $this->clientConfig->getDefaultServerScope()) {
if (is_array($responseData) && isset($responseData['scope']) && '' === $responseData['scope']) {
$responseData['scope'] = $this->clientConfig->getDefaultServerScope();
}
}
return new TokenResponse($responseData);
} catch (\Guzzle\Common\Exception\RuntimeException $e) {
return false;
}
}
示例3: testAllowsConfigsToBeChangedAndInjectedInBaseUrl
public function testAllowsConfigsToBeChangedAndInjectedInBaseUrl()
{
$client = new Client('http://{a}/{b}');
$this->assertEquals('http:///', $client->getBaseUrl());
$this->assertEquals('http://{a}/{b}', $client->getBaseUrl(false));
$client->setConfig(array('a' => 'test.com', 'b' => 'index.html'));
$this->assertEquals('http://test.com/index.html', $client->getBaseUrl());
}
示例4: sendRequest
/**
* Makes http request to remote host.
*
* @param string $url
* @param mixed $data
* @param array $options
*
* @throws \ErrorException|\Exception
* @return mixed
*/
protected function sendRequest($url, $data, $options = null)
{
$client = new HttpClient();
$client->setConfig(array('curl.options' => array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false)));
$request = $client->post($url, null, $data);
try {
return $request->send()->getBody();
} catch (RequestException $e) {
throw new CommunicationError('Communication failed: ' . $url);
}
}
示例5: setGuzzleConfig
/**
* @param array|\Guzzle\Common\Collection $config
* @return Client $this
*/
public function setGuzzleConfig($config)
{
$this->client->setConfig($config);
return $this;
}
示例6: DatabaseConfiguration
$configuration['database'] = $processor->processConfiguration(new DatabaseConfiguration(), array($database));
$configuration['mailer'] = $processor->processConfiguration(new MailerConfiguration(), array($mailer));
$configuration['leboncoin'] = $processor->processConfiguration(new LeboncoinConfiguration(), array($leboncoin));
return $configuration;
};
$app['db'] = function ($app) {
$config = $app['configuration']['database']['connection'];
if (isset($config['path'])) {
$config['path'] = substr($config['path'], 0, 1) == '/' ? $config['path'] : __DIR__ . '/../' . $config['path'];
}
return DriverManager::getConnection($config, new Configuration());
};
$app['guzzle'] = function ($app) {
$guzzle = new GuzzleClient($app['configuration']['leboncoin']['url']);
if (null !== ($proxy = $app['configuration']['leboncoin']['proxy'])) {
$guzzle->setConfig(array('request.options' => array('proxy' => $proxy)));
}
return $guzzle;
};
$app['client'] = function ($app) {
return new LeboncoinClient($app['guzzle']);
};
$app['bid.manager'] = function ($app) {
return new BidManager($app['db']);
};
$app['alert.manager'] = function ($app) {
return new AlertManager($app['db']);
};
$app['twig'] = function ($app) {
$loader = new \Twig_Loader_Filesystem(__DIR__ . '/../templates');
return new \Twig_Environment($loader);
示例7: getClient
/**
* Instantiate a Guzzle HTTP client object
*
* @return Client
*/
public function getClient()
{
if (is_null($this->client)) {
$this->client = new Client(sprintf('%s://%s', Config::GRAPH_USE_SSL === true ? 'https' : 'http', Config::GRAPH_BASE_URL));
$this->client->setConfig(array('exceptions' => true));
}
return $this->client;
}
示例8: setTimeout
/**
* {@inheritdoc}
*/
public function setTimeout($timeout)
{
$guzzleConfig = array(Client::CURL_OPTIONS => array(CURLOPT_TIMEOUT => $timeout, CURLOPT_CONNECTTIMEOUT => $timeout));
$this->client->setConfig($guzzleConfig);
}
示例9: __construct
/**
*
*/
public function __construct()
{
$this->guzzleClient = new Guzzle\Http\Client(static::$baseUrl);
$this->guzzleClient->setConfig(array('defaults' => array('headers' => array('Content-Type' => 'application/json', 'Authorization' => sprintf('Bearer %s', $this->accessToken)))));
}