|
16 | 16 | class HttpRequest extends HttpMessage |
17 | 17 | { |
18 | 18 | private string $method; |
19 | | - private string $scheme; |
20 | | - private Host $host; |
21 | | - private string $path; |
22 | | - private Query $query; |
| 19 | + private Url $url; |
23 | 20 | private Form $form; |
24 | 21 | public array $RouteValues = []; |
25 | 22 |
|
26 | | - public function __construct( |
27 | | - string $method, |
28 | | - string $url, |
29 | | - ?Headers $headers = null, |
30 | | - ?Stream $body = null, |
31 | | - ?Form $form = null |
32 | | - ) { |
| 23 | + public function __construct(string $method, string $url, ?Headers $headers = null, ?Stream $body = null, ?Form $form = null) |
| 24 | + { |
33 | 25 | $this->method = strtoupper($method); |
34 | | - $this->headers = $headers ?? new Headers(); |
| 26 | + $this->url = new Url($url); |
| 27 | + $this->headers = $headers ?? new Headers(['Host' => $this->url->Host]); |
35 | 28 | $this->cookies = new Cookies($this->Headers); |
36 | 29 | $this->body = $body ?? new FileStream('php://temp', FileMode::Open, FileAccess::ReadWrite); |
37 | 30 | $this->form = $form ?? new Form(); |
38 | | - $this->scheme = (string) parse_url($url, PHP_URL_SCHEME); |
39 | | - |
40 | | - if (!$this->scheme) { |
41 | | - $this->scheme = 'http'; |
42 | | - $url = $this->scheme . '://' . $url; |
43 | | - } |
44 | | - |
45 | | - $host = parse_url($url, PHP_URL_HOST); |
46 | | - $port = parse_url($url, PHP_URL_PORT); |
47 | | - $this->host = new Host($host, $port); |
48 | | - |
49 | | - $this->path = parse_url($url, PHP_URL_PATH) ?? '/'; |
50 | | - |
51 | | - $query = parse_url($url, PHP_URL_QUERY); |
52 | | - $this->query = new Query($query); |
53 | 31 | } |
54 | 32 |
|
55 | 33 | public function get_Method(): string |
56 | 34 | { |
57 | 35 | return $this->method; |
58 | 36 | } |
59 | 37 |
|
60 | | - public function get_Scheme(): string |
| 38 | + public function get_Url(): Url |
61 | 39 | { |
62 | | - return $this->scheme; |
63 | | - } |
64 | | - |
65 | | - public function get_Host(): Host |
66 | | - { |
67 | | - return $this->host; |
68 | | - } |
69 | | - |
70 | | - public function get_Path(): string |
71 | | - { |
72 | | - return $this->path; |
73 | | - } |
74 | | - |
75 | | - public function get_Query(): Query |
76 | | - { |
77 | | - return $this->query; |
| 40 | + return $this->url; |
78 | 41 | } |
79 | 42 |
|
80 | 43 | public function get_Form(): Form |
81 | 44 | { |
82 | 45 | return $this->form; |
83 | 46 | } |
84 | | - |
85 | | - public function set_Path(string $value): void |
86 | | - { |
87 | | - $this->path = $value; |
88 | | - } |
89 | 47 | } |
0 commit comments