1 | <?php |
||
34 | class AppConfig { |
||
35 | private $appName = 'files_antivirus'; |
||
36 | |||
37 | /** @var IConfig */ |
||
38 | private $config; |
||
39 | |||
40 | private $defaults = [ |
||
41 | 'av_mode' => 'executable', |
||
42 | 'av_socket' => '/var/run/clamav/clamd.ctl', |
||
43 | 'av_host' => '', |
||
44 | 'av_port' => '', |
||
45 | 'av_cmd_options' => '', |
||
46 | 'av_path' => '/usr/bin/clamscan', |
||
47 | 'av_max_file_size' => -1, |
||
48 | 'av_stream_max_length' => '26214400', |
||
49 | 'av_infected_action' => 'only_log', |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * AppConfig constructor. |
||
54 | * |
||
55 | * @param IConfig $config |
||
56 | */ |
||
57 | 1 | public function __construct(IConfig $config) { |
|
60 | |||
61 | public function getAvChunkSize(){ |
||
66 | |||
67 | /** |
||
68 | * Get full commandline |
||
69 | * @return string |
||
70 | */ |
||
71 | public function getCmdline(){ |
||
72 | $avCmdOptions = $this->getAvCmdOptions(); |
||
73 | |||
74 | $shellArgs = []; |
||
75 | if ($avCmdOptions) { |
||
76 | $shellArgs = explode(',', $avCmdOptions); |
||
77 | $shellArgs = array_map(function($i){ |
||
78 | return escapeshellarg($i); |
||
79 | }, |
||
80 | $shellArgs |
||
81 | ); |
||
82 | } |
||
83 | |||
84 | $preparedArgs = ''; |
||
85 | if (count($shellArgs)){ |
||
86 | $preparedArgs = implode(' ', $shellArgs); |
||
87 | } |
||
88 | return $preparedArgs; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Get all setting values as an array |
||
93 | * @return array |
||
94 | */ |
||
95 | public function getAllValues() { |
||
101 | |||
102 | /** |
||
103 | * Get a value by key |
||
104 | * @param string $key |
||
105 | * @return string |
||
106 | */ |
||
107 | 1 | public function getAppValue($key) { |
|
114 | |||
115 | /** |
||
116 | * Set a value by key |
||
117 | * @param string $key |
||
118 | * @param string $value |
||
119 | */ |
||
120 | public function setAppValue($key, $value) { |
||
123 | |||
124 | /** |
||
125 | * Set a value with magic __call invocation |
||
126 | * @param string $key |
||
127 | * @param array $args |
||
128 | * @throws \BadFunctionCallException |
||
129 | */ |
||
130 | protected function setter($key, $args) { |
||
137 | |||
138 | /** |
||
139 | * Get a value with magic __call invocation |
||
140 | * @param string $key |
||
141 | * @return string |
||
142 | * @throws \BadFunctionCallException |
||
143 | */ |
||
144 | 1 | protected function getter($key) { |
|
151 | |||
152 | /** |
||
153 | * Translates property_name into propertyName |
||
154 | * @param string $property |
||
155 | * @return string |
||
156 | */ |
||
157 | protected function camelCase($property){ |
||
162 | |||
163 | /** |
||
164 | * Does all the someConfig to some_config magic |
||
165 | * @param string $property |
||
166 | * @return string |
||
167 | */ |
||
168 | 1 | 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 | 1 | public function __call($methodName, $args){ |
|
202 | } |
||
203 |