Skip to content
Closed
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
1bb8f52
fix: fixed the codeigniter routing for installations in subdirectorie…
FrancescoCiannavei Jun 18, 2025
b65b1f5
Revert "fix: fixed the codeigniter routing for installations in subdi…
FrancescoCiannavei Jun 23, 2025
4343fe4
fix: fixed the codeigniter routing for installations in subdirectorie…
FrancescoCiannavei Jun 23, 2025
89ce426
fix: fixed the codeigniter routing for installations in subdirectorie…
FrancescoCiannavei Jun 23, 2025
74ef94a
fix: fixed the codeigniter routing for installations in subdirectorie…
FrancescoCiannavei Jun 23, 2025
9063df5
fix: fixed the codeigniter routing for installations in subdirectorie…
FrancescoCiannavei Jun 23, 2025
20607d8
fix: Error: Only booleans are allowed in &&, string given on the left…
FrancescoCiannavei Jun 23, 2025
f60db2c
fix: ran "php-cs-fixer fix" to make the SiteURIFactory follow the cha…
FrancescoCiannavei Jun 23, 2025
1639f88
refactor: Replaced config(App::class) with $this->appConfig inside th…
FrancescoCiannavei Jun 24, 2025
e588cd6
Merge remote-tracking branch 'upstream/develop' into develop
FrancescoCiannavei Jun 24, 2025
5e518fa
feat: added tests for the fix on the SiteURIFactory
FrancescoCiannavei Jun 24, 2025
94a8d83
fix: Apply Rector code style fixes
FrancescoCiannavei Jun 24, 2025
ee2013d
fix: Apply Rector code style fixes 2
FrancescoCiannavei Jun 24, 2025
ff0c9b3
refactor: test for index page and subdir combinations
FrancescoCiannavei Jun 26, 2025
20d43da
Refactor SiteURIFactory to use injected App config
FrancescoCiannavei Jun 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions system/HTTP/SiteURIFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,40 @@ public function detectRoutePath(string $protocol = ''): string
*/
private function parseRequestURI(): string
{
$appConfig = config(App::class);
$baseUrl = $appConfig->baseURL;
$indexPage = $appConfig->indexPage;
$baseUri = false;
$parsedUrl = parse_url($baseUrl);

if (isset($parsedUrl['path'])) { // The path could be empty if the url is just a domain
$baseUri = $parsedUrl['path'];
}
if ($baseUri) {
$baseUriArray = explode('/', $baseUri);
$baseUriArray = array_filter($baseUriArray); // We remove the empty strings from the array
$baseUri = implode('/', $baseUriArray); // We join the array back into a string with slashes
if ($baseUri !== '') {
$baseUri = '/' . $baseUri; // We add a slash at the beginning of the base Uri as implode will not do that
} else {
$baseUri = false;
}
}

$serverRequestUri = $this->superglobals->server('REQUEST_URI'); // We get the request URI from the server superglobals

if (null !== $serverRequestUri) {
if ($baseUri && str_starts_with($serverRequestUri, $baseUri)) {
$serverRequestUri = substr($serverRequestUri, strlen($baseUri));
} // We remove the base Uri from the request URI if it exists, baseUri is the path to the subdirectory
if ($indexPage !== false && str_starts_with($serverRequestUri, '/' . $indexPage)) {
$serverRequestUri = substr($serverRequestUri, strlen('/' . $indexPage));
} // We remove the index page from the request URI if it exists
$serverRequestUri = '/' . ltrim($serverRequestUri, '/'); // makes sure that the uri starts with a slash
}

if (
$this->superglobals->server('REQUEST_URI') === null
$serverRequestUri === null
|| $this->superglobals->server('SCRIPT_NAME') === null
) {
return '';
Expand All @@ -122,7 +154,7 @@ private function parseRequestURI(): string
// string contains a colon followed by a number. So we attach a dummy
// host since REQUEST_URI does not include the host. This allows us to
// parse out the query string and path.
$parts = parse_url('http://dummy' . $this->superglobals->server('REQUEST_URI'));
$parts = parse_url('http://dummy' . $serverRequestUri);
$query = $parts['query'] ?? '';
$path = $parts['path'] ?? '';

Expand Down
Loading