本文整理汇总了PHP中Guzzle\Http\Client::getBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getBaseUrl方法的具体用法?PHP Client::getBaseUrl怎么用?PHP Client::getBaseUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::getBaseUrl方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: injectScript
/**
* Injects the livereload script.
*
* @param Response $response A Response instance
*/
protected function injectScript(Response $response)
{
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
$substrFunction = 'mb_substr';
} else {
$posrFunction = 'strripos';
$substrFunction = 'substr';
}
$content = $response->getContent();
$pos = $posrFunction($content, '</body>');
if (false !== $pos) {
$script = "livereload.js";
if ($this->checkServerPresence) {
// GET is required, as livereload apparently does not support HEAD requests ...
$request = $this->httpClient->get($script);
try {
$checkResponse = $this->httpClient->send($request);
if ($checkResponse->getStatusCode() !== 200) {
return;
}
} catch (CurlException $e) {
// If error is connection failed, we assume the server is not running
if ($e->getCurlHandle()->getErrorNo() === 7) {
return;
}
throw $e;
}
}
$content = $substrFunction($content, 0, $pos) . "\n" . '<script src="' . $this->httpClient->getBaseUrl() . $script . '"></script>' . "\n" . $substrFunction($content, $pos);
$response->setContent($content);
}
}
示例2: delete
/**
* @param string $id
*/
public function delete($id)
{
$url = $this->getConnectionUrl($id);
$request = $this->client->delete($this->client->getBaseUrl() . $url, $this->HEADERS);
$response = $request->send();
$this->statusCodeValidator->validate(200, $url, $request, $response);
}
示例3: findAll
/**
* @return Connection[]
*/
public function findAll()
{
$url = $this->getConnectionsUrl();
$request = $this->client->get($this->client->getBaseUrl() . $url);
$response = $request->send();
$this->statusCodeValidator->validate(200, $url, $request, $response);
return $this->mapJsonToConnectionDescriptors($response->getBody(true));
}
示例4: get
/**
* Get data
*
* @param string $request
*
* @return array
*/
protected function get($request)
{
$response = $this->client->get($this->prefix . $this->getLocale() . $request)->send();
if ($response->isError()) {
throw new \RuntimeException('Failed execute request "' . $request . '" to the server "' . $this->client->getBaseUrl() . '"');
}
return json_decode($response->getBody(true), true);
}
示例5: get
/**
* Get data from path.
*
* @param string $path
*
* @return array
*/
public function get($path)
{
$response = $this->client->get($this->api_prefix . $path)->send();
if ($response->isError()) {
throw new \RuntimeException('Failed to query the server ' . $this->client->getBaseUrl());
}
$body = json_decode($response->getBody(true), true);
if (json_last_error() !== JSON_ERROR_NONE || !is_array($body)) {
throw new \RuntimeException('Invalid response from the server ' . $this->client->getBaseUrl());
}
return $body;
}
示例6: getBaseUrl
public function getBaseUrl($expand = true)
{
$baseUrl = parent::getBaseUrl(false);
$url = $baseUrl;
if ($this->tokens instanceof AccessToken) {
$url .= strpos($url, '?') ? '&' : '?';
$url .= http_build_query(array('access_token' => $this->tokens->access_token));
}
$this->setBaseUrl($url);
$return = parent::getBaseUrl($expand);
$this->setBaseUrl($baseUrl);
return $return;
}
示例7: testCreatesRequestsWithDefaultValues
public function testCreatesRequestsWithDefaultValues()
{
$client = new Client($this->getServer()->getUrl() . 'base');
// Create a GET request
$request = $client->createRequest();
$this->assertEquals('GET', $request->getMethod());
$this->assertEquals($client->getBaseUrl(), $request->getUrl());
// Create a DELETE request
$request = $client->createRequest('DELETE');
$this->assertEquals('DELETE', $request->getMethod());
$this->assertEquals($client->getBaseUrl(), $request->getUrl());
// Create a HEAD request with custom headers
$request = $client->createRequest('HEAD', 'http://www.test.com/');
$this->assertEquals('HEAD', $request->getMethod());
$this->assertEquals('http://www.test.com/', $request->getUrl());
// Create a PUT request
$request = $client->createRequest('PUT');
$this->assertEquals('PUT', $request->getMethod());
// Create a PUT request with injected config
$client->getConfig()->set('a', 1)->set('b', 2);
$request = $client->createRequest('PUT', '/path/{a}?q={b}');
$this->assertEquals($request->getUrl(), $this->getServer()->getUrl() . 'path/1?q=2');
}
示例8: setBaseUrl
/**
* Overwrites the base URL defined in $client.
* You can restore the base URL by calling restoreBaseUrl().
*
* @param string $base_url
*/
protected function setBaseUrl($base_url)
{
$this->cachedBaseUrl = $this->client->getBaseUrl();
$base_url = rtrim($this->config->endpoint, '/') . '/' . ltrim($base_url, '/');
$this->client->setBaseUrl($base_url);
}
示例9: getBaseUri
public function getBaseUri()
{
return $this->client->getBaseUrl();
}
示例10: setLatence
private function setLatence(BaseClient $client)
{
$latenceClient = new BaseClient($client->getBaseUrl());
$response = $latenceClient->get('auth/time')->send();
$this->latence = time() - (int) $response->getBody(true);
}
示例11: setId
protected function setId($str)
{
$str = str_replace($this->curl->getBaseUrl() . $this->uri . '/', '', $str);
$str = str_replace('/commit', '', $str);
$this->id = $str;
}