Skip to content

Commit 23b64e6

Browse files
authored
chore: remove IncomingRequest deprecations (codeigniter4#9851)
* chore: remove IncomingRequest deprecations * update user guide
1 parent 08bc0f8 commit 23b64e6

File tree

10 files changed

+16
-514
lines changed

10 files changed

+16
-514
lines changed

system/HTTP/IncomingRequest.php

Lines changed: 2 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -200,133 +200,6 @@ public function detectLocale($config)
200200
$this->setLocale($this->negotiate('language', $config->supportedLocales));
201201
}
202202

203-
/**
204-
* Sets up our URI object based on the information we have. This is
205-
* either provided by the user in the baseURL Config setting, or
206-
* determined from the environment as needed.
207-
*
208-
* @return void
209-
*
210-
* @deprecated 4.4.0 No longer used.
211-
*/
212-
protected function detectURI(string $protocol, string $baseURL)
213-
{
214-
$this->setPath($this->detectPath($this->config->uriProtocol), $this->config);
215-
}
216-
217-
/**
218-
* Detects the relative path based on
219-
* the URIProtocol Config setting.
220-
*
221-
* @deprecated 4.4.0 Moved to SiteURIFactory.
222-
*/
223-
public function detectPath(string $protocol = ''): string
224-
{
225-
if ($protocol === '') {
226-
$protocol = 'REQUEST_URI';
227-
}
228-
229-
$this->path = match ($protocol) {
230-
'REQUEST_URI' => $this->parseRequestURI(),
231-
'QUERY_STRING' => $this->parseQueryString(),
232-
default => $this->fetchGlobal('server', $protocol) ?? $this->parseRequestURI(),
233-
};
234-
235-
return $this->path;
236-
}
237-
238-
/**
239-
* Will parse the REQUEST_URI and automatically detect the URI from it,
240-
* fixing the query string if necessary.
241-
*
242-
* @return string The URI it found.
243-
*
244-
* @deprecated 4.4.0 Moved to SiteURIFactory.
245-
*/
246-
protected function parseRequestURI(): string
247-
{
248-
if (! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) {
249-
return '';
250-
}
251-
252-
// parse_url() returns false if no host is present, but the path or query string
253-
// contains a colon followed by a number. So we attach a dummy host since
254-
// REQUEST_URI does not include the host. This allows us to parse out the query string and path.
255-
$parts = parse_url('http://dummy' . $_SERVER['REQUEST_URI']);
256-
$query = $parts['query'] ?? '';
257-
$uri = $parts['path'] ?? '';
258-
259-
// Strip the SCRIPT_NAME path from the URI
260-
if (
261-
$uri !== '' && isset($_SERVER['SCRIPT_NAME'][0])
262-
&& pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_EXTENSION) === 'php'
263-
) {
264-
// Compare each segment, dropping them until there is no match
265-
$segments = $keep = explode('/', $uri);
266-
267-
foreach (explode('/', $_SERVER['SCRIPT_NAME']) as $i => $segment) {
268-
// If these segments are not the same then we're done
269-
if (! isset($segments[$i]) || $segment !== $segments[$i]) {
270-
break;
271-
}
272-
273-
array_shift($keep);
274-
}
275-
276-
$uri = implode('/', $keep);
277-
}
278-
279-
// This section ensures that even on servers that require the URI to contain the query string (Nginx) a correct
280-
// URI is found, and also fixes the QUERY_STRING Server var and $_GET array.
281-
if (trim($uri, '/') === '' && str_starts_with($query, '/')) {
282-
$query = explode('?', $query, 2);
283-
$uri = $query[0];
284-
$_SERVER['QUERY_STRING'] = $query[1] ?? '';
285-
} else {
286-
$_SERVER['QUERY_STRING'] = $query;
287-
}
288-
289-
// Update our globals for values likely to been have changed
290-
parse_str($_SERVER['QUERY_STRING'], $_GET);
291-
$this->populateGlobals('server');
292-
$this->populateGlobals('get');
293-
294-
$uri = URI::removeDotSegments($uri);
295-
296-
return ($uri === '/' || $uri === '') ? '/' : ltrim($uri, '/');
297-
}
298-
299-
/**
300-
* Parse QUERY_STRING
301-
*
302-
* Will parse QUERY_STRING and automatically detect the URI from it.
303-
*
304-
* @deprecated 4.4.0 Moved to SiteURIFactory.
305-
*/
306-
protected function parseQueryString(): string
307-
{
308-
$uri = $_SERVER['QUERY_STRING'] ?? @getenv('QUERY_STRING');
309-
310-
if (trim($uri, '/') === '') {
311-
return '/';
312-
}
313-
314-
if (str_starts_with($uri, '/')) {
315-
$uri = explode('?', $uri, 2);
316-
$_SERVER['QUERY_STRING'] = $uri[1] ?? '';
317-
$uri = $uri[0];
318-
}
319-
320-
// Update our globals for values likely to been have changed
321-
parse_str($_SERVER['QUERY_STRING'], $_GET);
322-
$this->populateGlobals('server');
323-
$this->populateGlobals('get');
324-
325-
$uri = URI::removeDotSegments($uri);
326-
327-
return ($uri === '/' || $uri === '') ? '/' : ltrim($uri, '/');
328-
}
329-
330203
/**
331204
* Provides a convenient way to work with the Negotiate class
332205
* for content negotiation.
@@ -411,14 +284,11 @@ public function isSecure(): bool
411284
* instance, this can be used to change the "current URL"
412285
* for testing.
413286
*
414-
* @param string $path URI path relative to baseURL
415-
* @param App|null $config Optional alternate config to use
287+
* @param string $path URI path relative to baseURL
416288
*
417289
* @return $this
418-
*
419-
* @deprecated 4.4.0 This method will be private. The parameter $config is deprecated. No longer used.
420290
*/
421-
public function setPath(string $path, ?App $config = null)
291+
private function setPath(string $path)
422292
{
423293
$this->path = $path;
424294

tests/system/HTTP/IncomingRequestDetectingTest.php

Lines changed: 0 additions & 196 deletions
This file was deleted.

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -909,36 +909,6 @@ public function testGetPostIndexNotExists(): void
909909
$this->assertNull($this->request->getGetPost('gc'));
910910
}
911911

