From c85c779f84bb555176771200bbbcdb1349630dd8 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 10 Nov 2023 19:02:03 -0300 Subject: [PATCH] Add `config` for `yiisoft/config`. --- README.md | 19 +++++++++++++++++-- composer.json | 6 ++++++ config/extension.php | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 config/extension.php diff --git a/README.md b/README.md index e3e3d1c..506723f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/composer.json b/composer.json index ca988ce..7879cff 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/config/extension.php b/config/extension.php new file mode 100644 index 0000000..ba2c6fb --- /dev/null +++ b/config/extension.php @@ -0,0 +1,18 @@ + [ + 'elasticsearch' => [ + 'class' => Connection::class, + 'nodes' => $params['yii2.elasticsearch.nodes'] ?? [['http_address' => '127.0.0.1:9200']], + 'dslVersion' => $params['yii2.elasticsearch.dslVersion'] ?? 7, + ], + ] +];