Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"league/flysystem": "^3.25.1",
"league/flysystem-local": "^3.25.1",
"league/uri": "^7.5.1",
"league/uri-polyfill": "^7.7.0",
"monolog/monolog": "^3.0",
"nesbot/carbon": "^3.8.4",
"nunomaduro/termwind": "^2.0",
Expand Down
4 changes: 3 additions & 1 deletion config/mail.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Uri\Rfc3986\Uri;

return [

/*
Expand Down Expand Up @@ -46,7 +48,7 @@
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url((string) env('APP_URL', 'http://localhost'), PHP_URL_HOST)),
'local_domain' => env('MAIL_EHLO_DOMAIN', (new Uri((string) env('APP_URL', 'http://localhost')))->getHost()),
],

'ses' => [
Expand Down
9 changes: 5 additions & 4 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use RuntimeException;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Throwable;
use Uri\Rfc3986\Uri;

/**
* @mixin \League\Flysystem\FilesystemOperator
Expand Down Expand Up @@ -858,12 +859,12 @@ protected function concatPathToUrl($url, $path)
*/
protected function replaceBaseUrl($uri, $url)
{
$parsed = parse_url($url);
$parsed = new Uri($url);

return $uri
->withScheme($parsed['scheme'])
->withHost($parsed['host'])
->withPort($parsed['port'] ?? null);
->withScheme($parsed->getScheme())
->withHost($parsed->getHost())
->withPort($parsed->getPort());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Filesystem/FilesystemServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Uri\Rfc3986\Uri;

class FilesystemServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -90,7 +91,7 @@ protected function serveFiles()

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

$isProduction = $app->isProduction();
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Filesystem/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"illuminate/contracts": "^12.0",
"illuminate/macroable": "^12.0",
"illuminate/support": "^12.0",
"league/uri-polyfill": "^7.7.0",
"symfony/finder": "^7.2.0"
},
"autoload": {
Expand Down
9 changes: 5 additions & 4 deletions src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Uri\Rfc3986\Uri;

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

$components = parse_url($uri);
$components = new Uri($uri);

$server = $_SERVER;

if (isset($components['path'])) {
if ($path = $components->getPath()) {
$server = array_merge($server, [
'SCRIPT_FILENAME' => $components['path'],
'SCRIPT_NAME' => $components['path'],
'SCRIPT_FILENAME' => $path,
'SCRIPT_NAME' => $path,
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Uri\Rfc3986\Uri;

// Check if the application is in maintenance mode...
if (! file_exists($down = __DIR__.'/down')) {
return;
Expand All @@ -15,7 +17,7 @@ if (! isset($data['template'])) {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\VarDumper\Caster\StubCaster;
use Symfony\Component\VarDumper\Cloner\AbstractCloner;
use Uri\Rfc3986\Uri as Rfc3986Uri;

class FoundationServiceProvider extends AggregateServiceProvider
{
Expand Down Expand Up @@ -133,7 +134,7 @@ public function registerDumper()
'html' == $format => HtmlDumper::register($basePath, $compiledViewPath),
'cli' == $format => CliDumper::register($basePath, $compiledViewPath),
'server' == $format => null,
$format && 'tcp' == parse_url($format, PHP_URL_SCHEME) => null,
$format && 'tcp' == Rfc3986Uri::parse($format)?->getScheme() => null,
default => in_array(PHP_SAPI, ['cli', 'phpdbg']) ? CliDumper::register($basePath, $compiledViewPath) : HtmlDumper::register($basePath, $compiledViewPath),
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Uri\Rfc3986\Uri;

class TrustHosts
{
Expand Down Expand Up @@ -109,7 +110,7 @@ protected function shouldSpecifyTrustedHosts()
*/
protected function allSubdomainsOfApplicationUrl()
{
if ($host = parse_url($this->app['config']->get('app.url'), PHP_URL_HOST)) {
if ($host = Uri::parse($this->app['config']->get('app.url'))?->getHost()) {
return '^(.+\.)?'.preg_quote($host).'$';
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Http/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"illuminate/macroable": "^12.0",
"illuminate/session": "^12.0",
"illuminate/support": "^12.0",
"league/uri-polyfill": "^7.7.0",
"symfony/http-foundation": "^7.2.0",
"symfony/http-kernel": "^7.2.0",
"symfony/polyfill-php83": "^1.33",
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Routing/RouteUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Routing\Exceptions\UrlGenerationException;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Uri\Rfc3986\Uri;

class RouteUrlGenerator
{
Expand Down Expand Up @@ -381,7 +382,7 @@ protected function addQueryString($uri, array $parameters)
// If the URI has a fragment we will move it to the end of this URI since it will
// need to come after any query string that may be added to the URL else it is
// not going to be available. We will remove it then append it back on here.
if (! is_null($fragment = parse_url($uri, PHP_URL_FRAGMENT))) {
if (! is_null($fragment = Uri::parse($uri)?->getFragment())) {
$uri = preg_replace('/#.*/', '', $uri);
}

Expand Down
45 changes: 22 additions & 23 deletions src/Illuminate/Support/ConfigurationUrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Support;

use InvalidArgumentException;
use Uri\Rfc3986\Uri;

class ConfigurationUrlParser
{
Expand Down Expand Up @@ -39,46 +40,44 @@ public function parseConfiguration($config)
return $config;
}

$rawComponents = $this->parseUrl($url);

$decodedComponents = $this->parseStringsToNativeTypes(
array_map(rawurldecode(...), $rawComponents)
);
$parsedUrl = $this->parseUrl($url);

return array_merge(
$config,
$this->getPrimaryOptions($decodedComponents),
$this->getQueryOptions($rawComponents)
$this->getPrimaryOptions($parsedUrl),
$this->getQueryOptions($parsedUrl)
);
}

/**
* Get the primary database connection options.
*
* @param array $url
* @param Uri $url
* @return array
*/
protected function getPrimaryOptions($url)
{
return array_filter([
$options = array_filter([
'driver' => $this->getDriver($url),
'database' => $this->getDatabase($url),
'host' => $url['host'] ?? null,
'port' => $url['port'] ?? null,
'username' => $url['user'] ?? null,
'password' => $url['pass'] ?? null,
], fn ($value) => ! is_null($value));
'host' => ($host = $url->getHost()) === 'null' ? null : $host,
'port' => $url->getPort(),
'username' => $url->getUsername(),
'password' => $url->getPassword(),
], fn ($value) => $value !== null && $value !== '');

return array_map(rawurldecode(...), $options);
}

/**
* Get the database driver from the URL.
*
* @param array $url
* @param Uri $url
* @return string|null
*/
protected function getDriver($url)
{
$alias = $url['scheme'] ?? null;
$alias = $url->getScheme();

if (! $alias) {
return;
Expand All @@ -90,25 +89,25 @@ protected function getDriver($url)
/**
* Get the database name from the URL.
*
* @param array $url
* @param Uri $url
* @return string|null
*/
protected function getDatabase($url)
{
$path = $url['path'] ?? null;
$path = $url->getPath();

return $path && $path !== '/' ? substr($path, 1) : null;
}

/**
* Get all of the additional database options from the query string.
*
* @param array $url
* @param Uri $url
* @return array
*/
protected function getQueryOptions($url)
{
$queryString = $url['query'] ?? null;
$queryString = $url->getQuery();

if (! $queryString) {
return [];
Expand All @@ -125,17 +124,17 @@ protected function getQueryOptions($url)
* Parse the string URL to an array of components.
*
* @param string $url
* @return array
* @return Uri
*
* @throws \InvalidArgumentException
*/
protected function parseUrl($url)
{
$url = preg_replace('#^(sqlite3?):///#', '$1://null/', $url);

$parsedUrl = parse_url($url);
$parsedUrl = Uri::parse($url);

if ($parsedUrl === false) {
if ($parsedUrl === null) {
throw new InvalidArgumentException('The database configuration URL is malformed.');
}

Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"illuminate/contracts": "^12.0",
"illuminate/macroable": "^12.0",
"illuminate/reflection": "^12.0",
"league/uri-polyfill": "^7.7.0",
"nesbot/carbon": "^3.8.4",
"symfony/polyfill-php83": "^1.33",
"symfony/polyfill-php85": "^1.33",
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use InvalidArgumentException;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Uri\Rfc3986\Uri;
use ValueError;

trait ValidatesAttributes
Expand Down Expand Up @@ -123,7 +124,7 @@ public function validateActiveUrl($attribute, $value)
return false;
}

if ($url = parse_url($value, PHP_URL_HOST)) {
if ($url = Uri::parse($value)?->getHost()) {
try {
$records = $this->getDnsRecords($url.'.', DNS_A | DNS_AAAA);

Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Validation/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"illuminate/macroable": "^12.0",
"illuminate/support": "^12.0",
"illuminate/translation": "^12.0",
"league/uri-polyfill": "^7.7.0",
"symfony/http-foundation": "^7.2",
"symfony/mime": "^7.2",
"symfony/polyfill-php83": "^1.33"
Expand Down
7 changes: 4 additions & 3 deletions tests/Http/HttpRedirectResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Cookie;
use Uri\Rfc3986\Uri;

class HttpRedirectResponseTest extends TestCase
{
Expand Down Expand Up @@ -57,13 +58,13 @@ public function testFragmentIdentifierOnRedirect()
$response = new RedirectResponse('foo.bar');

$response->withFragment('foo');
$this->assertSame('foo', parse_url($response->getTargetUrl(), PHP_URL_FRAGMENT));
$this->assertSame('foo', (new Uri($response->getTargetUrl()))->getFragment());

$response->withFragment('#bar');
$this->assertSame('bar', parse_url($response->getTargetUrl(), PHP_URL_FRAGMENT));
$this->assertSame('bar', (new Uri($response->getTargetUrl()))->getFragment());

$response->withoutFragment();
$this->assertNull(parse_url($response->getTargetUrl(), PHP_URL_FRAGMENT));
$this->assertNull((new Uri($response->getTargetUrl()))->getFragment());
}

public function testInputOnRedirect()
Expand Down
Loading