Skip to content

Commit

Permalink
Revising Dotenv::getConfig to support more custom Solr configurations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dl-unleashed-technologies committed Nov 30, 2021
1 parent 53ae8d5 commit 9df9341
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,22 @@ DATABASE_URL=mysql://foo:bar@host:3306
The default Solr connection can be configured via a [DSN](https://en.wikipedia.org/wiki/Data_source_name):

```dotenv
SOLR_URL=host:port
SOLR_URL=http://localhost
```

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

```dotenv
SOLR_URL=solr.foo.site:8983
SOLR_URL=http://default@localhost:8983#default
```

In the expanded example above, the `user` is the name of the Solr core & the `fragment` is the Drupal machine
name for the connection. Consider revising Solr core & Drupal Solr server machine names to `default`,
so the shorter DSN can be used.

Streamlined environment-dependent configuration of _one_ Solr core is supported at this time.

##### Supported Placeholders
* `{{app_path}}`: The path where Drupal is located.
* `{{project_path}}`: The path where the project is located.
Expand Down
10 changes: 7 additions & 3 deletions src/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ public function getConfig(): array
$config = [];
if (isset($_SERVER['SOLR_URL'])) {
$parts = parse_url($_SERVER['SOLR_URL']);
$config['search_api.server.afa_solr']['backend_config']['connector_config'] = [
'host' => $parts['host'],
'port' => $parts['port'],
$name = $parts['fragment'] ?? 'default';
$config['search_api.server.' . $name]['backend_config']['connector_config'] = [
'scheme' => $parts['scheme'] ?? 'http',
'host' => $parts['host'] ?? 'localhost',
'port' => $parts['port'] ?? 8983,
'path' => $parts['path'] ?? '/',
'core' => $parts['user'] ?? 'default',
];
}
switch ($this->getEnvironmentName()) {
Expand Down

0 comments on commit 9df9341

Please sign in to comment.