Pros:
symfony/http-client, Guzzle, or custom implementations).Cons:
symfony/http-client (recommended PSR-18 implementation).illuminate/http-client (v9+) implements PSR-18; PSR-17 can be added via php-http/message-factory.ContainerAware traits or using Laravel’s DI container.ParameterBag).symfony/http-client) are updated, backward compatibility may break.json_encode, parse_str), which may behave differently across PHP versions.Why Symfony-Specific?
laravel-http-client-transformers)?Resilience Requirements
PSR Implementation Lock-In
symfony/http-client), or is flexibility needed?Configuration Management
Alternatives Evaluation
Http::macro) or Guzzle (with middleware) achieve the same goals with lower risk?nelmio/api-client-bundle) with broader adoption?| Component | Fit Level | Notes |
|---|---|---|
| Symfony 5+ | Excellent | Designed for Symfony’s DI container and configuration system. |
| Laravel | Poor | Framework-specific assumptions (e.g., ParameterBag) require significant refactoring. |
| PSR-17/18 | Excellent | Agnostic to client implementation (e.g., symfony/http-client, Guzzle). |
| PHP 8.0+ | Good | Relies on modern PHP features (e.g., named arguments, attributes). |
composer require dormilich/http-client-bundle symfony/http-client php-http/message-factory
# config/packages/dormilich_http_client.yaml
dormilich_http_client:
encoder:
url: php
decoder:
json: !php/const JSON_OBJECT_AS_ARRAY
services:
App\Client\CustomClient:
tags: ['dormilich.http_client']
use Psr\Http\Client\ClientInterface;
class MyService {
public function __construct(private ClientInterface $client) {}
}
JsonEncoder, UrlEncoder, etc.) into a Laravel package.ParameterBagInterface) with Laravel’s Container or standalone implementations.class HttpClientTransformersServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton(JsonEncoder::class, fn() => new JsonEncoder(JSON_OBJECT_AS_ARRAY));
// Register other transformers...
}
}
Http::macro('withTransformers', function () use ($app) {
$client = $app->make(ClientInterface::class); // PSR-18 client
// Apply transformers...
return $client;
});
Http::macro('json', function ($url, $data = []) {
return Http::withOptions(['transformers' => [JsonEncoder::class]])->post($url, $data);
});
$client = new Client([
'handler' => HandlerStack::create([
new JsonTransformerMiddleware(),
]),
]);
symfony/http-client).symfony/http-client (actively maintained).symfony/http-client changes behavior).How can I help you explore Laravel packages today?