Skip to content

Commit 522f7b8

Browse files
committed
Cleanup the way handlers work
1 parent bdf1efc commit 522f7b8

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

config/hunt.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@
2121
],
2222

2323
'retries' => 1,
24+
25+
'handler' => null,
2426
],
2527

2628
/*
2729
|--------------------------------------------------------------------------
28-
| Amazon Elasticsearch Service
30+
| Handlers
2931
|--------------------------------------------------------------------------
3032
|
31-
| Sign all requests made to AWS by simply setting up the config with your
32-
| AWS settings like the following.
33-
|
34-
| 'aws_config' => [
35-
| 'key' => env('AWS_KEY'),
36-
| 'secret' => env('AWS_SECRET'),
37-
| 'region' => env('AWS_REGION'),
38-
| ],
33+
| Use this to handle certain aspects of a Elasticsearch request.
3934
|
4035
*/
4136

42-
'aws_config' => null,
37+
'handlers' => [
38+
'aws' => [
39+
'class' => \LaravelHunt\Handlers\AwsSignature::class,
40+
'key' => env('AWS_KEY'),
41+
'secret' => env('AWS_SECRET'),
42+
'region' => env('AWS_REGION', 'us-east-1'),
43+
],
44+
],
4345

4446
/*
4547
|--------------------------------------------------------------------------

src/Hunter.php

+27-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ public function __construct(array $config = [])
4545
$this->config = $config;
4646
$this->multilingual = $this->config('multilingual', false);
4747

48-
// AWS Elasticsearch enabled
49-
if ($aws = $this->config('aws_config', null)) {
50-
$this->config['config']['handler'] = new AwsSignature($aws);
51-
}
52-
53-
$this->elasticsearch = ClientBuilder::fromConfig($this->config('config'));
48+
$this->elasticsearch = ClientBuilder::fromConfig($this->getElasticSearchConfig());
5449
}
5550

5651
/**
@@ -646,4 +641,30 @@ public function getIndexName()
646641
{
647642
return $this->config('index', 'default');
648643
}
644+
645+
/**
646+
* Get Elasticsearch settings.
647+
*
648+
* @return array
649+
*/
650+
protected function getElasticSearchConfig()
651+
{
652+
// Get all settings
653+
$settings = $this->config('config');
654+
655+
// Get a handler if one is set
656+
if ($config = $this->config('handlers.' . $this->config('config.handler'), null)) {
657+
658+
// Get handler class
659+
$handler = Arr::pull($config, 'class');
660+
661+
// Create handler instance
662+
$settings['handler'] = new $handler($config);
663+
}
664+
else {
665+
unset($settings['handler']);
666+
}
667+
668+
return $settings;
669+
}
649670
}

0 commit comments

Comments
 (0)