Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Oct 10, 2023
1 parent 792c675 commit ce5e20b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
13 changes: 12 additions & 1 deletion src/Util/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,18 @@ public function getAppUri(?string $serverName = null): UriInterface
}
else
{
return $this->appUri = new Uri($this->getUri()->__toString(), $uriConfig);
$uri = $this->getUri();

if (isset($uriConfig['user']))
{
$userInfo = $uriConfig['user'] ?? '';
if (isset($uriConfig['pass']))
{
$userInfo .= ':' . $uriConfig['pass'];
}
}

return $this->appUri = Uri::makeUri($uriConfig['host'] ?? $uri->getHost(), $uriConfig['path'] ?? $uri->getPath(), $uriConfig['query'] ?? $uri->getQuery(), $uriConfig['port'] ?? $uri->getPort(), $uriConfig['scheme'] ?? $uri->getScheme(), $uriConfig['fragment'] ?? $uri->getFragment(), $userInfo ?? $uri->getUserInfo());
}
}
else
Expand Down
22 changes: 9 additions & 13 deletions src/Util/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Uri implements UriInterface, \Stringable
'ftp' => 21,
];

public function __construct(string $uri = '', array $params = [])
public function __construct(string $uri = '')
{
$isUnixSocket = str_starts_with($uri, 'unix:///');
if ($isUnixSocket)
Expand All @@ -70,22 +70,18 @@ public function __construct(string $uri = '', array $params = [])
$uriOption['host'] = "/{$uriOption['host']}{$uriOption['path']}";
$uriOption['path'] = '';
}
$this->scheme = $params['scheme'] ?? $uriOption['scheme'] ?? '';
$this->host = $params['host'] ?? $uriOption['host'] ?? '';
$this->port = $params['port'] ?? $uriOption['port'] ?? null;
$userInfo = $params['user'] ?? $uriOption['user'] ?? '';
if (isset($params['pass']))
{
$userInfo .= ':' . $params['pass'];
}
elseif (isset($uriOption['pass']))
$this->scheme = $uriOption['scheme'] ?? '';
$this->host = $uriOption['host'] ?? '';
$this->port = $uriOption['port'] ?? null;
$userInfo = $uriOption['user'] ?? '';
if (isset($uriOption['pass']))
{
$userInfo .= ':' . $uriOption['pass'];
}
$this->userInfo = $userInfo;
$this->path = $params['path'] ?? $uriOption['path'] ?? '';
$this->query = $params['query'] ?? $uriOption['query'] ?? '';
$this->fragment = $params['fragment'] ?? $uriOption['fragment'] ?? '';
$this->path = $uriOption['path'] ?? '';
$this->query = $uriOption['query'] ?? '';
$this->fragment = $uriOption['fragment'] ?? '';
}

/**
Expand Down

0 comments on commit ce5e20b

Please sign in to comment.