|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Codervio\Envmanager; |
|
4
|
|
|
|
|
5
|
|
|
use Codervio\Envmanager\Envparser; |
|
6
|
|
|
use Codervio\Envmanager\Editor\EnvWriter; |
|
7
|
|
|
use Codervio\Envmanager\Loader\Loader; |
|
8
|
|
|
|
|
9
|
|
|
class Enveditor extends EnvParser |
|
10
|
|
|
{ |
|
11
|
|
|
private $content; |
|
12
|
|
|
|
|
13
|
|
|
protected $writer; |
|
14
|
|
|
protected $reader; |
|
15
|
|
|
protected $context; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct($context) |
|
18
|
|
|
{ |
|
19
|
|
|
new Prerequisities(); |
|
20
|
|
|
|
|
21
|
|
|
$this->writer = new EnvWriter(); |
|
22
|
|
|
|
|
23
|
|
|
if ($context instanceof EnvParser) { |
|
24
|
|
|
|
|
25
|
|
|
if ($context->loader->getLoadStatus()) { |
|
26
|
|
|
|
|
27
|
|
|
$this->context = $context->loader->getFile(); |
|
28
|
|
|
|
|
29
|
|
|
$parsedValues = $context->parsercollector->getArrayCopy(); |
|
30
|
|
|
|
|
31
|
|
|
foreach ($parsedValues as $parsedKey => $parsedValue) { |
|
32
|
|
|
|
|
33
|
|
|
$this->writer->put($parsedKey, $parsedValue); |
|
34
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
} else { |
|
39
|
|
|
|
|
40
|
|
|
$this->context = $context; |
|
41
|
|
|
|
|
42
|
|
|
$loader = new Loader($context, array('env', 'main.env')); |
|
43
|
|
|
|
|
44
|
|
|
$content = $loader->run(); |
|
45
|
|
|
|
|
46
|
|
|
if (!$content) { |
|
47
|
|
|
return null; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->content = $content; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function addEmptyLine() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->writer->appendLine(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function persist($key, $value = null, $comment = null, $export = false) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->writer->put($key, $value, $comment, $export); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function addComment($comment = null) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->writer->appendComment($comment); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function removeComment($value) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->writer->removeComment($value); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function remove($key) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->writer->remove($key); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function save() |
|
80
|
|
|
{ |
|
81
|
|
|
return (bool)(int)file_put_contents($this->context, $this->getContent()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function removeFile() |
|
85
|
|
|
{ |
|
86
|
|
|
unlink($this->context); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getContent() |
|
90
|
|
|
{ |
|
91
|
|
|
return (string)$this->writer->get(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function clearContent() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->writer->clearBuffer(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function forceClear() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->writer->clearAll(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
} |