Skip to content

Commit 9998dba

Browse files
Merge pull request #22 from ginkelsoft-development/fix/add-config-validation
fix: add configuration validation to service provider boot
2 parents a940a56 + 89bbd66 commit 9998dba

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)