Skip to content

Commit

Permalink
Code: reflect v8
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 15, 2023
1 parent 1598207 commit 6bc66a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
16 changes: 1 addition & 15 deletions .docs/README.md
Expand Up @@ -26,21 +26,7 @@ extensions:

```neon
elasticsearch:
hosts:
- 'localhost'
```

### Advanced configuration

```neon
elasticsearch:
hosts:
-
host: 'localhost'
port: 9200
scheme: 'https'
user: 'foo'
pass: 'bar'
hosts: [localhost:9200]
```

**NOTE:** The `host` is required, others are recommended, but not necessary.
22 changes: 5 additions & 17 deletions src/DI/ElasticsearchExtension.php
Expand Up @@ -2,42 +2,30 @@

namespace Contributte\Elasticsearch\DI;

use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;
use Elastic\Elasticsearch\Client;
use Elastic\Elasticsearch\ClientBuilder;
use Nette\DI\CompilerExtension;
use Nette\DI\Definitions\Statement;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use stdClass;

/**
* @property-read stdClass $config
* @method stdClass getConfig()
*/
class ElasticsearchExtension extends CompilerExtension
{

public function getConfigSchema(): Schema
{
return Expect::structure([
'hosts' => Expect::arrayOf(Expect::anyOf(
Expect::string(),
Expect::type(Statement::class),
Expect::structure([
'host' => Expect::anyOf(Expect::string(), Expect::type(Statement::class))->required(),
'port' => Expect::anyOf(Expect::int(), Expect::type(Statement::class)),
'scheme' => Expect::anyOf(Expect::string(), Expect::type(Statement::class)),
'path' => Expect::anyOf(Expect::string(), Expect::type(Statement::class)),
'user' => Expect::anyOf(Expect::string(), Expect::type(Statement::class)),
'pass' => Expect::anyOf(Expect::string(), Expect::type(Statement::class)),
])->castTo('array')
))->required()->min(1),
'hosts' => Expect::arrayOf('string')->required(),
'retries' => Expect::int(1),
]);
}

public function beforeCompile(): void
{
$config = $this->config;
$config = $this->getConfig();
$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('client'))
Expand Down

0 comments on commit 6bc66a8

Please sign in to comment.