Skip to content

Commit 89bbd66

Browse files
fix: add configuration validation to service provider boot
Added validation to check Elasticsearch configuration when ES mode is enabled. This catches configuration errors early at boot time rather than failing silently during runtime operations. Changes: - Added validateConfiguration() method to service provider - Validates ELASTICSEARCH_HOST is set when ES is enabled - Validates ELASTICSEARCH_INDEX is set when ES is enabled - Throws InvalidArgumentException with helpful error messages - Called automatically during boot()
1 parent 6975c73 commit 89bbd66

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/EncryptedSearchServiceProvider.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function register(): void
5353
*/
5454
public function boot(): void
5555
{
56+
// Validate configuration
57+
$this->validateConfiguration();
58+
5659
// Publish configuration
5760
$this->publishes([
5861
__DIR__ . '/../config/encrypted-search.php' => config_path('encrypted-search.php'),
@@ -75,4 +78,35 @@ public function boot(): void
7578
// Listen for all Eloquent model events and route them through the observer
7679
Event::listen('eloquent.*: *', SearchIndexObserver::class);
7780
}
81+
82+
/**
83+
* Validate package configuration at boot time.
84+
*
85+
* @return void
86+
*
87+
* @throws \InvalidArgumentException if configuration is invalid
88+
*/
89+
protected function validateConfiguration(): void
90+
{
91+
// Validate Elasticsearch configuration if enabled
92+
if (config('encrypted-search.elasticsearch.enabled', false)) {
93+
$host = config('encrypted-search.elasticsearch.host');
94+
95+
if (empty($host)) {
96+
throw new \InvalidArgumentException(
97+
'Elasticsearch is enabled but ELASTICSEARCH_HOST is not configured. ' .
98+
'Set it in your .env file or disable Elasticsearch mode.'
99+
);
100+
}
101+
102+
$index = config('encrypted-search.elasticsearch.index');
103+
104+
if (empty($index)) {
105+
throw new \InvalidArgumentException(
106+
'Elasticsearch is enabled but ELASTICSEARCH_INDEX is not configured. ' .
107+
'Set it in your .env file.'
108+
);
109+
}
110+
}
111+
}
78112
}

0 commit comments

Comments
 (0)