You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(config): replace deprecated IConfig app/user value examples
Replaces IConfig::getAppValue/setAppValue with OCP\AppFramework\Services\IAppConfig
(deprecated since NC29) and IConfig::getUserValue/setUserValue with
OCP\Config\IUserConfig (deprecated since NC31).
System values section unchanged — IConfig is still correct there.
Fixes#12221
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Copy file name to clipboardExpand all lines: developer_manual/basics/storage/configuration.rst
+61-67Lines changed: 61 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,42 +4,17 @@ Configuration
4
4
5
5
.. sectionauthor:: Bernhard Posselt <dev@bernhard-posselt.com>
6
6
7
-
The config that allows the app to set global, app and user settings can be injected from the ServerContainer. All values are saved as strings and must be cast to the correct value.
7
+
Nextcloud provides three configuration scopes: system-wide values (``config.php``),
8
+
per-app values, and per-user values. Each scope has a dedicated API.
8
9
9
10
10
-
.. code-block:: php
11
-
12
-
<?php
13
-
namespace OCA\MyApp\AppInfo;
14
-
15
-
use OCP\AppFramework\App;
16
-
use OCP\IConfig;
17
-
use OCP\IServerContainer;
18
-
use OCA\MyApp\Service\AuthorService;
19
-
20
-
class Application extends App {
21
-
22
-
public function __construct(array $urlParams=array()){
System values are saved in the :file:`config/config.php` and allow the app to modify and read the global configuration. Please note that ``setSystemValue`` might throw a ``OCP\HintException`` when the config file is read-only.
14
+
System values are saved in :file:`config/config.php`. Inject ``\OCP\IConfig``
15
+
and use the ``getSystemValue*`` / ``setSystemValue`` methods.
16
+
17
+
Note that ``setSystemValue`` may throw ``OCP\HintException`` when the config file is read-only.
43
18
44
19
.. code-block:: php
45
20
@@ -50,19 +25,15 @@ System values are saved in the :file:`config/config.php` and allow the app to mo
50
25
use OCP\IConfig;
51
26
52
27
class AuthorService {
53
-
private IConfig $config;
54
-
private string $appName;
28
+
public function __construct(
29
+
private IConfig $config,
30
+
) {}
55
31
56
-
public function __construct(IConfig $config, string $appName){
57
-
$this->config = $config;
58
-
$this->appName = $appName;
59
-
}
60
-
61
-
public function getSystemValue(string $key) {
32
+
public function getSystemValue(string $key): mixed {
62
33
return $this->config->getSystemValue($key);
63
34
}
64
35
65
-
public function setSystemValue(string $key, $value): void {
36
+
public function setSystemValue(string $key, mixed $value): void {
66
37
try {
67
38
$this->config->setSystemValue($key, $value);
68
39
} catch (HintException $e) {
@@ -71,7 +42,10 @@ System values are saved in the :file:`config/config.php` and allow the app to mo
71
42
}
72
43
}
73
44
74
-
.. note:: It's also possible to use ``getSystemValueBool``, ``getSystemValueString``, ``getSystemValueInt`` to get type hinted return values.
45
+
.. note::
46
+
47
+
Use ``getSystemValueBool()``, ``getSystemValueString()``, and ``getSystemValueInt()``
48
+
for typed return values.
75
49
76
50
Naming conventions
77
51
~~~~~~~~~~~~~~~~~~
@@ -89,62 +63,82 @@ Here are some examples:
89
63
4. ``mail_smtpname``
90
64
5. ``session_lifetime``
91
65
66
+
92
67
App values
93
68
----------
94
69
95
-
App values are saved in the database per app and are useful for setting global app settings:
70
+
.. versionchanged:: 29
71
+
72
+
Use ``\OCP\AppFramework\Services\IAppConfig`` (app-scoped) or ``\OCP\IAppConfig``
73
+
(global) instead of ``IConfig::getAppValue()`` / ``IConfig::setAppValue()``,
74
+
which are deprecated.
75
+
76
+
App values are stored in the database and are useful for global app settings.
77
+
78
+
Inside an AppFramework app, inject ``\OCP\AppFramework\Services\IAppConfig``.
79
+
Methods are automatically scoped to your app — no app ID argument needed.
96
80
97
81
.. code-block:: php
98
82
99
83
<?php
100
84
namespace OCA\MyApp\Service;
101
85
102
-
use OCP\IConfig;
86
+
use OCP\AppFramework\Services\IAppConfig;
103
87
104
88
class AuthorService {
105
-
private IConfig $config;
106
-
private string $appName;
89
+
public function __construct(
90
+
private IAppConfig $appConfig,
91
+
) {}
107
92
108
-
public function __construct(IConfig $config, string $appName){
0 commit comments