本文整理汇总了PHP中Guzzle\Http\ClientInterface::setBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::setBaseUrl方法的具体用法?PHP ClientInterface::setBaseUrl怎么用?PHP ClientInterface::setBaseUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::setBaseUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param \Guzzle\Http\ClientInterface $client A ClientInterface instance.
* @param string $owner The owner of the Github repository.
* @param string $repository The Github repository.
*/
public function __construct(ClientInterface $client, $owner, $repository)
{
$this->client = $client;
$this->owner = $owner;
$this->repository = $repository;
$this->client->setBaseUrl('https://api.github.com');
}
示例2: __construct
public function __construct(\Guzzle\Http\ClientInterface $client = null)
{
if (empty($client)) {
$client = new \Guzzle\Http\Client();
}
$this->client = $client;
$this->client->setBaseUrl('https://drupal.org/');
}
示例3: __construct
/**
* AmplitudeClient constructor.
*
* @param $apiKey
* @param ClientInterface $client
*/
public function __construct($apiKey, ClientInterface $client)
{
if (empty($apiKey)) {
throw new \InvalidArgumentException('Empty api key', 500);
}
$this->apiKey = $apiKey;
$this->client = $client;
$this->client->setBaseUrl(self::AMPLITUDE_URL);
}
示例4: __construct
/**
* @param string $clientId
* @param string $clientSecret
* @param string $redirectUri
* @param array $scopes
* @param ProviderInterface $provider
* @param ClientInterface $httpClient
*/
public function __construct($clientId, $clientSecret, $redirectUri, $scopes = [], ProviderInterface $provider = null, ClientInterface $httpClient = null)
{
if (is_null($provider)) {
$this->provider = new Base(['clientId' => $clientId, 'clientSecret' => $clientSecret, 'redirectUri' => $redirectUri, 'scopes' => $scopes]);
} else {
$this->provider = $provider;
}
if (is_null($httpClient)) {
$this->httpClient = new HttpClient();
} else {
$this->httpClient = $httpClient;
}
$this->httpClient->setBaseUrl(Base::BASE_URL);
}
示例5: __construct
/**
* @param array $configs
* @param ClientInterface $client
* @param LoggerInterface $logger
*/
protected function __construct(array $configs, ClientInterface $client = null, LoggerInterface $logger = null)
{
$configs = array_merge($this->getDefaultConfig(), $configs);
$this->setCredentials($configs);
$this->setDefaults();
if ($configs['auth_in_header']) {
$this->headers['Authorization'] = $this->getAuthHeader();
}
$this->logger = $logger ?: new NullLogger();
$this->client = $client ?: new Client();
$this->client->setBaseUrl($configs['base_url']);
$this->client->addSubscriber(new LogPlugin(new PsrLogAdapter($this->logger)));
$this->tokenRequestPath = $configs['token_request_path'];
}
示例6: send
/**
* @return Response
* @throws ConnectionErrorException
* @throws EmptyHostPoolException
* @throws ServerErrorException
*/
public function send()
{
$exception = null;
while ($this->hostPool->hasNext()) {
try {
$this->guzzleClient->setBaseUrl($this->hostPool->getNext());
/** @var GuzzleRequest $guzzleRequest */
$guzzleRequest = $this->guzzleClient->{$this->method}(array($this->url, $this->binds));
$guzzleRequest->addHeaders($this->headers);
if ($this->body && $guzzleRequest instanceof EntityEnclosingRequest) {
/** @var EntityEnclosingRequest $guzzleRequest */
$guzzleRequest->setBody($this->body);
}
$this->updateQueryParams($guzzleRequest);
return new Response($guzzleRequest->send());
} catch (ClientErrorResponseException $e) {
return new Response($e->getResponse());
} catch (ServerErrorResponseException $e) {
$exception = new ServerErrorException(new Response($e->getResponse()), $e->getMessage(), $e->getCode(), $e);
} catch (CurlException $e) {
$exception = new ConnectionErrorException($e->getMessage(), $e->getCode(), $e);
}
}
if ($exception == null) {
throw new EmptyHostPoolException(sprintf("Empty host pool: %s", $this->hostPool->getName()));
}
throw $exception;
}
示例7: __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)));
}
示例8: setBaseUrl
/**
* Set application hostname, optionally including a base URL, for purge and
* refresh requests
*
* @param string $url Your application’s base URL or hostname
*/
public function setBaseUrl($url)
{
if ($url) {
$url = $this->filterUrl($url);
}
$this->client->setBaseUrl($url);
}
示例9: call
/**
* Perform a cURL request based on a supplied path
*
* @param string $path
*
* @return array
*/
private function call($path)
{
$this->client->setBaseUrl(self::URL);
$request = $this->client->get($path);
$request->setHeader('Accept', 'application/json');
return $request->send()->json();
}
示例10: 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();
}
示例11: __construct
/**
* HttpClient constructor.
* @param $clientId
* @param $apiKey
* @param $apiSecret
* @param $endpoint
* @param ClientInterface $client
*/
public function __construct($clientId, $apiKey, $apiSecret, $endpoint, ClientInterface $client)
{
$this->authData = ['clientId' => $clientId, 'apiKey' => $apiKey, 'sha' => sha1($apiKey . $clientId . $apiSecret)];
$this->client = $client;
$this->client->setBaseUrl($endpoint);
}
示例12: __construct
/**
* Constructor.
*
* @param \Guzzle\Http\ClientInterface $client A ClientInterface instance.
*/
public function __construct(ClientInterface $client)
{
$this->client = $client;
$this->client->setBaseUrl('https://api.github.com');
}
示例13: setBaseUrl
/**
* {@inheritDoc}
*/
public function setBaseUrl($url)
{
$this->client->setBaseUrl($url);
return $this;
}
示例14: __construct
/**
* Constructor.
*
* @param \Guzzle\Http\ClientInterface $client A ClientInterface instance.
* @param string $folder The ID of the folder on Google Drive.
*/
public function __construct(ClientInterface $client, $folder = 'root')
{
$this->client = $client;
$this->folder = $folder;
$this->client->setBaseUrl('https://www.googleapis.com/upload/drive/v2');
}
示例15: setGuzzleClient
private function setGuzzleClient(GuzzleClientInterface $guzzleClient)
{
$guzzleClient->setBaseUrl('https://leanpub.com');
$this->guzzleClient = $guzzleClient;
}