Skip to content

Commit 9df9341

Browse files
Revising Dotenv::getConfig to support more custom Solr configurations.
1 parent 53ae8d5 commit 9df9341

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,22 @@ DATABASE_URL=mysql://foo:bar@host:3306
9191
The default Solr connection can be configured via a [DSN](https://en.wikipedia.org/wiki/Data_source_name):
9292

9393
```dotenv
94-
SOLR_URL=host:port
94+
SOLR_URL=http://localhost
9595
```
9696

97-
For example:
97+
This package makes several assumptions, which can be overridden via the `SOLR_URL` DSN. The DSN in the
98+
example above is automatically expanded to:
9899

99100
```dotenv
100-
SOLR_URL=solr.foo.site:8983
101+
SOLR_URL=http://default@localhost:8983#default
101102
```
102103

104+
In the expanded example above, the `user` is the name of the Solr core & the `fragment` is the Drupal machine
105+
name for the connection. Consider revising Solr core & Drupal Solr server machine names to `default`,
106+
so the shorter DSN can be used.
107+
108+
Streamlined environment-dependent configuration of _one_ Solr core is supported at this time.
109+
103110
##### Supported Placeholders
104111
* `{{app_path}}`: The path where Drupal is located.
105112
* `{{project_path}}`: The path where the project is located.

src/Dotenv.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ public function getConfig(): array
9595
$config = [];
9696
if (isset($_SERVER['SOLR_URL'])) {
9797
$parts = parse_url($_SERVER['SOLR_URL']);
98-
$config['search_api.server.afa_solr']['backend_config']['connector_config'] = [
99-
'host' => $parts['host'],
100-
'port' => $parts['port'],
98+
$name = $parts['fragment'] ?? 'default';
99+
$config['search_api.server.' . $name]['backend_config']['connector_config'] = [
100+
'scheme' => $parts['scheme'] ?? 'http',
101+
'host' => $parts['host'] ?? 'localhost',
102+
'port' => $parts['port'] ?? 8983,
103+
'path' => $parts['path'] ?? '/',
104+
'core' => $parts['user'] ?? 'default',
101105
];
102106
}
103107
switch ($this->getEnvironmentName()) {

0 commit comments

Comments
 (0)