boson-php/uri-factory
PSR-17 URI factory for Boson PHP. Create and normalize URIs for Boson apps and WebView navigation, with simple Composer installation and docs integrated into the Boson ecosystem. PHP 8.4+ and MIT-licensed.
Url::to(), route(), and action() helpers by offering type safety, composability, and reusability for complex URI scenarios (e.g., multi-tenant, locale-aware, or API-specific URIs)./api/v1/{service}/{resource}). Reduces coupling between services by centralizing URI logic.UriFactory::mock('dashboard')->returns('/mock-path')), which is harder with Laravel’s native helpers.app://, ws://) and non-HTTP protocols (e.g., mailto:, tel:), which Laravel’s routing layer doesn’t natively handle.UriFactory::route()) to mimic Laravel’s Url facade, reducing learning curves.Symfony\Component\HttpFoundation\Request/Response).$uri = UriFactory::make('user.profile', ['id' => 123, 'tab' => 'posts']);
vs. Laravel’s:
route('user.profile', ['id' => 123, 'tab' => 'posts']);
| Risk Area | Assessment |
|---|---|
| Package Maturity | High Risk: 0 stars, no dependents, and minimal documentation. Evaluate via a proof-of-concept before full adoption. |
| Laravel Ecosystem Gap | Low Risk: Fills a niche for custom URI schemes and type-safe construction, but doesn’t replace Laravel’s routing. |
| Performance | Negligible: URI generation is lightweight; risk only if overused for trivial cases (e.g., static /about paths). |
| Testing Overhead | Moderate: May require adjustments to Laravel’s Http\Testing\Mixed assertions (e.g., assertRouteIs()). Test URIs against Laravel’s url() for consistency. |
| Future Laravel Features | Low Risk: Laravel’s URI tools are stable; this package adds optional abstractions. |
| Community Support | High Risk: Limited to a Telegram group. Plan for internal documentation or fork if critical issues arise. |
php artisan route:cache)?Testing facade (e.g., assertRouteIs(), assertRedirects())?illuminate/uri-factory)?config:cache)?Illuminate\Support\Uri without conflicts.UriFactory) to mirror Laravel’s Url facade:
// app/Providers/UriFactoryServiceProvider.php
public function register()
{
$this->app->singleton('uri.factory', function () {
return new \Boson\UriFactory\UriFactory();
});
}
$uri = app('uri.factory')->make('dashboard');
Uri Component: More feature-rich but heavier (~2x larger).route(), url(), string concatenation)./api/v1/users/{id}/posts?limit=10).url() helper using:
dd(
UriFactory::make('dashboard'),
url('dashboard')
);
UriFactory::route('dashboard')).app('helpers')->buildUri()).@deprecated tags to old URI helpers.config/uri.php) to switch between old/new URIs:
'use_factory' => env('URI_USE_FACTORY', false),
| Component | Compatibility Notes |
|---|---|
| Laravel Routing | Works alongside Route::url() but does not handle signed/rate-limited routes (e.g., password resets). Use Laravel’s action() for those cases. |
| Middleware | URIs generated by the factory will pass through Laravel’s middleware pipeline if resolved via route(). For raw URIs, ensure middleware is applied manually (e.g., TrustProxiesMiddleware). |
| Queue Jobs | Safe for delayed URI generation (e.g., password reset links). URIs can be serialized/deserialized via UriFactory::serialize() (if supported). |
| Blade Templates | Use @inject or service container bindings: |
| API Resources | Ideal for dynamic links() in JSON:API responses. Example: |
| PSR-7/HTTP Messages | Supports Psr\Http\Message\UriInterface for integration with frameworks like Symfony’s HTTP components. |
composer require boson-php/uri-factory
AppServiceProvider.http://api.app vs. https://app.com) in config/uri.php.url() for edge cases:
/dashboard vs. /dashboard/).?sort=asc vs. ?sort=desc).php artisan route:list that generated URIs match expected routes.dd() to inspect generated URIs in production-like environments.UriFactory::template('user.profile')).How can I help you explore Laravel packages today?