Replies: 1 comment
{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
HTTP client PSR is 18, not 7: https://www.php-fig.org/psr/psr-18/
Well, so it’s not any client! Ideally, your library should depend on
That way you don’t force implementations upon the library’s consumers. If you want to use Symfony HTTP Client, it will be your application’s responsibility, not the library’s.
You should use dependency injection. That way you’re in full control of which dependencies your services get; which typically allows to pass mocks when testing. As you will need to refactor either way, I really recommend you to follow this path as it will be a great learning opportunity. |
Beta Was this translation helpful? Give feedback.
{{title}}
-
I recently forked a library that makes API calls to wikidata.org, the original library appears to be abandoned and was using a deprecated package, which was preventing the application from upgrading to Symfony 7. I've fixed that, and would like to also replace the dependency on Guzzle. Ideally, it should be any PSR-7 client, I would like to use Symfony so I get all the bonuses like automatic retry and integration with the debug toolbar.
The main class instantiates an ApiClient:
https://github.com/survos/wikidata/blob/master/src/Wikidata.php#L22-L24
The ApiClient uses the Guzzle Client
I thought it'd be easy to swap out one for the other, but I got stuck quickly.
There are a lot of libraries out there that require guzzle to make API calls, but the better way is say something like
https://github.com/meilisearch/meilisearch-php?tab=readme-ov-file#-installation
I've been using the meili library as a model for how to do this, but am a bit stuck and looking for some guidance on an easier way.
At this point, I'd even be okay with requiring the Symfony client. I still struggle with Mocks and testing, but maybe there are modern solutions to that as well. Pest looks pretty interesting, for example.
Since this is not my main focus, I really just want to fetch some wikidata from a Symfony 7 app (which I can do now), using the Symfony client is just a bonus. So again, looking for an easy way to drop guzzle and using symfony.
Any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions