Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/EncryptedSearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function register(): void
*/
public function boot(): void
{
// Validate configuration
$this->validateConfiguration();

// Publish configuration
$this->publishes([
__DIR__ . '/../config/encrypted-search.php' => config_path('encrypted-search.php'),
Expand All @@ -75,4 +78,35 @@ public function boot(): void
// Listen for all Eloquent model events and route them through the observer
Event::listen('eloquent.*: *', SearchIndexObserver::class);
}

/**
* Validate package configuration at boot time.
*
* @return void
*
* @throws \InvalidArgumentException if configuration is invalid
*/
protected function validateConfiguration(): void
{
// Validate Elasticsearch configuration if enabled
if (config('encrypted-search.elasticsearch.enabled', false)) {
$host = config('encrypted-search.elasticsearch.host');

if (empty($host)) {
throw new \InvalidArgumentException(
'Elasticsearch is enabled but ELASTICSEARCH_HOST is not configured. ' .
'Set it in your .env file or disable Elasticsearch mode.'
);
}

$index = config('encrypted-search.elasticsearch.index');

if (empty($index)) {
throw new \InvalidArgumentException(
'Elasticsearch is enabled but ELASTICSEARCH_INDEX is not configured. ' .
'Set it in your .env file.'
);
}
}
}
}
Loading