Passed
Push — master ( fa41e0...4bd63f )
by Daniel
07:07 queued 12s
created

ConfigService::getDefaultValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * CMS Pico - Create websites using Pico CMS for Nextcloud.
4
 *
5
 * @copyright Copyright (c) 2017, Maxence Lange (<[email protected]>)
6
 * @copyright Copyright (c) 2019, Daniel Rudolf (<[email protected]>)
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
declare(strict_types=1);
25
26
namespace OCA\CMSPico\Service;
27
28
use OCA\CMSPico\AppInfo\Application;
29
use OCP\IConfig;
30
31
class ConfigService
32
{
33
	/** @var string */
34
	public const SYSTEM_TEMPLATES = 'system_templates';
35
36
	/** @var string */
37
	public const CUSTOM_TEMPLATES = 'custom_templates';
38
39
	/** @var string */
40
	public const SYSTEM_THEMES = 'system_themes';
41
42
	/** @var string */
43
	public const CUSTOM_THEMES = 'custom_themes';
44
45
	/** @var string */
46
	public const THEMES_ETAG = 'themes_etag';
47
48
	/** @var string */
49
	public const SYSTEM_PLUGINS = 'system_plugins';
50
51
	/** @var string */
52
	public const CUSTOM_PLUGINS = 'custom_plugins';
53
54
	/** @var string */
55
	public const PLUGINS_ETAG = 'plugins_etag';
56
57
	/** @var string */
58
	public const LIMIT_GROUPS = 'limit_groups';
59
60
	/** @var string */
61
	public const LINK_MODE = 'link_mode';
62
63
	/** @var IConfig */
64
	protected $config;
65
66
	/** @var array<string,string> */
67
	protected $defaultValues;
68
69
	/**
70
	 * ConfigService constructor.
71
	 *
72
	 * @param IConfig      $config
73
	 */
74
	public function __construct(IConfig $config)
75
	{
76
		$this->config = $config;
77
78
		$this->defaultValues = [
79
			self::SYSTEM_TEMPLATES => '',
80
			self::CUSTOM_TEMPLATES => '',
81
			self::SYSTEM_THEMES => '',
82
			self::CUSTOM_THEMES => '',
83
			self::THEMES_ETAG => '',
84
			self::SYSTEM_PLUGINS => '',
85
			self::CUSTOM_PLUGINS => '',
86
			self::PLUGINS_ETAG => '',
87
			self::LIMIT_GROUPS => '',
88
			self::LINK_MODE => (string) WebsitesService::LINK_MODE_LONG,
89
		];
90
	}
91
92
	/**
93
	 * @param string $key
94
	 *
95
	 * @return string
96
	 */
97 25
	public function getAppValue(string $key): string
98
	{
99 25
		return $this->config->getAppValue(Application::APP_NAME, $key, $this->defaultValues[$key] ?? '');
100
	}
101
102
	/**
103
	 * @param string $key
104
	 * @param string $value
105
	 */
106
	public function setAppValue(string $key, string $value): void
107
	{
108
		$this->config->setAppValue(Application::APP_NAME, $key, $value);
109
	}
110
111
	/**
112
	 * @param string $key
113
	 */
114
	public function deleteAppValue(string $key): void
115
	{
116
		$this->config->deleteAppValue(Application::APP_NAME, $key);
117
	}
118
119
	/**
120
	 * @param string $key
121
	 * @param mixed  $defaultValue
122
	 *
123
	 * @return mixed
124
	 */
125 6
	public function getSystemValue(string $key, $defaultValue = '')
126
	{
127 6
		return $this->config->getSystemValue($key, $defaultValue);
128
	}
129
}
130