-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Proposal for NullClient #319
Comments
Would you mind explaining advantage of following in algolia_search:
http_client: 'App\Client\NullClient' over doing following in services:
algolia.http_client: 'App\Client\NullClient' I don't see it. Anyways, doing algolia/algoliasearch-client-php#596 is a prerequisite to do either of these, otherwise where would you put |
@ostrolucky It's just to have a dedicated As for the call to |
Services are not available in that file, only their definitions. And I don't know how would you prepare definition for random static call. Result of this call is not a service, so it can't be service definition. Hence I think we should do this properly, inject correct stuff from beginning and not rely on
It doesn't make much difference for user, but does make difference for bundle maintainers, as new configuration requires maintainance of extra code. As for userland, it is slightly more clear, but IMHO it makes more sense to teach users how to override services for specific environment, which is universal for any bundle, without having to rely on bundle maintainers to provide options and is pretty easy in Symfony, just not very well known. Heck, you don't even need extra services file, user can just as well put services:
algolia.http_client: 'App\Client\NullClient' to |
And so where would you put the call to setup Algolia with its new client? |
This needs to be split into more services search-bundle/src/Resources/config/services.xml Lines 18 to 22 in 7b02cea
create factory method.
Following is what is currently required from userspace to do - that's the wiring difficulty I was talking in #317 (comment) <service id="AppBundle\Test\Algolia\TestClient" />
<service id="Algolia\AlgoliaSearch\Config\SearchConfig" />
<service id="search.client" class="Algolia\AlgoliaSearch\SearchClient" public="true" lazy="true">
<argument type="service">
<service class="Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper">
<argument id="AppBundle\Test\Algolia\TestClient" type="service"/>
<argument id="Algolia\AlgoliaSearch\Config\SearchConfig" type="service" />
<argument type="service">
<service class="Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts">
<factory class="Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts" method="createFromAppId" />
<argument> </argument>
</service>
</argument>
</service>
</argument>
<argument id="Algolia\AlgoliaSearch\Config\SearchConfig" />
</service> Goal is for bundle to define http client service, so userspace needs to override just that one, instead of whole chain of dependencies, as user currently needs to override |
Okay, I see what you want to achieve and while this is not a bad idea, I think we're drifting away from our initial implementation. Plus I don't want to update the PHP Client to achieve this particular need for the Symfony integration. @ostrolucky you were really helpful in here and thanks a lot for all your ideas and suggestions! Please keep on sharing your thoughts with us. I'm closing this issue. |
See #320 |
Several conversations have been around about how to handle during development or test the calls made to Algolia.
After some thoughts the solution I propose would be to have a new settings in the
algolia_search
parameters that would behttp_client
. This would give the opportunity for the customer to pass any requester they like, including aNullClient
, and solve the issue of Algolia calls on the lowest level.Based on a
NullClient
written by @ostrolucky in this issue, I came up with an example client that handles roughly the expected response formats:and the config would be as follow:
IMHO, the drawbacks of the different other solutions were as follow:
NullSearchService
: too much code duplication to handle the communication with DBNullEngine
: the bundle would not be Engine-agnostic anymore, which is not what we wanted.ClusterHosts
as proposed in #596 : the ApiWrapper shouldn't rely on the bundle config. Moreover, Algolia::setHttpClient already lets you set a new http client, so I'm not sure what are the advantages of wanting to set a whole newClient
with a whole newApiWrapper
.WDYT?
The text was updated successfully, but these errors were encountered: