jord-jd/psr-18-guzzle-adapter
Simple PSR-18 adapter for the Guzzle HTTP client, letting you use Guzzle wherever a PSR-18 (ClientInterface) implementation is required. Lightweight, focused package for bridging PSR-compliant libraries with Guzzle.
spatie/laravel-http-client.ClientInterface (e.g., with Mockery or PHPUnit), isolating HTTP dependencies from business logic.Http client for mixed-stack applications.Http facade or create a dedicated PSR-18 facade (e.g., Psr18::get()) for consistency.MessageFactoryInterface) support may require manual handling of request/response creation in some edge cases.TransferStats) are exposed via PSR-18. Teams relying on these may need custom wrappers or middleware.Http client (e.g., duplicate bindings). Requires clear naming conventions (e.g., psr18.client vs. http.client).getGuzzleClient() method in the adapter for unsupported use cases.php-http/guzzle7-adapter) in the future?Http client entirely, or coexist with it (e.g., for legacy code)?GuzzleHttp\Client) be updated to use ClientInterface?Http client middleware)?$this->app->bind(\Psr\Http\Client\ClientInterface::class, function ($app) {
return new GuzzleAdapter(
new \GuzzleHttp\Client($app['config']['http.client'])
);
});
config/http.php to include PSR-18-specific settings (e.g., default options, middleware).Psr18) to mirror Laravel’s Http facade:
facade_root('Psr18', 'App\Facades\Psr18Facade');
// App\Facades\Psr18Facade.php
public static function get($uri, array $options = [])
{
return app(\Psr\Http\Client\ClientInterface::class)
->sendRequest(new \GuzzleHttp\Psr7\Request('GET', $uri, [], $options));
}
grep or static analysis tools like PHPStan).AppServiceProvider and update constructors/services to accept ClientInterface.
// Before
public function __construct(GuzzleHttp\Client $client) { ... }
// After
public function __construct(\Psr\Http\Client\ClientInterface $client) { ... }
$client->request()) with PSR-18 equivalents (e.g., $client->sendRequest()).
Use IDE refactoring tools (e.g., PHPStorm’s "Rename" or "Change Signature") to automate this.// Guzzle Middleware (Before)
$stack->push(Middleware::retry($retryConfig));
// PSR-15 Middleware (After)
$handler = new \League\Pipeline\Pipeline([
new RetryMiddleware($retryConfig),
]);
ClientInterface mocks:
// Before
$mock = $this->createMock(GuzzleHttp\Client::class);
// After
$mock = $this->createMock(\Psr\Http\Client\ClientInterface::class);
public function getGuzzleClient(): GuzzleHttp\Client
{
return $this->adapter->getClient();
}
deprecated() helper.onPrepare vs. PSR-15).^8.0) to avoid surprises.ClientInterface, RequestInterface, and ResponseInterface.MessageFactoryInterface) support. Workaround:
use GuzzleHttp\Psr7\Factory\Psr17Factory;
$request = (new Psr17Factory())->createRequest('GET', 'https://example.com');
Http client can coexist if bound to different container keys (e.g., psr18.client vs. http.client).Illuminate\Pipeline\Pipeline).How can I help you explore Laravel packages today?