psr-discovery/http-factory-implementations
Discovers a PSR-17 HTTP factory at runtime by scanning for well-known implementations and returning the first available instance. Ideal for libraries/SDKs that want PSR-17 support without hard dependencies or user configuration. PHP 8.2+.
symfony/http-foundation for Request/Response in Laravel). It abstracts implementation details, reducing coupling to specific libraries like Guzzle or Slim.HttpClient and Illuminate\Http abstractions.symfony/http-foundation for Request/Response) will be auto-discovered.Illuminate\Http\Request/Response already implement PSR-17 interfaces, so this package can coexist without breaking existing code.psr-mock/http-factory-implementation) integrate seamlessly with Laravel’s testing tools (e.g., Mockery, PHPUnit).null. Mitigation:
nyholm/psr7) as a dev dependency.bootstrap check in config/app.php to enforce required packages.Discover::httpRequestFactory(singleton: true)) should be used in Laravel’s service container to avoid redundant instantiation.guzzlehttp/psr7) have version constraints. Laravel’s composer.json must align with the package’s supported ranges (e.g., ^2.0 for Guzzle PSR7).nyholm/psr7 for performance) or rely on auto-discovery?HttpClient (PSR-18) and Illuminate\Http layers?createMock(RequestFactoryInterface))?bindIf)?symfony/http-foundation) if they are deprecated in favor of this package?Illuminate\Http\Request/Response (PSR-17 compatible).Illuminate\Http\UploadedFile (PSR-7 UploadedFileInterface).Illuminate\Support\Facades\Request (can delegate factory creation).HttpClient (PSR-18) can use this package to resolve PSR-17 factories for request/response handling.laravel/pint or phpunit can leverage mock implementations for isolated testing.composer require --dev psr-discovery/http-factory-implementations).Discover::httpRequestFactory() in new features (e.g., plugins, SDKs) to avoid hardcoding dependencies.// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bindIf(
RequestFactoryInterface::class,
fn() => Discover::httpRequestFactory() ?? new Nyholm\Psr7\Factory\Psr17Factory()
);
}
GuzzleHttp\Psr7\Factory\Psr17Factory with discovered instances.null allows graceful degradation.v1.1.1 (PHP 8.1 support).guzzlehttp/guzzle may pull in guzzlehttp/psr7. Ensure version constraints are compatible (e.g., ^2.0).symfony/http-foundation is not auto-discovered (not in the package’s list). Explicitly prefer it if needed:
RequestFactories::prefer('symfony/http-foundation');
composer require --dev psr-discovery/http-factory-implementations
composer.json:
nyholm/psr7) as dev dependencies if none exist."require-dev": {
"nyholm/psr7": "^1.0",
"psr-mock/http-factory-implementation": "^1.0"
}
app/Providers to handle null returns.symfony/http-client if it gains PSR-17 support).composer why-not psr-discovery/http-factory-implementations).Discover::httpRequestFactory() returning null).$this->app->singleton(RequestFactoryInterface::class, fn() => Discover::httpRequestFactory(singleton: true));
new GuzzleHttp\Psr7\Factory\Psr17Factory()).| Scenario | Impact | Mitigation Strategy |
|---|---|---|
| No PSR-17 implementations installed | null returns, broken functionality |
Enforce required dev dependencies via composer.json. |
| Version conflicts | Runtime errors (e.g., method not found) | Pin compatible versions in composer.json. |
| Mock implementations missing | Tests fail | Add psr-mock/http-factory-implementation as a test dependency. |
| Singleton misconfiguration | Memory leaks or stale instances | Use singleton: true explicitly in container bindings. |
How can I help you explore Laravel packages today?