Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Uri Factory Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • URI Abstraction Layer: The package provides a factory-based URI construction pattern, which is a clean abstraction for dynamic URI generation in Laravel. It complements Laravel’s existing 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).
  • Microservices Alignment: Ideal for service-to-service communication where URIs must adhere to strict contracts (e.g., /api/v1/{service}/{resource}). Reduces coupling between services by centralizing URI logic.
  • Testing and Mocking: Enables easier URI mocking in unit tests (e.g., UriFactory::mock('dashboard')->returns('/mock-path')), which is harder with Laravel’s native helpers.
  • Extensibility: Supports custom URI schemes (e.g., app://, ws://) and non-HTTP protocols (e.g., mailto:, tel:), which Laravel’s routing layer doesn’t natively handle.

Integration Feasibility

  • Zero Laravel Core Changes: Can be integrated without modifying Laravel’s routing or service container, making it low-risk.
  • Facade Compatibility: Can be wrapped in a Laravel facade (e.g., UriFactory::route()) to mimic Laravel’s Url facade, reducing learning curves.
  • PSR-7 Adapter: The package mentions PSR-7 compatibility, which aligns with Laravel’s HTTP message handling (e.g., Symfony\Component\HttpFoundation\Request/Response).
  • Dynamic Route Parameters: Supports named arguments (PHP 8.4+) for cleaner syntax:
    $uri = UriFactory::make('user.profile', ['id' => 123, 'tab' => 'posts']);
    
    vs. Laravel’s:
    route('user.profile', ['id' => 123, 'tab' => 'posts']);
    

Technical Risk

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.

Key Questions

  1. Use Case Validation:
    • Are we replacing ad-hoc URI logic (e.g., string concatenation) or custom URI services?
    • Does the team need URI validation (e.g., enforcing path segments or query params via factories)?
  2. Laravel Integration Depth:
    • Will URIs need to integrate with Laravel’s route caching (php artisan route:cache)?
    • Does the package support signed routes or rate-limited redirects (e.g., password resets)?
  3. Testing Strategy:
    • How will this interact with Laravel’s Testing facade (e.g., assertRouteIs(), assertRedirects())?
    • Can URIs be mocked in unit tests without breaking Laravel’s test helpers?
  4. Long-Term Viability:
    • Could this become a core Laravel package (e.g., illuminate/uri-factory)?
    • Is there a risk of duplicate effort with Laravel’s future URI improvements (e.g., PHP 9’s native URI handling)?
  5. Performance Impact:
    • Will URI factories introduce noticeable overhead in high-throughput APIs?
    • Can URI templates be pre-compiled (e.g., during config:cache)?

Integration Approach

Stack Fit

  • PHP 8.4+: Aligns perfectly with Laravel 10+/11’s requirements; no version conflicts.
  • Laravel Compatibility:
    • No Core Modifications: Works alongside Laravel’s Illuminate\Support\Uri without conflicts.
    • Service Provider: Register a facade (e.g., 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();
          });
      }
      
    • Service Container: Bind the factory to Laravel’s IoC:
      $uri = app('uri.factory')->make('dashboard');
      
  • Alternatives:
    • Symfony’s Uri Component: More feature-rich but heavier (~2x larger).
    • Laravel’s Native Tools: Sufficient for 80% of use cases; this package adds optional abstractions.

Migration Path

  1. Assessment Phase:
    • Audit top 10 URI generation points in the codebase (e.g., route(), url(), string concatenation).
    • Identify repetitive patterns (e.g., /api/v1/users/{id}/posts?limit=10).
  2. Pilot Implementation:
    • Replace 3–5 critical URIs (e.g., API client base URLs, email verification links).
    • Compare output with Laravel’s url() helper using:
      dd(
          UriFactory::make('dashboard'),
          url('dashboard')
      );
      
  3. Incremental Rollout:
    • Phase 1: Use for non-routable URIs (e.g., external service endpoints, WebSocket URLs).
    • Phase 2: Extend to internal routes (e.g., UriFactory::route('dashboard')).
    • Phase 3: Replace custom URI logic in services/controllers (e.g., app('helpers')->buildUri()).
  4. Deprecation Strategy:
    • Add @deprecated tags to old URI helpers.
    • Provide a config-based toggle (config/uri.php) to switch between old/new URIs:
      'use_factory' => env('URI_USE_FACTORY', false),
      

Compatibility

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.

Sequencing

  1. Setup:
    • Composer install:
      composer require boson-php/uri-factory
      
    • Publish config (if needed) and bind the factory in AppServiceProvider.
    • Configure default URI schemes (e.g., http://api.app vs. https://app.com) in config/uri.php.
  2. Validation:
    • Test against Laravel’s url() for edge cases:
      • Trailing slashes (/dashboard vs. /dashboard/).
      • Query strings (?sort=asc vs. ?sort=desc).
      • Relative vs. absolute paths.
    • Verify with php artisan route:list that generated URIs match expected routes.
  3. Rollout:
    • Start with non-critical paths (e.g., admin panels, webhooks).
    • Monitor for 404s or redirect loops (common with malformed URIs).
    • Use Laravel’s dd() to inspect generated URIs in production-like environments.
  4. Optimization:
    • Cache frequently used URI templates (e.g., UriFactory::template('user.profile')).
    • Add telemetry to track URI generation
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky