zenstruck/uri
Immutable, fluent URI/URL value objects for PHP with easy parsing, building, and modification of URIs. Create, normalize, and manipulate components (scheme, host, path, query, fragment) safely, with helpers for encoding and query params.
parse_url(), which aligns well with Laravel’s emphasis on object-oriented design and fluent interfaces. It can replace manual URL parsing/manipulation (e.g., in routing, redirects, or API responses) with a cleaner, type-safe API.Illuminate\Support\Facades\URL and Illuminate\Http\Request already handle URLs, but this package could complement them by offering:
?feature=experimental).config/app.php or a service provider).parse_url(), existing code using parse_url() or filter_var() with FILTER_VALIDATE_URL can be incrementally replaced without breaking changes.url()->current()), the package may introduce unnecessary abstraction. Risk mitigated by documenting when to prefer Laravel’s built-in helpers.parse_url() returns null for invalid URLs). Test thoroughly with:
/path?query=value vs. ?query=value).#section).parse_url() for high-throughput scenarios (e.g., bulk URL processing). The package’s overhead should be negligible for typical use cases.spatie/url, nWidart/ask) that overlap? If so, how does this package differentiate?$uri->withQuery(['key' => 'value'])) align with Laravel’s conventions?parse_url() quirks) without regressions?Redirect, Response, or Route objects)?// Before: Manual string manipulation
return redirect("https://example.com/path?utm_source={$source}");
// After: Using zenstruck/uri
$uri = Uri::create("https://example.com/path")
->withQuery(['utm_source' => $source]);
return redirect($uri->__toString());
Uri::create("/api/users")->withQuery(['page' => 2])).parse_url() call at a time, using the package’s Uri::fromString() or Uri::create().$this->app->bind(Uri::class, function () {
return new Uri();
});
UrlHelper) to wrap the package’s functionality for consistency with Laravel’s URL facade.@deprecated) to mark legacy parse_url() usages for removal.symfony/psr-http-message (if using PSR-7 requests/responses).illuminate/support (for array/string helpers used in URL manipulation).composer.json and publish config (if needed).Uri to the container.parse_url() calls in:
Uri::fromRoute('profile.show', ['user' => 1])).composer.json until the package stabilizes in Laravel’s ecosystem.Uri class to add Laravel-specific methods (e.g., withRouteParams()) if gaps exist.parse_url() entirely over 1–2 releases to avoid technical debt.Uri objects to trace transformations).Uri::create('invalid://url')->getScheme() should throw a descriptive exception).README.Uri objects (though immutability may reduce cache benefits).Uri for URL manipulation").Uri::create()->isValid()).filter_var($url, FILTER_VALIDATE_URL) for critical paths.parse_url() for critical operations.How can I help you explore Laravel packages today?