Skip to content

Commit b78452e

Browse files
committed
refactor: remove deprecations in HTTP
1 parent 3483334 commit b78452e

File tree

18 files changed

+54
-441
lines changed

18 files changed

+54
-441
lines changed

system/HTTP/CURLRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function setJSON($data)
313313
protected function parseOptions(array $options)
314314
{
315315
if (array_key_exists('baseURI', $options)) {
316-
$this->baseURI = $this->baseURI->setURI($options['baseURI']);
316+
$this->baseURI = new URI($options['baseURI']);
317317
unset($options['baseURI']);
318318
}
319319

system/HTTP/Message.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,6 @@ public function getBody()
6060
return $this->body;
6161
}
6262

63-
/**
64-
* Returns an array containing all headers.
65-
*
66-
* @return array<string, Header> An array of the request headers
67-
*
68-
* @deprecated 4.0.5 Use Message::headers() to make room for PSR-7
69-
*
70-
* @TODO Incompatible return value with PSR-7
71-
*
72-
* @codeCoverageIgnore
73-
*/
74-
public function getHeaders(): array
75-
{
76-
return $this->headers();
77-
}
78-
79-
/**
80-
* Returns a single header object. If multiple headers with the same
81-
* name exist, then will return an array of header objects.
82-
*
83-
* @return array|Header|null
84-
*
85-
* @deprecated 4.0.5 Use Message::header() to make room for PSR-7
86-
*
87-
* @TODO Incompatible return value with PSR-7
88-
*
89-
* @codeCoverageIgnore
90-
*/
91-
public function getHeader(string $name)
92-
{
93-
return $this->header($name);
94-
}
95-
9663
/**
9764
* Determines whether a header exists.
9865
*/

system/HTTP/Request.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,6 @@ public function __construct($config = null)
4242
}
4343
}
4444

45-
/**
46-
* Sets the request method. Used when spoofing the request.
47-
*
48-
* @return $this
49-
*
50-
* @deprecated 4.0.5 Use withMethod() instead for immutability
51-
*
52-
* @codeCoverageIgnore
53-
*/
54-
public function setMethod(string $method)
55-
{
56-
$this->method = $method;
57-
58-
return $this;
59-
}
60-
6145
/**
6246
* Returns an instance with the specified method.
6347
*

system/HTTP/RequestTrait.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ trait RequestTrait
3636

3737
/**
3838
* IP address of the current user.
39-
*
40-
* @var string
41-
*
42-
* @deprecated 4.0.5 Will become private in a future release
4339
*/
44-
protected $ipAddress = '';
40+
private string $ipAddress = '';
4541

4642
/**
4743
* Stores values we've retrieved from PHP globals.
@@ -78,11 +74,11 @@ public function getIPAddress(): string
7874
);
7975
}
8076

81-
$this->ipAddress = $this->getServer('REMOTE_ADDR');
77+
$this->ipAddress = $this->getServer('REMOTE_ADDR') ?? '0.0.0.0';
8278

83-
// If this is a CLI request, $this->ipAddress is null.
84-
if ($this->ipAddress === null) {
85-
return $this->ipAddress = '0.0.0.0';
79+
// If this is a CLI request, $this->ipAddress is '0.0.0.0'.
80+
if ($this->ipAddress === '0.0.0.0') {
81+
return $this->ipAddress;
8682
}
8783

8884
// @TODO Extract all this IP address logic to another class.
@@ -206,23 +202,6 @@ public function getServer($index = null, $filter = null, $flags = null)
206202
return $this->fetchGlobal('server', $index, $filter, $flags);
207203
}
208204

209-
/**
210-
* Fetch an item from the $_ENV array.
211-
*
212-
* @param array|string|null $index Index for item to be fetched from $_ENV
213-
* @param int|null $filter A filter name to be applied
214-
* @param array|int|null $flags
215-
*
216-
* @return mixed
217-
*
218-
* @deprecated 4.4.4 This method does not work from the beginning. Use `env()`.
219-
*/
220-
public function getEnv($index = null, $filter = null, $flags = null)
221-
{
222-
// @phpstan-ignore-next-line
223-
return $this->fetchGlobal('env', $index, $filter, $flags);
224-
}
225-
226205
/**
227206
* Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
228207
*

system/HTTP/SiteURI.php

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,10 @@ class SiteURI extends URI
5353
* 1 => 'public',
5454
* 2 => 'index.php',
5555
* ];
56-
*/
57-
private array $baseSegments;
58-
59-
/**
60-
* List of URI segments after indexPage.
61-
*
62-
* The word "URI Segments" originally means only the URI path part relative
63-
* to the baseURL.
64-
*
65-
* If the URI is "http://localhost:8888/ci431/public/index.php/test?a=b",
66-
* and the baseURL is "http://localhost:8888/ci431/public/", then:
67-
* $segments = [
68-
* 0 => 'test',
69-
* ];
7056
*
71-
* @var array<int, string>
72-
*
73-
* @deprecated 4.4.0 This property will be private.
57+
* @var list<string>
7458
*/
75-
protected $segments;
59+
private array $baseSegments;
7660

