-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loader.php
67 lines (62 loc) · 1.41 KB
/
Loader.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace cyberinferno\yii\phpdotenv;
use Dotenv\Dotenv;
use Yii;
use yii\base\BootstrapInterface;
/**
* Class Loader
*
* @property Dotenv $dotenv
*
* @package yii\phpdotenv
*/
class Loader implements BootstrapInterface
{
/**
* @var string Environment variable file directory
*/
public $path = '@vendor/../';
/**
* @var string Use if custom environment variable file
*/
public $file = '.env';
/**
* @var bool Whether to overload already existing environment variables
*/
public $overload = false;
/**
* @var Dotenv
*/
private $_dotenv;
/**
* @inheritdoc
*/
public function bootstrap($app)
{
try {
if ($this->path === null) {
$this->path = '@vendor/../';
}
if ($this->file === null) {
$this->file = '.env';
}
$this->path = Yii::getAlias($this->path);
$this->_dotenv = New Dotenv($this->path, $this->file);
if ($this->overload) {
$this->_dotenv->overload();
} else {
$this->_dotenv->load();
}
} catch (\Exception $e) {
\Yii::error('Could not load Dotenv file. ERROR: '.$e->getMessage());
}
}
/**
* Get dotenv
* @return Dotenv
*/
public function getDotenv()
{
return $this->_dotenv;
}
}