本文整理汇总了PHP中Psr\Http\Message\UriInterface::withUserInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::withUserInfo方法的具体用法?PHP UriInterface::withUserInfo怎么用?PHP UriInterface::withUserInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::withUserInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: absoluteURIFor
/**
* Get the absolute URL for a given route name.
* You must provide the current request Uri to retrieve the scheme and host.
*
* @param UriInterface $uri
* @param string $route
* @param array $params
* @param array $query
*
* @return string
*/
public function absoluteURIFor(UriInterface $uri, $route, array $params = [], array $query = [])
{
$path = $this->uriFor($route, $params);
return (string) $uri->withUserInfo('')->withPath($path)->withQuery(http_build_query($query))->withFragment('');
}
示例2: obfuscateUri
/**
* Obfuscates URI if there is an username and a password present
*
* @param UriInterface $uri
*
* @return UriInterface
*/
private static function obfuscateUri($uri)
{
$userInfo = $uri->getUserInfo();
if (false !== ($pos = strpos($userInfo, ':'))) {
return $uri->withUserInfo(substr($userInfo, 0, $pos), '***');
}
return $uri;
}
示例3: buildRequest
private function buildRequest(Command $command, UriInterface $uri) : RequestInterface
{
$parameters = sprintf('-db=%s&%s', urlencode($this->database), $command);
$body = new Stream('php://temp', 'wb+');
$body->write($parameters);
$body->rewind();
$request = (new Request($uri->withUserInfo(''), 'POST'))->withAddedHeader('User-agent', 'SimpleFM')->withAddedHeader('Content-type', 'application/x-www-form-urlencoded')->withAddedHeader('Content-length', (string) strlen($parameters))->withBody($body);
$credentials = urldecode($uri->getUserInfo());
if ($command->hasIdentity()) {
Assertion::notNull($this->identityHandler, 'An identity handler must be set to use identities on commands');
$identity = $command->getIdentity();
$credentials = sprintf('%s:%s', $identity->getUsername(), $this->identityHandler->decryptPassword($identity));
}
$this->logger->info(sprintf('%s?%s', (string) $uri->withUserInfo(''), $parameters));
if ('' === $credentials) {
return $request;
}
return $request->withAddedHeader('Authorization', sprintf('Basic %s', base64_encode($credentials)));
}