Skip to content

Commit 9a05cc0

Browse files
committed
restructure actions/constants
1 parent 243fa36 commit 9a05cc0

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?php
22

3-
namespace UriManage;
3+
namespace UriManage\Actions;
44

55
use InvalidArgumentException;
66
use UriManage\Components\Path;
77
use UriManage\Components\Query;
8-
use UriManage\Constants\Component;
98

109
/**
1110
* @internal
1211
*/
13-
class UriParser {
12+
final class Parse {
1413
static function parseHost (string $host) : string {
1514
return strtolower($host);
1615
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace UriManage;
3+
namespace UriManage\Constants;
44

55
/**
66
* @internal
77
*/
8-
class DefaultSchemePorts {
8+
final class DefaultSchemePorts {
99

1010
const SCHEME_TO_PORT = [
1111
'http' => 80,

src/Uri.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace UriManage;
44

55
use InvalidArgumentException;
6-
use Stringable;
76
use Psr\Http\Message\UriInterface;
7+
use Stringable;
88
use UriManage\Actions\Compose;
9+
use UriManage\Actions\Parse;
910
use UriManage\Components\Path;
1011
use UriManage\Components\Query;
1112
use UriManage\Constants\Component;
13+
use UriManage\Constants\DefaultSchemePorts;
1214
use UriManage\Exceptions\UriException;
1315

1416
class Uri implements UriInterface {
@@ -43,9 +45,9 @@ function __construct (string|Stringable|null $uri) {
4345
foreach ($uriComponents as $component => $value) {
4446
/** @psalm-suppress InvalidScalarArgument TODO: Remove when psalm supports `ArrayShape` attribute */
4547
match ($component) {
46-
Component::HOST => $this->host = UriParser::parseHost($value),
47-
Component::PATH => $this->path = UriParser::parsePath($value),
48-
Component::QUERY => $this->query = UriParser::parseQuery($value),
48+
Component::HOST => $this->host = Parse::parseHost($value),
49+
Component::PATH => $this->path = Parse::parsePath($value),
50+
Component::QUERY => $this->query = Parse::parseQuery($value),
4951
default => $this->$component = $value
5052
};
5153
}
@@ -160,7 +162,7 @@ function withQuery ($query) : static {
160162
}
161163

162164
$instance = clone $this;
163-
$instance->query = ($query === '') ? null : (($query instanceof Query) ? $query : UriParser::parseQuery($query));
165+
$instance->query = ($query === '') ? null : (($query instanceof Query) ? $query : Parse::parseQuery($query));
164166

165167
return $instance;
166168
}
@@ -182,7 +184,7 @@ function withHost ($host) : static {
182184
if ($host === '') {
183185
$instance->host = null;
184186
} else {
185-
$instance->host = UriParser::parseHost($host);
187+
$instance->host = Parse::parseHost($host);
186188
}
187189

188190
return $instance;
@@ -200,7 +202,7 @@ function withPath ($path) : static {
200202
}
201203

202204
$instance = clone $this;
203-
$instance->path = ($path instanceof Path) ? $path : UriParser::parsePath($path);
205+
$instance->path = ($path instanceof Path) ? $path : Parse::parsePath($path);
204206

205207
return $instance;
206208
}

0 commit comments

Comments
 (0)