7761
/**
7862
* URI path relative to baseURL.
@@ -149,9 +133,9 @@ private function determineBaseURL(
149133

150134
// Update scheme
151135
if ($scheme !== null && $scheme !== '') {
152-
$uri->setScheme($scheme);
136+
$uri = $uri->withScheme($scheme);
153137
} elseif ($configApp->forceGlobalSecureRequests) {
154-
$uri->setScheme('https');
138+
$uri = $uri->withScheme('https');
155139
}
156140

157141
// Update host
@@ -219,26 +203,10 @@ private function setBasePath(): void
219203
}
220204
}
221205

222-
/**
223-
* @deprecated 4.4.0
224-
*/
225-
public function setBaseURL(string $baseURL): void
226-
{
227-
throw new BadMethodCallException('Cannot use this method.');
228-
}
229-
230-
/**
231-
* @deprecated 4.4.0
232-
*/
233-
public function setURI(?string $uri = null)
234-
{
235-
throw new BadMethodCallException('Cannot use this method.');
236-
}
237-
238206
/**
239207
* Returns the baseURL.
240208
*
241-
* @interal
209+
* @internal
242210
*/
243211
public function getBaseURL(): string
244212
{
@@ -298,23 +266,21 @@ private function setRoutePath(string $routePath): void
298266
}
299267

300268
/**
301-
* Converts path to segments
269+
* @return list<string>
302270
*/
303271
private function convertToSegments(string $path): array
304272
{
305273
$tempPath = trim($path, '/');
306274

307-
return ($tempPath === '') ? [] : explode('/', $tempPath);
275+
return $tempPath === '' ? [] : explode('/', $tempPath);
308276
}
309277

310278
/**
311279
* Sets the path portion of the URI based on segments.
312280
*
313281
* @return $this
314-
*
315-
* @deprecated 4.4.0 This method will be private.
316282
*/
317-
public function refreshPath()
283+
protected function refreshPath(): self
318284
{
319285
$allSegments = array_merge($this->baseSegments, $this->segments);
320286
$this->path = '/' . $this->filterPath(implode('/', $allSegments));
@@ -364,11 +330,7 @@ protected function applyParts(array $parts): void
364330
$this->fragment = $parts['fragment'];
365331
}
366332

367-
if (isset($parts['scheme'])) {
368-
$this->setScheme(rtrim($parts['scheme'], ':/'));
369-
} else {
370-
$this->setScheme('http');
371-
}
333+
$this->scheme = $this->withScheme($parts['scheme'] ?? 'http')->getScheme();
372334

373335
if (isset($parts['port'])) {
374336
// Valid port numbers are enforced by earlier parse_url or setPort()

0 commit comments

Comments
 (0)