本文整理汇总了PHP中Psr\Http\Message\UriInterface::getUserInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::getUserInfo方法的具体用法?PHP UriInterface::getUserInfo怎么用?PHP UriInterface::getUserInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::getUserInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: withUri
/**
* Returns an instance with the provided URI.
*
* This method MUST update the Host header of the returned request by
* default if the URI contains a host component. If the URI does not
* contain a host component, any pre-existing Host header MUST be carried
* over to the returned request.
*
* You can opt-in to preserving the original state of the Host header by
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
* `true`, this method interacts with the Host header in the following ways:
*
* - If the the Host header is missing or empty, and the new URI contains
* a host component, this method MUST update the Host header in the returned
* request.
* - If the Host header is missing or empty, and the new URI does not contain a
* host component, this method MUST NOT update the Host header in the returned
* request.
* - If a Host header is present and non-empty, this method MUST NOT update
* the Host header in the returned request.
*
* @link http://tools.ietf.org/html/rfc3986#section-4.3
*
* @param UriInterface $uri New request URI to use.
* @param bool $preserveHost Preserve the original state of the Host header.
* @return self
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$request = clone $this;
$request->scheme($uri->getScheme());
$userInfo = $uri->getUserInfo();
$parts = explode(':', $userInfo);
$request->username($parts[0] ?: null);
$request->password(!empty($parts[1]) ? $parts[1] : null);
$request->port($uri->getPort());
if ($preserveHost) {
$host = $request->headers['Host'];
$request->host($uri->getHost());
$request->headers['Host'] = $host;
} else {
$request->host($uri->getHost());
}
$request->path($uri->getPath());
$request->query($uri->getQuery());
$request->fragment($uri->getFragment());
return $request;
}
示例2: runMatches
protected function runMatches(UriInterface $uri)
{
return $uri->getUserInfo() == $this->expected;
}
示例3: 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;
}
示例4: 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)));
}