Skip to content

Commit 3ab2ad3

Browse files
author
Wazabii
committed
Patch
Fix URI host, authority and path method
1 parent eacba51 commit 3ab2ad3

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Env.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Env
1313
private $data = array();
1414
private $set = array();
1515
private $drop = array();
16-
//private $readOnly = false;
1716

1817
public function __construct(?string $file = null)
1918
{
@@ -22,7 +21,6 @@ public function __construct(?string $file = null)
2221
}
2322
}
2423

25-
2624
public function loadEnvFile(string $file): void
2725
{
2826
$this->fileData = parse_ini_file($file);
@@ -122,10 +120,12 @@ public function putenvArray(array $array): self
122120
private function put(array $data, bool $overwrite = false)
123121
{
124122
foreach ($data as $key => $value) {
123+
/*
125124
if (!$overwrite && getenv($key) !== false) {
126125
throw new InvalidArgumentException("The Environmental variable \"{$key}\" already exists. " .
127126
"It's recommended to make every variable unique.", 1);
128127
}
128+
*/
129129
$_ENV[$key] = $value;
130130
if (is_array($value)) {
131131
$value = json_encode($value);

Uri.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public function getAuthority(): string
120120
$this->authority .= ":{$port}";
121121
}
122122
}
123-
124123
return $this->authority;
125124
}
126125

@@ -139,7 +138,7 @@ public function getUserInfo(): string
139138
$this->encoded['pass'] = $pass;
140139
}
141140

142-
if (!is_null($user)) {
141+
if (is_string($user) && !empty($user)) {
143142
$this->userInfo .= "{$user}";
144143
if (!is_null($pass)) {
145144
$this->userInfo .= ":{$pass}";
@@ -156,8 +155,13 @@ public function getUserInfo(): string
156155
public function getHost(): string
157156
{
158157
if ($val = $this->getUniquePart("host")) {
158+
if(($pos = strpos($val, ":")) !== false) {
159+
$val = substr($val, 0, $pos);
160+
}
159161
$this->encoded['host'] = Format\Str::value($val)->tolower()->get();
160162
}
163+
164+
161165
return (string)$this->encoded['host'];
162166
}
163167

@@ -196,6 +200,7 @@ public function getPath(): string
196200
{
197201
if ($val = $this->getUniquePart("path")) {
198202
$this->encoded['path'] = Format\Str::value($val)->toggleUrlencode(['%2F'], ['/'])->get();
203+
if($this->encoded['path']) $this->encoded['path'] = "/".ltrim($this->encoded['path'], "/");
199204
}
200205
return (string)$this->encoded['path'];
201206
}

Url.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function withType(null|string|array $type = null): self
5959
$type = [];
6060
}
6161

62+
6263
$inst = clone $this;
6364
$parts = $vars = array();
6465
foreach ($inst->parts as $sel => $row) {
@@ -256,8 +257,13 @@ public function getRootDir(string $path = "", bool $endSlash = false): string
256257
if ($scheme = $this->getScheme()) {
257258
$url .= "{$scheme}:";
258259
}
259-
if ($authority = $this->getHost()) {
260-
$url .= "//{$authority}";
260+
if ($host = $this->getHost()) {
261+
$url .= "//{$host}";
262+
}
263+
264+
// Do not show standard ports becouse they are not needed.
265+
if (($port = $this->getPort()) && $port !== 80 && $port !== 443) {
266+
$url .= ":{$port}";
261267
}
262268

263269
if ($dir = $this->getDirPath()) {

0 commit comments

Comments
 (0)