Skip to content

Commit

Permalink
Cleanup the way handlers work
Browse files Browse the repository at this point in the history
  • Loading branch information
Torann committed Jun 2, 2017
1 parent bdf1efc commit 522f7b8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
22 changes: 12 additions & 10 deletions config/hunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@
],

'retries' => 1,

'handler' => null,
],

/*
|--------------------------------------------------------------------------
| Amazon Elasticsearch Service
| Handlers
|--------------------------------------------------------------------------
|
| Sign all requests made to AWS by simply setting up the config with your
| AWS settings like the following.
|
| 'aws_config' => [
| 'key' => env('AWS_KEY'),
| 'secret' => env('AWS_SECRET'),
| 'region' => env('AWS_REGION'),
| ],
| Use this to handle certain aspects of a Elasticsearch request.
|
*/

'aws_config' => null,
'handlers' => [
'aws' => [
'class' => \LaravelHunt\Handlers\AwsSignature::class,
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION', 'us-east-1'),
],
],

/*
|--------------------------------------------------------------------------
Expand Down
33 changes: 27 additions & 6 deletions src/Hunter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ public function __construct(array $config = [])
$this->config = $config;
$this->multilingual = $this->config('multilingual', false);

// AWS Elasticsearch enabled
if ($aws = $this->config('aws_config', null)) {
$this->config['config']['handler'] = new AwsSignature($aws);
}

$this->elasticsearch = ClientBuilder::fromConfig($this->config('config'));
$this->elasticsearch = ClientBuilder::fromConfig($this->getElasticSearchConfig());
}

/**
Expand Down Expand Up @@ -646,4 +641,30 @@ public function getIndexName()
{
return $this->config('index', 'default');
}

/**
* Get Elasticsearch settings.
*
* @return array
*/
protected function getElasticSearchConfig()
{
// Get all settings
$settings = $this->config('config');

// Get a handler if one is set
if ($config = $this->config('handlers.' . $this->config('config.handler'), null)) {

// Get handler class
$handler = Arr::pull($config, 'class');

// Create handler instance
$settings['handler'] = new $handler($config);
}
else {
unset($settings['handler']);
}

return $settings;
}
}

0 comments on commit 522f7b8

Please sign in to comment.