| 1 | <?php |
||
| 5 | class Loader |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Set the env file |
||
| 9 | */ |
||
| 10 | protected $file; |
||
| 11 | |||
| 12 | protected $parser; |
||
| 13 | |||
| 14 | 18 | public function __construct($path, $filename = '.env') |
|
| 21 | |||
| 22 | /** |
||
| 23 | * parse and set the env |
||
| 24 | */ |
||
| 25 | 15 | public function load() |
|
| 26 | { |
||
| 27 | 15 | $this->parse(); |
|
| 28 | 15 | $this->toEnv(); |
|
| 29 | |||
| 30 | 15 | return $this; |
|
| 31 | } |
||
| 32 | |||
| 33 | 15 | public function parse(array $options = []) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Return the parser |
||
| 44 | */ |
||
| 45 | 3 | public function getParser() |
|
| 46 | { |
||
| 47 | 3 | return $this->parser; |
|
| 48 | } |
||
| 49 | |||
| 50 | 18 | public function toEnv() |
|
| 51 | { |
||
| 52 | 18 | if (!isset($this->parser)) { |
|
| 53 | 3 | throw new \LogicException("You must call parse() before", 1); |
|
| 54 | } |
||
| 55 | |||
| 56 | 15 | foreach ($this->parser->getContent() as $key => $value) { |
|
| 57 | 15 | static::putenv($key, $value); |
|
| 58 | 10 | } |
|
| 59 | |||
| 60 | 15 | return $this; |
|
| 61 | } |
||
| 62 | |||
| 63 | 15 | public static function putenv($key, $value) |
|
| 74 | |||
| 75 | 9 | public static function getenv($key, $default = null) |
|
|
2 ignored issues
–
show
|
|||
| 76 | { |
||
| 77 | 6 | switch (true) { |
|
| 87 | } |
||
| 88 |