Skip to content

Commit 1665375

Browse files
weitzmanwebflo
authored andcommitted
Honor .env files and suggest usage (drupal-composer#351)
1 parent 5693600 commit 1665375

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

.env.example

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copy and rename this file to .env at root of this project.
3+
#
4+
5+
# A common use case is to supply database creds via the environment. Edit settings.php
6+
# like so:
7+
#
8+
# $databases['default']['default'] = [
9+
# 'database' => getenv('MYSQL_DATABASE'),
10+
# 'driver' => 'mysql',
11+
# 'host' => getenv('MYSQL_HOSTNAME'),
12+
# 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
13+
# 'password' => getenv('MYSQL_PASSWORD'),
14+
# 'port' => getenv('MYSQL_PORT'),
15+
# 'prefix' => '',
16+
# 'username' => getenv('MYSQL_USER'),
17+
# ];
18+
#
19+
# Uncomment and populate as needed.
20+
# MYSQL_DATABASE=
21+
# MYSQL_HOSTNAME=
22+
# MYSQL_PASSWORD=
23+
# MYSQL_PORT=
24+
# MYSQL_USER=
25+
26+
# Another common use case is to set Drush's --uri via environment.
27+
# DRUSH_OPTIONS_URI=http://example.com

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919

2020
# Ignore files generated by PhpStorm
2121
/.idea/
22+
23+
# Ignore .env files as they are personal
24+
/.env

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/drupal-composer/drupal-project.svg?branch=8.x)](https://travis-ci.org/drupal-composer/drupal-project)
44

5-
This project template should provide a kickstart for managing your site
5+
This project template provides a starter kit for managing your site
66
dependencies with [Composer](https://getcomposer.org/).
77

88
If you want to know how to use it as replacement for
@@ -49,6 +49,7 @@ When installing the given `composer.json` some tasks are taken care of:
4949
* Creates `web/sites/default/files`-directory.
5050
* Latest version of drush is installed locally for use at `vendor/bin/drush`.
5151
* Latest version of DrupalConsole is installed locally for use at `vendor/bin/drupal`.
52+
* Creates environment variables based on your .env file. See [.env.example](.env.example).
5253

5354
## Updating Drupal Core
5455

composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"drupal/console": "^1.0.2",
2323
"drupal/core": "~8.5",
2424
"drush/drush": "^9.0.0",
25+
"vlucas/phpdotenv": "^2.4",
2526
"webflo/drupal-finder": "^1.0.0",
2627
"webmozart/path-util": "^2.3"
2728
},
@@ -39,7 +40,8 @@
3940
"autoload": {
4041
"classmap": [
4142
"scripts/composer/ScriptHandler.php"
42-
]
43+
],
44+
"files": ["load.environment.php"]
4345
},
4446
"scripts": {
4547
"drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",

load.environment.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* This file is included very early. See autoload.files in composer.json and
5+
* https://getcomposer.org/doc/04-schema.md#files
6+
*/
7+
8+
use Dotenv\Dotenv;
9+
use Dotenv\Exception\InvalidPathException;
10+
11+
/**
12+
* Load any .env file. See /.env.example.
13+
*/
14+
$dotenv = new Dotenv(__DIR__);
15+
try {
16+
$dotenv->load();
17+
}
18+
catch (InvalidPathException $e) {
19+
// Do nothing. Production environments rarely use .env files.
20+
}

0 commit comments

Comments
 (0)