diff --git a/src/RaspAP/DotEnv/DotEnv.php b/src/RaspAP/DotEnv/DotEnv.php index edf3d906..a29a4e99 100644 --- a/src/RaspAP/DotEnv/DotEnv.php +++ b/src/RaspAP/DotEnv/DotEnv.php @@ -12,15 +12,18 @@ declare(strict_types=1); namespace RaspAP\DotEnv; -class DotEnv { +class DotEnv +{ protected $envFile; protected $data = []; - public function __construct($envFile = '.env') { + public function __construct($envFile = '.env') + { $this->envFile = $envFile; } - public function load() { + public function load() + { if (file_exists($this->envFile)) { $this->data = parse_ini_file($this->envFile); foreach ($this->data as $key => $value) { @@ -34,26 +37,31 @@ class DotEnv { } } - public function set($key, $value) { + public function set($key, $value) + { $this->data[$key] = $value; putenv("$key=$value"); $this->store($key, $value); } - public function get($key) { + public function get($key) + { return getenv($key); } - public function getAll() { + public function getAll() + { return $this->data; } - public function unset($key) { + public function unset($key) + { unset($_ENV[$key]); return $this; } - private function store($key, $value) { + private function store($key, $value) + { $content = file_get_contents($this->envFile); $content = preg_replace("/^$key=.*/m", "$key=$value", $content, 1, $count); if ($count === 0) {