feat(clickhouse): accept any PSR-18 client in adapter constructor#13
Merged
Conversation
Widen the ClickHouse adapter's $client parameter from the concrete Utopia\Client to the PSR-18 ClientInterface. The adapter only ever calls sendRequest() on the transport, so the narrower type was unnecessary and blocked passing a Utopia\Client\Pool — which is a ClientInterface but not a Utopia\Client — to share a bounded set of connections across concurrent coroutine callers (the default single-handle cURL client is not coroutine-safe when the adapter is shared). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR widens the ClickHouse adapter transport type to accept any PSR-18 client. The main changes are:
Confidence Score: 5/5The change is narrowly scoped and merge-safe. The adapter continues to use only the PSR-18 sendRequest contract, while the default transport behavior remains unchanged for existing callers.
What T-Rex did
Reviews (1): Last reviewed commit: "feat(clickhouse): accept any PSR-18 clie..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Widens the
ClickHouseadapter's$clientconstructor parameter (and the backing property) from the concreteUtopia\Clientto the PSR-18Psr\Http\Client\ClientInterface.Why
The adapter only ever calls
sendRequest()on the injected transport, so requiring the concreteUtopia\Clientwas stricter than necessary — and it blocked a real use case.In a Swoole-coroutine server, the default transport (a cURL client with
withConnectionReuse()) keeps a singleCurlHandleon the instance. When the adapter is shared as a singleton across concurrent coroutines, that one handle gets clobbered by concurrent requests — it is not coroutine-safe.The fix for that is
Utopia\Client\Pool, which borrows a client from a bounded pool per request and reclaims it. ButPoolimplementsClientInterface/StreamingClientInterface— it is not aUtopia\Client— so it could not be passed in. Widening toClientInterfaceunblocks it:The default still constructs the same cURL-backed
Utopia\Client, so existing callers are unaffected.Notes
psr/http-clientas an explicit dependency (previously only transitive viautopia-php/client), since the source now references it directly.composer check(PHPStan max) andpintpass; unit tests green.🤖 Generated with Claude Code