Skip to content

Commit 7a2036c

Browse files
Merge pull request #3 from unleashedtech/feature/namespaced-vars
Adding support for namespaced variable names...
2 parents b4eeead + 2b1b8d2 commit 7a2036c

File tree

4 files changed

+149
-66
lines changed

4 files changed

+149
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
composer.lock
44
composer.phar
55
/vendor/
6+
*.ignore.*

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
44

55
## [Unreleased][unreleased]
66

7+
## [0.3.0] - 2022-05-17
8+
9+
### Changed
10+
11+
- Added support for namespaced variable names.
12+
- Added support for `SALT`.
13+
- Removed support for `SHIELD*` vars. Use `PUBLIC` instead.
14+
715
## [0.2.1] - 2022-03-30
816

917
### Fixed
@@ -141,7 +149,8 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
141149

142150
**Initial release!**
143151

144-
[unreleased]: https://github.com/unleashedtech/dotenv-drupal/compare/0.2.1...main
152+
[unreleased]: https://github.com/unleashedtech/dotenv-drupal/compare/0.3.0...main
153+
[0.3.0]: https://github.com/unleashedtech/dotenv-drupal/compare/0.2.1...0.3.0
145154
[0.2.1]: https://github.com/unleashedtech/dotenv-drupal/compare/0.2.0...0.2.1
146155
[0.2.0]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.17...0.2.0
147156
[0.1.17]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.16...0.1.17

README.md

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,21 @@ Environment variables can be set in `.env` files, or via modifying server config
107107
For production environments, environment variables should ideally be defined via server
108108
configuration.
109109

110+
Multi-site installations often need config that differs from the default site.
111+
This package first checks for variables following the `{{ app }}__{{ site }}__{{ var }}`
112+
naming convention, before falling back to the `{{ var }}` naming convention.
113+
114+
You can provide site-specific information via namespaced environment variables.
115+
110116
* [DATABASE_URL](#database_url)
111117
* [FILE_PUBLIC_PATH](#file_public_path)
112118
* [FILE_PRIVATE_PATH](#file_private_path)
113119
* [FILE_TEMP_PATH](#file_temp_path)
114120
* [CONFIG_SYNC_PATH](#config_sync_path)
115121
* [DOMAINS](#domains)
116122
* [MAILGUN_URL](#mailgun_url)
117-
* [SHIELD](#shield)
118-
* [SHIELD_USERNAME](#shield_username)
119-
* [SHIELD_PASSWORD](#shield_password)
120-
* [SHIELD_MESSAGE](#shield_message)
123+
* [PUBLIC](#public)
124+
* [SALT](#salt)
121125
* [SITES](#sites)
122126
* [SOLR_URL](#solr_url)
123127
* [TRUSTED_HOST_PATTERNS](#trusted_host_patterns)
@@ -133,13 +137,35 @@ DATABASE_URL=driver://user:password@host:port/database
133137
For example:
134138

135139
```dotenv
136-
DATABASE_URL=mysql://foo:bar@host:3306/baz
140+
DATABASE_URL=mysql://foo:bar@localhost:3306/baz
137141
```
138142

139-
For multi-site installations, do _not_ specify a database name in the `DATABASE_URL` variable:
143+
For multi-site installations, do _not_ specify a database name nor credentials in
144+
the `DATABASE_URL` variable:
140145

141146
```dotenv
142-
DATABASE_URL=mysql://foo:bar@host:3306
147+
DATABASE_URL=mysql://localhost:3306
148+
```
149+
150+
For an "earth" Drupal App with a "default" site & an "antarctica" site:
151+
```dotenv
152+
DATABASE_URL=mysql://localhost:3306
153+
154+
EARTH__DEFAULT__DATABASE_USER=foo
155+
EARTH__DEFAULT__DATABASE_PASSWORD=bar
156+
157+
EARTH__ANTARCTICA__DATABASE_USER=baz
158+
EARTH__ANTARCTICA__DATABASE_PASSWORD=qux
159+
```
160+
161+
The default Drupal [App Name](#app-name) is "default". For most use cases, you'll want to set the
162+
Drupal [App Name](#app-name) in the default `settings.php` file, as shown below:
163+
```php
164+
<?php
165+
use UnleashedTech\Drupal\Dotenv\Dotenv;
166+
$dotenv = $dotenv ?? new Dotenv();
167+
$dotenv->setAppName('earth');
168+
// ...
143169
```
144170

145171
#### FILE_PUBLIC_PATH
@@ -194,33 +220,32 @@ MAILGUN_URL=https://[email protected]
194220
MAILGUN_URL=https://[email protected]
195221
```
196222

197-
#### SHIELD
223+
#### PUBLIC
198224
A string allowing the enabling/disabling of Shield module auth functionality.
199225

200-
If empty, shield will not be enabled.
226+
If `true`, Shield will not be enabled.
201227

202-
If filled, the string will be used as username & password by default.
228+
If `false`, the username will be the [App Name](#app-name) & the password will
229+
be the [Site Name](#site-name).
203230

204231
Note: _Make sure the "Enable Shield" checkbox is checked in Drupal & that config is committed._
205232

206-
##### SHIELD_USERNAME
207-
The username for Shield to require, if enabled.
208-
209-
This package will use the value of `SHIELD` as username, by default.
233+
#### SITES
234+
A CSV list of Drupal "sites" (e.g. "subdomains") used by the given environment:
210235

211-
##### SHIELD_PASSWORD
212-
The password for Shield to require, if enabled.
236+
```dotenv
237+
SITES=foo,bar,baz,qux
238+
```
213239

214-
This package will use the value of `SHIELD` as password, by default.
240+
#### SALT
241+
A string used for "one-time login links, cancel links, form tokens, etc."
215242

216-
##### SHIELD_MESSAGE
217-
The _public_ message Shield should show in the auth prompt if enabled.
243+
[Best Practices Issue](https://www.drupal.org/project/drupal/issues/3107548)
218244

219-
#### SITES
220-
A CSV list of Drupal "sites" (e.g. "subdomains") used by the given environment:
245+
Use `drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))"` to generate one.
221246

222247
```dotenv
223-
SITES=foo,bar,baz,qux
248+
SALT=generatedSaltValue
224249
```
225250

226251
#### SOLR_URL
@@ -269,6 +294,14 @@ Drupal `trusted_host_patterns` setting array would have the following values:
269294
* `^baz\.foo\.example$`
270295
* `^qux\.foo\.example$`
271296

297+
#### Terms
298+
299+
##### App Name
300+
The machine name of the Drupal App (e.g. "default" or "earth").
301+
302+
##### Site Name
303+
The site name for a Drupal App Site (e.g. "default" or "antarctica").
304+
272305
#### Configuration Conclusion
273306
With these few Environment Variables, you will be able to configure Drupal in a streamlined
274307
fashion similar to the way Symfony is configured. Support for many more common Drupal features

0 commit comments

Comments
 (0)