本文整理汇总了PHP中GuzzleHttp\Psr7\Uri::resolve方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::resolve方法的具体用法?PHP Uri::resolve怎么用?PHP Uri::resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Psr7\Uri
的用法示例。
在下文中一共展示了Uri::resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getForm
public function getForm($formId, $params, $headers)
{
/** @var DOMElement $form */
$dom = new DomDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($this->response());
$xpath = new DOMXpath($dom);
$form = $xpath->query("//form[@id='{$formId}']")->item(0);
$elements = $xpath->query('//input');
$form_params = [];
$allowedTypes = ["hidden", "text", "password"];
foreach ($elements as $element) {
/** @var DOMElement $element */
$type = $element->getAttribute("type");
if (in_array($type, $allowedTypes)) {
$name = $element->getAttribute("name");
$value = $element->getAttribute("value");
$form_params[$name] = $value;
}
}
$headers = array_merge(["Referer" => $this->baseUri], $headers);
$url = Uri::resolve(new Uri($this->baseUri), $form->getAttribute("action"))->__toString();
$method = strtoupper($form->getAttribute("method"));
return ["method" => $method, "url" => $url, "headers" => $headers, "params" => array_merge($form_params, $params)];
}
示例2: convertUrlsToAbsolute
/**
* Convert relative links, images scr and form actions to absolute
*
* @param ElementFinder $page
* @param string $affectedUrl
*/
public static function convertUrlsToAbsolute(ElementFinder $page, $affectedUrl)
{
$affected = new Uri($affectedUrl);
$srcElements = $page->element('//*[@src] | //*[@href] | //form[@action]');
$baseUrl = $page->value('//base/@href')->getFirst();
foreach ($srcElements as $element) {
$attributeName = 'href';
if ($element->hasAttribute('action') === true and $element->tagName === 'form') {
$attributeName = 'action';
} else {
if ($element->hasAttribute('src') === true) {
$attributeName = 'src';
}
}
$relative = $element->getAttribute($attributeName);
# don`t change javascript in href
if (preg_match('!^\\s*javascript\\s*:\\s*!', $relative)) {
continue;
}
if (parse_url($relative) === false) {
continue;
}
if (!empty($baseUrl) and !preg_match('!^(/|http)!i', $relative)) {
$relative = Uri::resolve(new Uri($baseUrl), $relative);
}
$url = Uri::resolve($affected, (string) $relative);
$element->setAttribute($attributeName, (string) $url);
}
}
示例3: uriFor
/**
* @param string $filename
* @param string $version
*
* @return \Psr\Http\Message\UriInterface
*/
public function uriFor($filename, $version = '')
{
$filename = original_version($filename);
if ($version) {
$filename .= ":{$version}";
}
return Uri::resolve($this->baseUri, $filename);
}
示例4: request
/**
* @param $httpMethod
* @param $url
* @param $blueprint
* @param array $options
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function request($httpMethod, $url, $blueprint, $options = [])
{
$url = Uri::resolve($this->getBaseUrl(), $url);
$this->currentMethod = new ApistMethod($this->getGuzzle(), $url, $blueprint);
$this->lastMethod = $this->currentMethod;
$this->currentMethod->setMethod($httpMethod);
$result = $this->currentMethod->get($options);
$this->currentMethod = null;
return $result;
}
示例5: get
public function get($url, array $options = [], \Closure $processor = null)
{
$url = Psr7\Uri::resolve($this->baseUri, $url);
$response = $this->httpClient->get($url, $options);
if (null !== $processor) {
$response = $processor($response);
}
$crawler = new Crawler(null, (string) $url, (string) $this->baseUri);
$crawler->addContent($response->getBody());
return $crawler;
}
示例6: resolveLinkAttribute
/**
* @param string $attribute
* @param UriInterface $base
*/
private function resolveLinkAttribute($attribute, UriInterface $base)
{
$elements = $this->xpath->query("//*[@{$attribute} and not(contains(@{$attribute}, \"://\"))]");
foreach ($elements as $element) {
try {
$resolved = Uri::resolve($base, $element->getAttribute($attribute));
$element->setAttribute($attribute, $resolved->__toString());
} catch (InvalidArgumentException $e) {
// Tolerate invalid urls
}
}
}
示例7: queueUrl
/**
* Moves the URI of the queue to the URI in the input parameter.
*
* @return callable
*/
private function queueUrl()
{
return static function (callable $handler) {
return function (CommandInterface $c, RequestInterface $r = null) use($handler) {
if ($c->hasParam('QueueUrl')) {
$uri = Uri::resolve($r->getUri(), $c['QueueUrl']);
$r = $r->withUri($uri);
}
return $handler($c, $r);
};
};
}
示例8: signRequest
/**
* @param RequestInterface $request
* @param bool $forceNew
*
* @return RequestInterface
*/
public function signRequest(RequestInterface $request, $forceNew = false)
{
try {
// force-get a new token if it was requested, if not, the regular
// caching mechanism will be used so the call is not necessary here.
if (true === $forceNew) {
$this->pool->getToken($forceNew);
}
// create a new request with the new uri and the token added to the headers
$uri = Uri::resolve(new Uri($this->pool->getEndpointUrl()), $request->getUri());
return $request->withUri($uri)->withHeader('X-Auth-Token', $this->pool->getTokenId());
} catch (TokenException $e) {
throw new ClientException('Could not obtain token', $request, null, $e);
}
}
示例9: proxy
/**
* @param $endpoint
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
public function proxy($endpoint, ServerRequestInterface $request)
{
/** @var ClientInterface $client */
$client = $this->container->get('bangpound_guzzle_proxy.client.' . $endpoint);
$rel = $request->getAttribute('path');
if ($request->getQueryParams()) {
$rel .= '?' . \GuzzleHttp\Psr7\build_query($request->getQueryParams());
}
$rel = new Uri($rel);
$uri = $client->getConfig('base_url');
$uri = new Uri($uri);
$uri = Uri::resolve($uri, $rel);
$request = \GuzzleHttp\Psr7\modify_request($request, array('uri' => $uri));
$response = $client->send($request);
if ($response->hasHeader('Transfer-Encoding')) {
$response = $response->withoutHeader('Transfer-Encoding');
}
return $response;
}
示例10: get
public static function get($path, $query = [])
{
if (!isset(self::$guzzle)) {
self::initUsingConfigFile();
}
if (is_array($query)) {
$query = self::weedOut($query);
$query = http_build_query($query, null, '&', PHP_QUERY_RFC3986);
$query = preg_replace('/%5[bB]\\d+%5[dD]=/', '=', $query);
}
$response = self::$guzzle->get($path, ['query' => $query]);
switch ($response->getStatusCode()) {
case 200:
return json_decode($response->getBody(), true);
case 404:
return null;
default:
$uri = Psr7\Uri::resolve(Psr7\uri_for(self::$guzzle->getConfig('base_uri')), $path);
$uri = $uri->withQuery($query);
throw new ServerException($response->getStatusCode() . " " . $response->getReasonPhrase() . ". URI: " . $uri);
}
}
示例11: testResolvesUris
/**
* @dataProvider getResolveTestCases
*/
public function testResolvesUris($base, $rel, $expected)
{
$uri = new Uri($base);
$actual = Uri::resolve($uri, $rel);
$this->assertEquals($expected, (string) $actual);
}
示例12: buildUri
private function buildUri($uri, array $config)
{
// for BC we accept null which would otherwise fail in uri_for
$uri = Psr7\uri_for($uri === null ? '' : $uri);
if (isset($config['base_uri'])) {
$uri = Psr7\Uri::resolve(Psr7\uri_for($config['base_uri']), $uri);
}
return $uri->getScheme() === '' ? $uri->withScheme('http') : $uri;
}
示例13: buildUri
private function buildUri($uri, array $config)
{
if (!isset($config['base_uri'])) {
return $uri instanceof UriInterface ? $uri : new Psr7\Uri($uri);
}
return Psr7\Uri::resolve(Psr7\uri_for($config['base_uri']), $uri);
}
示例14: fixUri
private function fixUri(Step $step, $uri)
{
if (!$step->getEndpoint()) {
return $uri;
}
return Psr7\Uri::resolve(Psr7\uri_for($step->getEndpoint()), $uri);
}
示例15: createRequest
private function createRequest($uri)
{
$baseUri = \GuzzleHttp\Psr7\uri_for($this->client->getConfig('base_uri'));
$uri = Uri::resolve($baseUri, $uri);
return new Request('GET', $uri);
}