-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnv.php
59 lines (40 loc) · 1.14 KB
/
Env.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
<?php
class Env
{
private array|string $file;
public function __construct(private string $fileName)
{
$this->file = array_merge(array_filter(file($fileName),'trim'));
}
public function getFileContent(): array
{
return $this->file;
}
public function getLineVarible(int $number = 0) : string
{
return $this->file[$number];
}
public function contentMerge()
{
return array_reduce($this->getFileContent(),[$this,'reduce'],[]);
}
public function reduce($lines,$line)
{
[$key,$value] = explode('=',$line);
$lines[$key] = $value;
return $lines;
}
public function getValue($name)
{
return $this->contentMerge()[$name] ?? null;
}
public function addVarible(string $key, string $value=null)
{
$a = strtoupper($key) . '=' . $value . "\n";
return file_put_contents($this->fileName,$a,FILE_APPEND);
}
public function rmVarible(string $key)
{
return file_put_contents($this->fileName,str_replace($key.'='.$this->getValue($key),'',file_get_contents($this->fileName)));
}
}