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

Swap usage of ClientInterface instead of Client #10

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ return [
If you need more control over the client creation, you can create your own client builder:

```php
// see Elastic\Client\ClientBuilder for the reference
class MyClientBuilder implements Elastic\Client\ClientBuilderInterface
use Elastic\Elasticsearch\ClientInterface;
use Elastic\Client\ClientBuilderInterface;

class MyClientBuilder implements ClientBuilderInterface
{
public function default(): Client
public function default(): ClientInterface
{
// should return a client instance for the default connection
}

public function connection(string $name): Client
public function connection(string $name): ClientInterface
{
// should return a client instance for the connection with the given name
}
Expand All @@ -109,7 +111,7 @@ Use `Elastic\Client\ClientBuilderInterface` to get access to the client instance
```php
namespace App\Console\Commands;

use Elastic\Elasticsearch\Client;
use Elastic\Elasticsearch\ClientInterface;
use Elastic\Client\ClientBuilderInterface;
use Illuminate\Console\Command;

Expand Down
6 changes: 3 additions & 3 deletions src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Elastic\Client;

use Elastic\Elasticsearch\Client;
use Elastic\Elasticsearch\ClientInterface;
use Elastic\Elasticsearch\ClientBuilder as BaseClientBuilder;
use ErrorException;

class ClientBuilder implements ClientBuilderInterface
{
protected array $cache;

public function default(): Client
public function default(): ClientInterface
{
$name = config('elastic.client.default');

Expand All @@ -21,7 +21,7 @@ public function default(): Client
return $this->connection($name);
}

public function connection(string $name): Client
public function connection(string $name): ClientInterface
{
if (isset($this->cache[$name])) {
return $this->cache[$name];
Expand Down
6 changes: 3 additions & 3 deletions src/ClientBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Elastic\Client;

use Elastic\Elasticsearch\Client;
use Elastic\Elasticsearch\ClientInterface;

interface ClientBuilderInterface
{
public function default(): Client;
public function default(): ClientInterface;

public function connection(string $name): Client;
public function connection(string $name): ClientInterface;
}
4 changes: 2 additions & 2 deletions tests/Unit/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Elastic\Client\Tests\Unit;

use Elastic\Client\ClientBuilder;
use Elastic\Elasticsearch\Client;
use Elastic\Elasticsearch\ClientInterface;
use ErrorException;
use Orchestra\Testbench\TestCase;

Expand Down Expand Up @@ -51,7 +51,7 @@ public function test_exception_is_thrown_when_building_client_with_non_existing_
$this->clientBuilder->connection('foo');
}

private function assertHost(Client $client, string $host): void
private function assertHost(ClientInterface $client, string $host): void
{
$transport = $client->getTransport();
$node = $transport->getNodePool()->nextNode();
Expand Down
Loading