本文整理汇总了PHP中GuzzleHttp\Url::buildUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::buildUrl方法的具体用法?PHP Url::buildUrl怎么用?PHP Url::buildUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Url
的用法示例。
在下文中一共展示了Url::buildUrl方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromMessage
/**
* Create a request or response object from an HTTP message string
*
* @param string $message Message to parse
*
* @return RequestInterface|ResponseInterface
* @throws \InvalidArgumentException if unable to parse a message
*/
public function fromMessage($message)
{
static $parser;
if (!$parser) {
$parser = new MessageParser();
}
// Parse a response
if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
$data = $parser->parseResponse($message);
return $this->createResponse($data['code'], $data['headers'], $data['body'] === '' ? null : $data['body'], $data);
}
// Parse a request
if (!($data = $parser->parseRequest($message))) {
throw new \InvalidArgumentException('Unable to parse request');
}
return $this->createRequest($data['method'], Url::buildUrl($data['request_url']), ['headers' => $data['headers'], 'body' => $data['body'] === '' ? null : $data['body'], 'config' => ['protocol_version' => $data['protocol_version']]]);
}
示例2: getAbsoluteUri
public function getAbsoluteUri($uri)
{
$build = parse_url($this->baseUri);
$uriparts = parse_url(preg_replace('~^/+(?=/)~', '', $uri));
if ($build === false) {
throw new \Codeception\Exception\TestRuntime("URL '{$this->baseUri}' is malformed");
} elseif ($uriparts === false) {
throw new \Codeception\Exception\TestRuntime("URI '{$uri}' is malformed");
}
foreach ($uriparts as $part => $value) {
if ($part === 'path' && strpos($value, '/') !== 0 && !empty($build[$part])) {
$build[$part] = rtrim($build[$part], '/') . '/' . $value;
} else {
$build[$part] = $value;
}
}
return \GuzzleHttp\Url::buildUrl($build);
}
示例3: getAbsoluteUrlFor
/**
* Returns an absolute URL for the passed URI with the current URL
* as the base path.
*
* @param string $uri the absolute or relative URI
* @return string the absolute URL
* @throws Codeception\Exception\TestRuntime if either the current
* URL or the passed URI can't be parsed
*/
protected function getAbsoluteUrlFor($uri)
{
$currentUrl = $this->client->getHistory()->current()->getUri();
if (empty($uri) || $uri === '#') {
return $currentUrl;
}
$build = parse_url($currentUrl);
$uriParts = parse_url($uri);
if ($build === false) {
throw new TestRuntime("URL '{$currentUrl}' is malformed");
} elseif ($uriParts === false) {
throw new TestRuntime("URI '{$uri}' is malformed");
}
$abs = $this->mergeUrls($build, $uriParts);
return \GuzzleHttp\Url::buildUrl($abs);
}
示例4: testAddsQueryIfPresent
public function testAddsQueryIfPresent()
{
$this->assertEquals('?foo=bar', Url::buildUrl(array('query' => 'foo=bar')));
}
示例5: getAbsoluteUri
public function getAbsoluteUri($uri)
{
if ($uri && 0 !== strpos($uri, 'http') && $uri[0] !== '/' && $this->redirect) {
$currentUri = $this->history->current()->getUri();
$path = parse_url($currentUri, PHP_URL_PATH);
if ('/' !== substr($path, -1)) {
$path = substr($path, 0, strrpos($path, '/') + 1);
}
$uri = $path . $uri;
}
$build = parse_url($this->baseUri);
$uriParts = parse_url(preg_replace('~^/+(?=/)~', '', $uri));
if ($build === false) {
throw new TestRuntimeException("URL '{$this->baseUri}' is malformed");
} elseif ($uriParts === false) {
throw new TestRuntimeException("URI '{$uri}' is malformed");
}
foreach ($uriParts as $part => $value) {
if ($part === 'path' && strpos($value, '/') !== 0 && !empty($build[$part])) {
$build[$part] = rtrim($build[$part], '/') . '/' . $value;
} else {
$build[$part] = $value;
}
}
return \GuzzleHttp\Url::buildUrl($build);
}
示例6: getFormUrl
/**
* @param \Symfony\Component\DomCrawler\Crawler $form
*
* @return string
*/
protected function getFormUrl($form)
{
$action = $form->attr('action');
$currentUrl = $this->client->getHistory()->current()->getUri();
if (empty($action) || $action === '#') {
return $currentUrl;
}
$build = parse_url($currentUrl);
if ($build === false) {
throw new TestRuntime("URL '{$currentUrl}' is malformed");
}
$uriParts = parse_url($action);
if ($uriParts === false) {
throw new TestRuntime("URI '{$action}' is malformed");
}
foreach ($uriParts as $part => $value) {
if ($part === 'path' && strpos($value, '/') !== 0 && !empty($build[$part])) {
// if it ends with a slash, relative paths are below it
if (preg_match('~/$~', $build[$part])) {
$build[$part] = $build[$part] . $value;
continue;
}
$build[$part] = dirname($build[$part]) . '/' . $value;
continue;
}
$build[$part] = $value;
}
return \GuzzleHttp\Url::buildUrl($build);
}
示例7: transformToUploadUrl
private function transformToUploadUrl()
{
$parts = parse_url($this->request->getUrl());
if (!isset($parts['path'])) {
$parts['path'] = '';
}
$parts['path'] = '/upload' . $parts['path'];
$url = Url::fromString(Url::buildUrl($parts));
$this->request->setUrl($url);
}
示例8: setUrlHelper
/**
* Set base parameters of homepage url.
*
* @param string $homepage satis repository url
*/
private function setUrlHelper($homepage)
{
$parsedUrl = Url::fromString($homepage)->getParts();
if (isset($parsedUrl['user']) && isset($parsedUrl['pass'])) {
$this->credentials = array('auth' => array($parsedUrl['user'], $parsedUrl['pass']));
}
if (isset($parsedUrl['path'])) {
$this->basePath = $parsedUrl['path'];
$this->basePath .= substr($this->basePath, -1) == '/' ? '' : '/';
}
$this->baseUrl = Url::buildUrl(array('scheme' => $parsedUrl['scheme'], 'host' => $parsedUrl['host'], 'port' => $parsedUrl['port']));
return $this;
}
示例9: coerceUri
private function coerceUri($uri)
{
if (is_null($uri)) {
return null;
} else {
if (is_string($uri)) {
return Url::fromString($uri);
} else {
if (is_array($uri)) {
return Url::buildUrl($uri);
} else {
if (get_class($uri) == 'GuzzleHttp\\Url') {
return $uri;
} else {
throw new \InvalidArgumentException('unexpected type for a uri: ' . get_class($uri));
}
}
}
}
}
示例10: amOnPage
public function amOnPage($page)
{
$build = parse_url($this->config['url']);
$uriparts = parse_url($page);
if ($build === false) {
throw new \Codeception\Exception\TestRuntime("URL '{$this->config['url']}' is malformed");
} elseif ($uriparts === false) {
throw new \Codeception\Exception\TestRuntime("URI '{$page}' is malformed");
}
foreach ($uriparts as $part => $value) {
if ($part === 'path' && !empty($build[$part])) {
$build[$part] = rtrim($build[$part], '/') . '/' . ltrim($value, '/');
} else {
$build[$part] = $value;
}
}
$this->webDriver->get(\GuzzleHttp\Url::buildUrl($build));
}