mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Processed w/ phpcbf
This commit is contained in:
parent
cfa916632b
commit
0b9cbee210
@ -12,15 +12,18 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace RaspAP\DotEnv;
|
namespace RaspAP\DotEnv;
|
||||||
|
|
||||||
class DotEnv {
|
class DotEnv
|
||||||
|
{
|
||||||
protected $envFile;
|
protected $envFile;
|
||||||
protected $data = [];
|
protected $data = [];
|
||||||
|
|
||||||
public function __construct($envFile = '.env') {
|
public function __construct($envFile = '.env')
|
||||||
|
{
|
||||||
$this->envFile = $envFile;
|
$this->envFile = $envFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load() {
|
public function load()
|
||||||
|
{
|
||||||
if (file_exists($this->envFile)) {
|
if (file_exists($this->envFile)) {
|
||||||
$this->data = parse_ini_file($this->envFile);
|
$this->data = parse_ini_file($this->envFile);
|
||||||
foreach ($this->data as $key => $value) {
|
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;
|
$this->data[$key] = $value;
|
||||||
putenv("$key=$value");
|
putenv("$key=$value");
|
||||||
$this->store($key, $value);
|
$this->store($key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($key) {
|
public function get($key)
|
||||||
|
{
|
||||||
return getenv($key);
|
return getenv($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAll() {
|
public function getAll()
|
||||||
|
{
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unset($key) {
|
public function unset($key)
|
||||||
|
{
|
||||||
unset($_ENV[$key]);
|
unset($_ENV[$key]);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function store($key, $value) {
|
private function store($key, $value)
|
||||||
|
{
|
||||||
$content = file_get_contents($this->envFile);
|
$content = file_get_contents($this->envFile);
|
||||||
$content = preg_replace("/^$key=.*/m", "$key=$value", $content, 1, $count);
|
$content = preg_replace("/^$key=.*/m", "$key=$value", $content, 1, $count);
|
||||||
if ($count === 0) {
|
if ($count === 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user