1 | <?php |
||
37 | class AppConfig { |
||
38 | private $appName = 'files_antivirus'; |
||
39 | |||
40 | /** @var IConfig */ |
||
41 | private $config; |
||
42 | |||
43 | private $defaults = [ |
||
44 | 'av_mode' => 'executable', |
||
45 | 'av_socket' => '/var/run/clamav/clamd.ctl', |
||
46 | 'av_host' => '', |
||
47 | 'av_port' => '', |
||
48 | 'av_cmd_options' => '', |
||
49 | 'av_chunk_size' => '8192', |
||
50 | 'av_path' => '/usr/bin/clamscan', |
||
51 | 'av_max_file_size' => -1, |
||
52 | 'av_stream_max_length' => '26214400', |
||
53 | 'av_infected_action' => 'only_log', |
||
54 | ]; |
||
55 | |||
56 | /** |
||
57 | * AppConfig constructor. |
||
58 | * |
||
59 | * @param IConfig $config |
||
60 | */ |
||
61 | 5 | public function __construct(IConfig $config) { |
|
62 | 5 | $this->config = $config; |
|
63 | 5 | } |
|
64 | |||
65 | /** |
||
66 | * Get full commandline |
||
67 | * @return string |
||
68 | */ |
||
69 | public function getCmdline(){ |
||
88 | |||
89 | /** |
||
90 | * Get all setting values as an array |
||
91 | * @return array |
||
92 | */ |
||
93 | public function getAllValues() { |
||
99 | |||
100 | /** |
||
101 | * Get a value by key |
||
102 | * @param string $key |
||
103 | * @return string |
||
104 | */ |
||
105 | 5 | public function getAppValue($key) { |
|
106 | 5 | $defaultValue = null; |
|
107 | 5 | if (array_key_exists($key, $this->defaults)){ |
|
108 | 5 | $defaultValue = $this->defaults[$key]; |
|
109 | } |
||
110 | 5 | return $this->config->getAppValue($this->appName, $key, $defaultValue); |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * Set a value by key |
||
115 | * @param string $key |
||
116 | * @param string $value |
||
117 | * @return string |
||
118 | */ |
||
119 | public function setAppValue($key, $value) { |
||
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) { |
||
136 | |||
137 | /** |
||
138 | * Get a value with magic __call invocation |
||
139 | * @param string $key |
||
140 | * @return string |
||
141 | * @throws \BadFunctionCallException |
||
142 | */ |
||
143 | 5 | protected function getter($key) { |
|
144 | 5 | if (array_key_exists($key, $this->defaults)) { |
|
145 | 5 | return $this->getAppValue($key); |
|
146 | } else { |
||
147 | throw new \BadFunctionCallException($key . ' is not a valid key'); |
||
148 | } |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Translates property_name into propertyName |
||
153 | * @param string $property |
||
154 | * @return string |
||
155 | */ |
||
156 | protected function camelCase($property){ |
||
162 | |||
163 | /** |
||
164 | * Does all the someConfig to some_config magic |
||
165 | * @param string $property |
||
166 | * @return string |
||
167 | */ |
||
168 | 5 | protected function propertyToKey($property){ |
|
182 | |||
183 | /** |
||
184 | * Get/set an option value by calling getSomeOption method |
||
185 | * @param string $methodName |
||
186 | * @param array $args |
||
187 | * @return string|null |
||
188 | * @throws \BadFunctionCallException |
||
189 | */ |
||
190 | 5 | public function __call($methodName, $args){ |
|
202 | } |
||
203 |