phrity/net-uri
Lightweight PSR-7 UriInterface and PSR-17 UriFactory implementation not tied to HTTP messaging. Supports any valid scheme plus helpful extras like query item helpers, component access, equals/string/json support, and immutable with* methods.
mailto:, ftp:, or custom schemes like app://). This is particularly useful for Laravel applications interacting with diverse systems (e.g., CLI tools, microservices with custom protocols, or integrations with non-web services).with*() methods align with Laravel’s functional programming patterns (e.g., middleware chains, request pipelines), ensuring thread safety and predictable state management.withQueryItems(), getQueryItem(), withComponents()) simplify these operations, reducing boilerplate in Laravel’s route definitions or request validation logic.Symfony\Component\HttpFoundation\Url or GuzzleHttp\Psr7\Uri) in custom HTTP logic. For example:
Phrity\Net\Uri in middleware to parse or modify request URIs.URL::to() with UriFactory::createUri() for generating canonical URIs in API responses.Phrity\Net\UriFactory as a PSR-17-compliant factory, ensuring consistency across URI creation. This is particularly useful in Laravel’s service container for dependency injection.use Phrity\Net\Uri;
$uri = new Uri(request()->getUri());
$queryParams = $uri->getQueryItems(); // Directly access query params
IDN_ENCODE, IDN_DECODE), ensuring compatibility with non-ASCII domains (e.g., ηßöø必Дあ.com).Validator facade to validate URIs before processing.REQUIRE_PORT, NORMALIZE_PATH) introduces minor overhead. Mitigation:
replace directive to avoid conflicts:
"replace": {
"psr/http-message": "phrity/net-uri"
}
config/app.php to override Laravel’s default bindings.config/app.php enforces PHP 8.1+ compatibility.Uri, Guzzle’s Uri) do not? For example:
URL helper.URL::to()) need updates?Phrity\Net\Uri with Laravel’s HttpTests or custom feature tests.symfony/http-foundation)? Will there be conflicts in the service container?composer why-not phrity/net-uri and composer why symfony/http-foundation.URL helper changes) and adjust integration accordingly.Symfony\Component\HttpFoundation\Url or GuzzleHttp\Psr7\Uri in custom middleware to parse or modify URIs. For example:
public function handle($request, Closure $next) {
$uri = new Phrity\Net\Uri($request->getUri());
// Modify URI (e.g., add query params, normalize path)
$request = $request->withUri($uri);
return $next($request);
}
Phrity\Net\Uri in route definitions for dynamic URI handling. For example:
Route::get('/search', function (Phrity\Net\Uri $uri) {
$queryParams = $uri->getQueryItems();
// Process query params
});
Phrity\Net\UriFactory as the default PSR-17 factory in Laravel’s service container. Update config/app.php:
'bindings' => [
Psr\Http\Message\UriInterface::class => function ($app) {
return (new Phrity\Net\UriFactory())->createUri('');
},
],
$client = new GuzzleHttp\Client([
'base_uri' => (new Phrity\Net\UriFactory())->createUri('https://api.example.com'),
]);
FormRequest or API resource validation. For example:
public function rules() {
$uri = new Phrity\Net\Uri($this->request->getUri());
$queryParams = $uri->getQueryItems();
return [
'query_param' => 'required|string',
// Custom validation logic based on $queryParams
];
}
$uri = new Phrity\Net\Uri('https://ηßöø必Дあ.com');
$encodedHost = $uri->getHost(Phrity\Net\Uri::IDN_ENCODE);
Phrity\Net\Uri.Symfony\Component\HttpFoundation\Url or GuzzleHttp\Psr7\Uri in middleware, controllers, or services.Phrity\Net\UriFactory as the default PSR-17 factory.request()->query() with `Phrity\Net\UriHow can I help you explore Laravel packages today?