1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - Richdocuments App |
4
|
|
|
* |
5
|
|
|
* @author Victor Dubiniuk |
6
|
|
|
* @copyright 2015 Victor Dubiniuk [email protected] |
7
|
|
|
* |
8
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
9
|
|
|
* later. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Richdocuments; |
13
|
|
|
|
14
|
|
|
use OCA\Richdocuments\AppInfo\Application; |
15
|
|
|
use \OCP\IConfig; |
16
|
|
|
|
17
|
|
|
class AppConfig { |
18
|
|
|
|
19
|
|
|
private $defaults = [ |
20
|
|
|
'wopi_url' => '', |
21
|
|
|
'timeout' => 15, |
22
|
|
|
'watermark_text' => '{userId}', |
23
|
|
|
'watermark_allGroupsList' => [], |
24
|
|
|
'watermark_allTagsList' => [], |
25
|
|
|
'watermark_linkTagsList' => [], |
26
|
|
|
|
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
const WATERMARK_APP_NAMESPACE = 'files'; |
30
|
|
|
|
31
|
|
|
const APP_SETTING_TYPES = [ |
32
|
|
|
'watermark_allGroupsList' => 'array', |
33
|
|
|
'watermark_allTagsList' => 'array', |
34
|
|
|
'watermark_linkTagsList' => 'array' |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** @var IConfig */ |
38
|
|
|
private $config; |
39
|
|
|
|
40
|
|
|
public function __construct(IConfig $config) { |
41
|
|
|
$this->config = $config; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getAppNamespace($key) { |
45
|
|
|
if (strpos($key, 'watermark_') === 0) { |
46
|
|
|
return self::WATERMARK_APP_NAMESPACE; |
47
|
|
|
} |
48
|
|
|
return Application::APPNAME; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get a value by key |
53
|
|
|
* @param string $key |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getAppValue($key) { |
57
|
|
|
$defaultValue = null; |
58
|
|
|
if (array_key_exists($key, $this->defaults)){ |
59
|
|
|
$defaultValue = $this->defaults[$key]; |
60
|
|
|
} |
61
|
|
|
return $this->config->getAppValue($this->getAppNamespace($key), $key, $defaultValue); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param $key |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function getAppValueArray($key) { |
69
|
|
|
$value = $this->config->getAppValue($this->getAppNamespace($key), $key, []); |
|
|
|
|
70
|
|
|
if (array_key_exists($key, self::APP_SETTING_TYPES) && self::APP_SETTING_TYPES[$key] === 'array') { |
71
|
|
|
$value = $value !== '' ? explode(',', $value) : []; |
72
|
|
|
} |
73
|
|
|
return $value; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Set a value by key |
78
|
|
|
* @param string $key |
79
|
|
|
* @param string $value |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public function setAppValue($key, $value) { |
83
|
|
|
$this->config->setAppValue($this->getAppNamespace($key), $key, $value); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get all app settings |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function getAppSettings() { |
91
|
|
|
$result = []; |
92
|
|
|
$keys = $this->config->getAppKeys(Application::APPNAME); |
93
|
|
View Code Duplication |
foreach ($keys as $key) { |
|
|
|
|
94
|
|
|
$value = $this->getAppValueArray($key); |
95
|
|
|
$value = $value === 'yes' ? true : $value; |
96
|
|
|
$result[$key] = $value === 'no' ? false : $value; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$keys = $this->config->getAppKeys(self::WATERMARK_APP_NAMESPACE); |
100
|
|
View Code Duplication |
foreach ($keys as $key) { |
|
|
|
|
101
|
|
|
if (strpos($key, 'watermark_') === 0) { |
102
|
|
|
$value = $this->getAppValueArray($key); |
103
|
|
|
$value = $value === 'yes' ? true : $value; |
104
|
|
|
$result[$key] = $value === 'no' ? false : $value; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
return $result; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: