Skip to content

Commit

Permalink
Add config for yiisoft/config.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 10, 2023
1 parent d82b95e commit c85c779
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ or add

to the require section of your `composer.json` file.

## Configuration
## Usage

To use this extension, you have to configure the Connection class in your application configuration:

```php
use yii\elasticsearch\Connection;

return [
//....
'components' => [
'elasticsearch' => [
'class' => 'yii\elasticsearch\Connection',
'class' => Connection::class,
'nodes' => [
['http_address' => '127.0.0.1:9200'],
// configure more hosts if you have a cluster
Expand All @@ -72,6 +74,19 @@ return [
];
```

### Configure with yiisoft/config

> Add the following code to your `config/config-plugin` file in your application.
```php
'config-plugin' => [
'web' => [
'$yii2-elasticsearch', // add this line
'web/*.php'
],
],
```

## Testing

[Check the documentation testing](/docs/testing.md) to learn about testing.
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
"extra": {
"branch-alias": {
"dev-main": "1.0.x-dev"
},
"config-plugin-options": {
"source-directory": "config"
},
"config-plugin": {
"yii2-elasticsearch": "extension.php"
}
},
"config": {
Expand Down
18 changes: 18 additions & 0 deletions config/extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use yii\elasticsearch\Connection;

/**
* @var array $params
*/
return [
'components' => [
'elasticsearch' => [
'class' => Connection::class,
'nodes' => $params['yii2.elasticsearch.nodes'] ?? [['http_address' => '127.0.0.1:9200']],
'dslVersion' => $params['yii2.elasticsearch.dslVersion'] ?? 7,
],
]
];

0 comments on commit c85c779

Please sign in to comment.