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

Http Factory Implementations Laravel Package

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+.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Decoupling HTTP Factories from Core Dependencies: Enables SDKs, libraries, or microservices to support PSR-17 HTTP factories (e.g., RequestFactory, ResponseFactory) without forcing users to explicitly declare dependencies (e.g., guzzlehttp/psr7, laminas/laminas-diactoros). Reduces friction for developers integrating your product.
  • Testing-Friendly Architecture: Prioritizes mock implementations (e.g., psr-mock/http-factory-implementation) during unit tests, simplifying test setup and isolation. Aligns with CI/CD pipelines requiring zero-config mocking.
  • Multi-Implementation Support: Allows users to "bring their own" PSR-17 implementation (e.g., nyholm/psr7 or zend-diactoros) without breaking compatibility. Critical for products targeting diverse ecosystems (e.g., Laravel, Symfony, standalone PHP).
  • Roadmap for PSR Compliance: Supports future-proofing by adopting PSR-17 standards. Justifies investment in HTTP-related features (e.g., API clients, middleware, or webhooks) with minimal vendor lock-in.
  • Build vs. Buy: Avoids reinventing discovery logic for PSR-17 implementations. Leverages community-maintained solutions to reduce maintenance overhead.
  • Use Cases:
    • SDKs: HTTP client libraries (e.g., for Stripe, Twilio) can auto-detect user-installed PSR-17 factories.
    • Middleware Frameworks: Decouple HTTP message creation from specific libraries (e.g., psr7 vs. diactoros).
    • Testing Utilities: Automatically inject mock factories in test environments.
    • Serverless/Edge Functions: Lightweight discovery for minimal dependencies in cloud-native apps.

When to Consider This Package

  • Adopt When:

    • Your product relies on PSR-17 HTTP factories but wants to avoid hard dependencies on specific implementations (e.g., guzzlehttp/psr7).
    • You’re building a library/SDK where users should control their HTTP stack (e.g., frameworks like Laravel/Symfony may already provide implementations).
    • Testing is a priority, and you need seamless mock injection without manual configuration.
    • You target multi-framework environments (e.g., standalone PHP scripts, Lumen, Swoole) where PSR-17 compatibility is desired.
    • Your team prefers PSR standards to reduce vendor lock-in (e.g., switching from guzzle to nyholm/psr7 should be trivial).
  • Look Elsewhere If:

    • You require a specific PSR-17 implementation (e.g., only laminas/laminas-diactoros is supported). Use the implementation directly instead of discovery.
    • Your project doesn’t use PSR-17 (e.g., relies on raw Guzzle or Symfony HTTP components). No need for abstraction.
    • You need advanced features (e.g., custom factory logic, non-standard HTTP message types) beyond PSR-17. Extend the package or use a dedicated library.
    • Your PHP version is <8.2. This package enforces PHP 8.2+ (as of v1.2.0).
    • You’re building a monolithic app where all dependencies are tightly coupled (e.g., always uses guzzlehttp/psr7). Discovery adds unnecessary complexity.

How to Pitch It (Stakeholders)

For Executives:

"This package lets us build HTTP-dependent features (e.g., API clients, webhooks) without forcing users to adopt specific libraries. For example, a developer using our SDK could already have laminas/laminas-diactoros installed for their framework—our tool would auto-detect and use it, reducing onboarding friction. It also simplifies testing by automatically mocking HTTP factories in CI pipelines, cutting dev time. The MIT license and PHP-FIG alignment ensure long-term stability, while the lightweight design keeps our product’s footprint minimal. This is a low-risk way to future-proof our HTTP infrastructure."

For Engineers:

*"This solves the ‘which PSR-17 library should we depend on?’ problem. Instead of forcing users to add guzzlehttp/psr7 to their projects, we let them use whatever they already have (or none, with graceful fallbacks). Key benefits:

  • Zero-config mocking: Tests automatically use psr-mock/http-factory-implementation if installed.
  • Framework-agnostic: Works in Laravel, Symfony, or standalone PHP.
  • Extensible: Users can prefer() or use() specific implementations via code.
  • Lightweight: ~1KB package with no runtime overhead.

Use case: If we’re building a new API client or middleware layer, this lets us support PSR-17 without bloating dependencies. For example:*

// Auto-detects user’s PSR-17 factory (e.g., from Slim, Laminas, or Guzzle)
$request = Discover::httpRequestFactory()->createRequest('GET', '/api');

No need for if (class_exists(GuzzleHttp\Psr7\Factory\Psr17Factory)) sprawl."

For Architects:

*"This package aligns with our PSR-first strategy and reduces technical debt by:

  1. Decoupling HTTP concerns: Libraries can depend on psr/http-message interfaces, not implementations.
  2. Enabling polyfills: Users can swap guzzlehttp/psr7 for nyholm/psr7 without breaking changes.
  3. Simplifying BDD: Mock factories are prioritized in dev environments, ensuring tests run consistently.
  4. Future-proofing: Supports UploadedFileFactoryInterface and UriFactoryInterface (added in v1.1.0), covering more PSR-17 use cases.

Tradeoff: Adds a minor abstraction layer, but the benefits for maintainability and user flexibility outweigh the cost. Recommended for any HTTP-related feature where implementation agnosticism is valuable."*

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.
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
spatie/mailcoach-vapor