-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathEnvironmentHandler.php
46 lines (36 loc) · 1.1 KB
/
EnvironmentHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace VA\Composer;
use Dotenv\Dotenv;
// Run here so it is loaded as soon as the file is included.
EnvironmentHandler::load();
/**
* Sets environment variables from .env files.
*/
class EnvironmentHandler {
/**
* Loads .env files if they exist.
*/
public static function load() {
$env_file_dir = dirname(dirname(__DIR__));
$env_file_name = '.env';
$env_file = $env_file_dir . DIRECTORY_SEPARATOR . $env_file_name;
$backup_env_file = $env_file_dir . DIRECTORY_SEPARATOR . $env_file_name . '.example';
try {
// If the .env file doesn't exist, don't try to load it.
if (!file_exists($env_file)) {
// Check for the backup file -- this is checked into git, so it should
// always be present.
if (!file_exists($backup_env_file)) {
return;
}
$env_file = $backup_env_file;
}
// Load environment and set required params.
$dotenv = Dotenv::createUnsafeMutable($env_file_dir, $env_file_name);
$dotenv->safeLoad();
}
catch (\Exception $exception) {
throw $exception;
}
}
}