- How do I install GuzzleFactory in a Laravel project?
- Run `composer require graham-campbell/guzzle-factory` to install. No additional Laravel-specific setup is needed beyond requiring the package. It works with Laravel 9–11 and PHP 7.4–8.5 out of the box.
- Can I use GuzzleFactory with Laravel’s service container?
- Yes. Bind it as a singleton in your `AppServiceProvider` or resolve dynamically via `app(GuzzleFactory::class)`. This enables dependency injection into controllers, jobs, or commands for cleaner architecture.
- What are the default security settings for Guzzle clients created by this factory?
- The factory enforces TLS 1.2+ by default and includes sensible retry policies. You can override these via config or factory arguments, but the defaults align with PCI DSS, GDPR, and HIPAA compliance.
- How do I configure multiple API clients (e.g., Stripe, PayPal) with different settings?
- Centralize configurations in `config/services.php` and pass the relevant config array to `GuzzleFactory::make()`. For example, use `'stripe' => ['base_uri' => 'https://api.stripe.com', 'auth' => [env('STRIPE_KEY'), '']]` for Stripe-specific clients.
- Does GuzzleFactory support custom middleware like logging or caching?
- Yes. Use `makeWithHandler()` (v4.2+) to inject custom middleware stacks. For example, add Laravel’s caching middleware or logging middleware by passing a closure that modifies the `HandlerStack`.
- Is GuzzleFactory compatible with Laravel’s HTTP client facade or caching middleware?
- No, it’s not a drop-in replacement for Laravel’s HTTP facade. However, you can integrate it with Laravel’s caching middleware by using `makeWithHandler()` to inject the caching stack manually.
- How do I mock GuzzleFactory in PHPUnit tests?
- Use Laravel’s service container to mock the factory: `$this->app->instance(GuzzleFactory::class, Mockery::mock(GuzzleFactory::class));`. This allows you to stub responses or verify client configurations in unit tests.
- What Laravel versions and PHP versions does GuzzleFactory support?
- GuzzleFactory supports PHP 7.4–8.5 and integrates seamlessly with Laravel 9–11. It’s compatible with Laravel’s default Guzzle 7+ and avoids version conflicts.
- Does GuzzleFactory add significant overhead to my application?
- No, the package adds minimal overhead (~1MB for Guzzle) and is optimized for simplicity. It’s ideal for most Laravel apps, though high-performance scenarios (e.g., >10K requests/sec) may require raw Guzzle or Symfony’s HttpClient.
- What if I need connection pooling or gRPC support?
- GuzzleFactory doesn’t support connection pooling or gRPC out of the box. For these use cases, consider using raw Guzzle middleware or Symfony’s HttpClient, which offers more advanced features like connection pooling.