~/docs
Resonate
Resonate
13.x 13.43.0.3, current
Fledge
Toggle sidebar
Fledge
webpatser/fledge-framework 13.43.0.3

Fledge 13.x

Native URI

How Fledge uses PHP's native Uri\Rfc3986\Uri instead of league/uri, and the normalization layer that keeps existing URLs working.

Laravel's Illuminate\Support\Uri is built on league/uri, about 11,000 lines of PHP. Fledge's framework replaces it with Uri\Rfc3986\Uri (fledge-fiber still requires league/uri ^7.0), the URI parser compiled into PHP since 8.5. URIs are parsed on every request (Request::uri(), the url() helper, redirects, route generation), so the savings add up across the request lifecycle.

The class and its public API are unchanged. Illuminate\Support\Uri keeps methods such as of(), to(), route(), host(), path(), query() and value().

The strictness problem

PHP's native parser follows RFC 3986 strictly, and is stricter than league/uri. It rejects:

  • Internationalized domain names like bébé.be
  • Unicode in paths like /日本語/page
  • Unencoded brackets in query strings like ?filter[status]=active

All three are common in real applications.

The normalization layer

The Illuminate\Support\Uri constructor runs every string through normalizeForRfc3986() before handing it to the native parser. It is a protected static method, so you do not call it yourself. It applies three steps in order:

  1. encodeIdnHost() converts an internationalized host to ASCII punycode. Userinfo is split off first, so only the real host label is mapped. A host that cannot be mapped is passed through untouched, and the native parser rejects it like any other invalid host.
  2. encodeUnicodePath() percent-encodes non-ASCII characters in the path with rawurlencode.
  3. encodeQueryBrackets() percent-encodes [ and ] in the query string. Brackets that are already encoded are left alone.

An empty string is returned unchanged.

You write Fledge normalizes to
https://bébé.be https://xn--bb-bjab.be
https://example.com/日本語 https://example.com/%E6%97%A5%E6%9C%AC%E8%AA%9E
?filter[status]=active ?filter%5Bstatus%5D=active
use Illuminate\Support\Uri;
 
$uri = Uri::of('https://bébé.be/日本語?filter[status]=active');
 
$uri->value();

The result is the normalized string, so existing URLs keep working without changes in your application. The IDN step needs the intl extension.

Try it

Type a URL or pick a preset. The server passes the raw string to Uri\Rfc3986\Uri and to Uri::of(), and shows what each one does with it.

URL
Raw input, native parser
https://bébé.be/
Rejected

The specified URI is malformed

After normalizeForRfc3986()
https://xn--bb-bjab.be/
Parsed
Uri\Rfc3986\Uri Value
getScheme() https
getUserInfo() null
getHost() xn--bb-bjab.be
getPort() null
getPath() /
getQuery() null
getFragment() null
use Illuminate\Support\Uri;
use Uri\Rfc3986\Uri as NativeUri;

// The raw string, straight into PHP's native parser
new NativeUri($input); // throws Uri\InvalidUriException when rejected

// Through Fledge: normalizeForRfc3986() runs in the constructor
$uri = Uri::of($input);
$uri->value();

Computed on this server at request time with the installed Fledge framework and PHP 8.6.

Instances created from a native URI

If you pass an existing Uri\Rfc3986\Uri instance to the constructor, it is used as is and not normalized.

Measuring it

php artisan fledge:bench --scenario=uri times native parsing. It compares against league/uri only when that package is installed, and prints how to install it otherwise. See Benchmarks.