Skip to content

Commit b562c0e

Browse files
tg666f3l1x
authored andcommitted
Client configuration (#4)
- added dependency on package `nette/schema` - fixed structure of config schema for the compiler extension `ElasticaExtension` - removed an option `compression` (the option is not defined in `ClientConfiguration` class) - removed an option `log` (the option has been removed in version `7.0`) - added an option `auth_type` - updated examples in README - options for the default (root) client and also options under a key `connections` are strictly defined in a configuration schema - updated the configuration keys in README
1 parent 9474135 commit b562c0e

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
lines changed

.docs/README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,33 @@ Define at least one host, this would be minimal possible config.
2929

3030
```neon
3131
elastica:
32-
hosts:
33-
es01:
34-
host: localhost
32+
config:
33+
host: localhost
3534
```
3635

3736
Full config
3837
```neon
3938
elastica:
4039
debug: %debugMode%
41-
hosts:
42-
es01:
40+
config:
4341
host: null
4442
port: null
45-
username: null
46-
password: null
4743
path: null
4844
url: null
4945
proxy: null
50-
persistent: null
46+
transport: null
47+
compression: false
48+
persistent: true
5149
timeout: null
52-
connections: null
50+
connections: []
5351
roundRobin: null
54-
log: null
55-
retryOnConflict: null
52+
retryOnConflict: 0
5653
bigintConversion: null
54+
username: null
55+
password: null
56+
auth_type: null
57+
curl: []
58+
headers: []
5759
```
5860
Extension does not pass any unset values to elastica so elastica defaults just work.
5961
Take a look to [Elastica docs](https://elastica-docs.readthedocs.io/en/latest/client.html#client-configurations).

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"phpstan/phpstan-nette": "^1.0",
3636
"phpstan/phpstan-strict-rules": "^1.0"
3737
},
38+
"conflict": {
39+
"nette/schema": "<1.2.0"
40+
},
3841
"autoload": {
3942
"psr-4": {
4043
"Contributte\\Elastica\\": "src/"

src/DI/ElasticaExtension.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,37 @@ class ElasticaExtension extends CompilerExtension
2020

2121
public function getConfigSchema(): Schema
2222
{
23-
// https://elastica-docs.readthedocs.io/en/latest/client.html#client-configurations
23+
// https://github.com/ruflin/Elastica/blob/master/src/ClientConfiguration.php#L26
24+
$clientConfig = [
25+
'host' => Expect::string()->nullable()->dynamic(),
26+
'port' => Expect::int()->nullable()->dynamic(),
27+
'path' => Expect::string()->nullable(),
28+
'url' => Expect::string()->nullable(),
29+
'proxy' => Expect::string()->nullable(),
30+
'transport' => Expect::string()->nullable(),
31+
'compression' => Expect::bool(),
32+
'persistent' => Expect::bool(),
33+
'timeout' => Expect::int()->nullable(),
34+
'retryOnConflict' => Expect::int(),
35+
'bigintConversion' => Expect::bool(),
36+
'username' => Expect::string()->nullable()->dynamic(),
37+
'password' => Expect::string()->nullable()->dynamic(),
38+
'auth_type' => Expect::anyOf('basic', 'digest', 'gssnegotiate', 'ntlm')->nullable()->dynamic(),
39+
'curl' => Expect::arrayOf('mixed', 'int'),
40+
'headers' => Expect::arrayOf('string', 'string'),
41+
];
42+
2443
return Expect::structure([
2544
'debug' => Expect::bool(false),
26-
'hosts' => Expect::arrayOf(
27-
Expect::structure([
28-
'port' => Expect::int(),
29-
'path' => Expect::string(),
30-
'host' => Expect::string(),
31-
'url' => Expect::string(),
32-
'proxy' => Expect::string(),
33-
'transport' => Expect::string(),
34-
'persistent' => Expect::bool(),
35-
'timeout' => Expect::int(),
36-
'connections' => Expect::array(),
45+
'config' => Expect::structure(array_merge(
46+
$clientConfig,
47+
[
48+
'connections' => Expect::arrayOf(
49+
Expect::structure($clientConfig)->skipDefaults()->castTo('array')
50+
),
3751
'roundRobin' => Expect::bool(),
38-
'compression' => Expect::bool(),
39-
'log' => Expect::anyOf(Expect::bool(), Expect::string()),
40-
'retryOnConflict' => Expect::int(),
41-
'bigintConversion' => Expect::bool(),
42-
'username' => Expect::string(),
43-
'password' => Expect::string(),
44-
])->castTo('array')
45-
),
52+
]
53+
))->skipDefaults()->castTo('array'),
4654
]);
4755
}
4856

@@ -52,7 +60,7 @@ public function loadConfiguration(): void
5260
$builder = $this->getContainerBuilder();
5361

5462
$elastica = $builder->addDefinition($this->prefix('client'))
55-
->setFactory(ContributteClient::class, [$this->config->hosts]);
63+
->setFactory(ContributteClient::class, [$this->config->config]);
5664

5765
if ($this->config->debug) {
5866
$builder->addDefinition($this->prefix('panel'))

0 commit comments

Comments
 (0)