912-
/**
913-
* @param mixed $path
914-
* @param mixed $detectPath
915-
*/
916-
#[DataProvider('provideExtensionPHP')]
917-
public function testExtensionPHP($path, $detectPath): void
918-
{
919-
$config = new App();
920-
$config->baseURL = 'http://example.com/';
921-
922-
$_SERVER['REQUEST_URI'] = $path;
923-
$_SERVER['SCRIPT_NAME'] = $path;
924-
$request = new IncomingRequest($config, new SiteURI($config, $path), null, new UserAgent());
925-
$this->assertSame($detectPath, $request->detectPath());
926-
}
927-
928-
public static function provideExtensionPHP(): iterable
929-
{
930-
return [
931-
'not /index.php' => [
932-
'/test.php',
933-
'/',
934-
],
935-
'/index.php' => [
936-
'/index.php',
937-
'/',
938-
],
939-
];
940-
}
941-
942912
public function testGetPath(): void
943913
{
944914
$request = $this->createRequest(null, null, 'fruits/banana');
@@ -952,7 +922,8 @@ public function testSetPath(): void
952922
$request = new IncomingRequest($config, new SiteURI($config), null, new UserAgent());
953923
$this->assertSame('', $request->getPath());
954924

955-
$request->setPath('foobar');
925+
$setPath = $this->getPrivateMethodInvoker($request, 'setPath');
926+
$setPath('foobar');
956927
$this->assertSame('foobar', $request->getPath());
957928
}
958929

0 commit comments

Comments
 (0)