Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Elasticsearch contract instead of concrete class in constructor #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

floristenhove
Copy link
Contributor

@floristenhove floristenhove commented Oct 24, 2024

For service containers to correctly handle dependency injection we should pass the interface instead of the concrete implementation of the Elasticsearch PHP Client.

@boserup
Copy link

boserup commented Nov 11, 2024

This is also useful when testing. See elastic/elasticsearch-php#1227

@bram-pkg
Copy link
Collaborator

bram-pkg commented Nov 11, 2024

I appreciate this is useful, but I believe this would be a breaking change.

People that dependency inject a bound version of the "Client" class will have to update the container binding to bind this interface to a client implementation now.

An example in Laravel would be:

app()->bind(Client::class, function (): Client {
    // create configured client here
});

// this would now break, if Builder is changed to have `ClientInterface` as the typehint.
app(Builder::class)->index('my-index')->search();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants