Skip to content

Commit d726cb5

Browse files
committed
Use new PHP 8.5 RFC 3986 compliant Uri class
Including polyfill for prior PHP versions without native support See also https://wiki.php.net/rfc/url_parsing_api
1 parent e4551e7 commit d726cb5

File tree

16 files changed

+57
-41
lines changed

16 files changed

+57
-41
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"league/flysystem": "^3.25.1",
3838
"league/flysystem-local": "^3.25.1",
3939
"league/uri": "^7.5.1",
40+
"league/uri-polyfill": "^7.7.0",
4041
"monolog/monolog": "^3.0",
4142
"nesbot/carbon": "^3.8.4",
4243
"nunomaduro/termwind": "^2.0",

config/mail.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Uri\Rfc3986\Uri;
4+
35
return [
46

57
/*
@@ -46,7 +48,7 @@
4648
'username' => env('MAIL_USERNAME'),
4749
'password' => env('MAIL_PASSWORD'),
4850
'timeout' => null,
49-
'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url((string) env('APP_URL', 'http://localhost'), PHP_URL_HOST)),
51+
'local_domain' => env('MAIL_EHLO_DOMAIN', (new Uri((string) env('APP_URL', 'http://localhost')))->getHost()),
5052
],
5153

5254
'ses' => [

src/Illuminate/Filesystem/FilesystemAdapter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use RuntimeException;
3939
use Symfony\Component\HttpFoundation\StreamedResponse;
4040
use Throwable;
41+
use Uri\Rfc3986\Uri;
4142

4243
/**
4344
* @mixin \League\Flysystem\FilesystemOperator
@@ -858,12 +859,12 @@ protected function concatPathToUrl($url, $path)
858859
*/
859860
protected function replaceBaseUrl($uri, $url)
860861
{
861-
$parsed = parse_url($url);
862+
$parsed = new Uri($url);
862863

863864
return $uri
864-
->withScheme($parsed['scheme'])
865-
->withHost($parsed['host'])
866-
->withPort($parsed['port'] ?? null);
865+
->withScheme($parsed->getScheme())
866+
->withHost($parsed->getHost())
867+
->withPort($parsed->getPort());
867868
}
868869

869870
/**

src/Illuminate/Filesystem/FilesystemServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Http\Request;
77
use Illuminate\Support\Facades\Route;
88
use Illuminate\Support\ServiceProvider;
9+
use Uri\Rfc3986\Uri;
910

1011
class FilesystemServiceProvider extends ServiceProvider
1112
{
@@ -90,7 +91,7 @@ protected function serveFiles()
9091

9192
$this->app->booted(function ($app) use ($disk, $config) {
9293
$uri = isset($config['url'])
93-
? rtrim(parse_url($config['url'])['path'], '/')
94+
? rtrim((new Uri($config['url']))->getPath(), '/')
9495
: '/storage';
9596

9697
$isProduction = $app->isProduction();

src/Illuminate/Filesystem/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"illuminate/contracts": "^12.0",
2020
"illuminate/macroable": "^12.0",
2121
"illuminate/support": "^12.0",
22+
"league/uri-polyfill": "^7.7.0",
2223
"symfony/finder": "^7.2.0"
2324
},
2425
"autoload": {

src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Contracts\Foundation\Application;
66
use Illuminate\Http\Request;
7+
use Uri\Rfc3986\Uri;
78

89
class SetRequestForConsole
910
{
@@ -17,14 +18,14 @@ public function bootstrap(Application $app)
1718
{
1819
$uri = $app->make('config')->get('app.url', 'http://localhost');
1920

20-
$components = parse_url($uri);
21+
$components = new Uri($uri);
2122

2223
$server = $_SERVER;
2324

24-
if (isset($components['path'])) {
25+
if ($path = $components->getPath()) {
2526
$server = array_merge($server, [
26-
'SCRIPT_FILENAME' => $components['path'],
27-
'SCRIPT_NAME' => $components['path'],
27+
'SCRIPT_FILENAME' => $path,
28+
'SCRIPT_NAME' => $path,
2829
]);
2930
}
3031

src/Illuminate/Foundation/Console/stubs/maintenance-mode.stub

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Uri\Rfc3986\Uri;
4+
35
// Check if the application is in maintenance mode...
46
if (! file_exists($down = __DIR__.'/down')) {
57
return;
@@ -15,7 +17,7 @@ if (! isset($data['template'])) {
1517

1618
// Allow framework to handle request if request URI is in the exclude list...
1719
if (isset($data['except'])) {
18-
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
20+
$uri = (new Uri($_SERVER['REQUEST_URI']))->getPath();
1921

2022
$uri = rawurldecode($uri !== '/' ? trim($uri, '/') : $uri);
2123

src/Illuminate/Foundation/Providers/FoundationServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
3636
use Symfony\Component\VarDumper\Caster\StubCaster;
3737
use Symfony\Component\VarDumper\Cloner\AbstractCloner;
38+
use Uri\Rfc3986\Uri as Rfc3986Uri;
3839

3940
class FoundationServiceProvider extends AggregateServiceProvider
4041
{
@@ -133,7 +134,7 @@ public function registerDumper()
133134
'html' == $format => HtmlDumper::register($basePath, $compiledViewPath),
134135
'cli' == $format => CliDumper::register($basePath, $compiledViewPath),
135136
'server' == $format => null,
136-
$format && 'tcp' == parse_url($format, PHP_URL_SCHEME) => null,
137+
$format && 'tcp' == Rfc3986Uri::parse($format)?->getScheme() => null,
137138
default => in_array(PHP_SAPI, ['cli', 'phpdbg']) ? CliDumper::register($basePath, $compiledViewPath) : HtmlDumper::register($basePath, $compiledViewPath),
138139
};
139140
}

src/Illuminate/Http/Middleware/TrustHosts.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Contracts\Foundation\Application;
66
use Illuminate\Http\Request;
7+
use Uri\Rfc3986\Uri;
78

89
class TrustHosts
910
{
@@ -109,7 +110,7 @@ protected function shouldSpecifyTrustedHosts()
109110
*/
110111
protected function allSubdomainsOfApplicationUrl()
111112
{
112-
if ($host = parse_url($this->app['config']->get('app.url'), PHP_URL_HOST)) {
113+
if ($host = Uri::parse($this->app['config']->get('app.url'))?->getHost()) {
113114
return '^(.+\.)?'.preg_quote($host).'$';
114115
}
115116
}

src/Illuminate/Http/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"illuminate/macroable": "^12.0",
2424
"illuminate/session": "^12.0",
2525
"illuminate/support": "^12.0",
26+
"league/uri-polyfill": "^7.7.0",
2627
"symfony/http-foundation": "^7.2.0",
2728
"symfony/http-kernel": "^7.2.0",
2829
"symfony/polyfill-php83": "^1.33",

0 commit comments

Comments
 (0)