1 | <?php |
||
33 | class AppConfig { |
||
34 | private $appName = 'files_antivirus'; |
||
35 | |||
36 | /** @var IConfig */ |
||
37 | private $config; |
||
38 | |||
39 | private $defaults = [ |
||
40 | 'av_mode' => 'executable', |
||
41 | 'av_socket' => '/var/run/clamav/clamd.ctl', |
||
42 | 'av_host' => '', |
||
43 | 'av_port' => '', |
||
44 | 'av_cmd_options' => '', |
||
45 | 'av_path' => '/usr/bin/clamscan', |
||
46 | 'av_max_file_size' => -1, |
||
47 | 'av_stream_max_length' => '26214400', |
||
48 | 'av_infected_action' => 'only_log', |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * AppConfig constructor. |
||
53 | * |
||
54 | * @param IConfig $config |
||
55 | */ |
||
56 | 5 | public function __construct(IConfig $config) { |
|
57 | 5 | $this->config = $config; |
|
58 | 5 | } |
|
59 | |||
60 | 4 | public function getAvChunkSize(){ |
|
65 | |||
66 | /** |
||
67 | * Get full commandline |
||
68 | * @return string |
||
69 | */ |
||
70 | 2 | public function getCmdline(){ |
|
89 | |||
90 | /** |
||
91 | * Get all setting values as an array |
||
92 | * @return array |
||
93 | */ |
||
94 | public function getAllValues() { |
||
100 | |||
101 | /** |
||
102 | * Get a value by key |
||
103 | * @param string $key |
||
104 | * @return string |
||
105 | */ |
||
106 | 1 | public function getAppValue($key) { |
|
113 | |||
114 | /** |
||
115 | * Set a value by key |
||
116 | * @param string $key |
||
117 | * @param string $value |
||
118 | */ |
||
119 | public function setAppValue($key, $value) { |
||
120 | $this->config->setAppValue($this->appName, $key, $value); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Set a value with magic __call invocation |
||
125 | * @param string $key |
||
126 | * @param array $args |
||
127 | * @throws \BadFunctionCallException |
||
128 | */ |
||
129 | protected function setter($key, $args) { |
||
130 | if (array_key_exists($key, $this->defaults)) { |
||
131 | $this->setAppValue($key, $args[0]); |
||
132 | } else { |
||
133 | throw new \BadFunctionCallException($key . ' is not a valid key'); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Get a value with magic __call invocation |
||
139 | * @param string $key |
||
140 | * @return string |
||
141 | * @throws \BadFunctionCallException |
||
142 | */ |
||
143 | 3 | protected function getter($key) { |
|
150 | |||
151 | /** |
||
152 | * Translates property_name into propertyName |
||
153 | * @param string $property |
||
154 | * @return string |
||
155 | */ |
||
156 | protected function camelCase($property){ |
||
161 | |||
162 | /** |
||
163 | * Does all the someConfig to some_config magic |
||
164 | * @param string $property |
||
165 | * @return string |
||
166 | */ |
||
167 | 3 | protected function propertyToKey($property){ |
|
181 | |||
182 | /** |
||
183 | * Get/set an option value by calling getSomeOption method |
||
184 | * @param string $methodName |
||
185 | * @param array $args |
||
186 | * @return string|null |
||
187 | * @throws \BadFunctionCallException |
||
188 | */ |
||
189 | 3 | public function __call($methodName, $args){ |
|
201 | } |
||
202 |