Skip to content

Commit 97e6cf5

Browse files
authored
Merge pull request #12942 from nextcloud/backport/12941/stable29
[stable29] feat(developer_manual): document IAppConfig AppFramework service
2 parents 2dce467 + 288401b commit 97e6cf5

File tree

2 files changed

+54
-30
lines changed

2 files changed

+54
-30
lines changed

developer_manual/basics/front-end/js.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ and a JS part (that fetches and parses the state).
170170
Providing the initial state with PHP
171171
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172172
Providing state in PHP is done via the ``OCP\AppFramework\Services\IInitialState``. This service
173-
has two methods you can use to provide the initial state.
173+
has two methods you can use to provide the initial state. They will automatically be scoped
174+
to your app, so you don't have to provide your app id anymore.
174175

175-
* ``provideInitialState(string $appName, string $key, $data)``:
176+
* ``provideInitialState(string $key, $data)``:
176177
If you know for sure your state will be used. For example on the settings page of your app.
177-
* ``provideLazyInitialState(string $appName, string $key, Closure $closure)``:
178+
* ``provideLazyInitialState(string $key, Closure $closure)``:
178179
If you want to inject your state on a general page. For example the initial state of the notifications app. The callback will be invoked if and only if a template is rendered.
179180

180181
You call both methods with the name of your app and a key. This is to scope

developer_manual/digging_deeper/config/appconfig.rst

+50-27
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ AppConfig
66

77
Since v29, Nextcloud includes a new API to manage your app configuration.
88

9+
AppFramework
10+
------------
11+
12+
The AppConfig API is also available in the AppFramework, allowing you to use it in your app.
13+
All of the methods are available in the ``OCP\AppFramework\Services\IAppConfig`` interface.
14+
Any of the methods below will automatically be scoped to your app, meaning you can omit the app id.
15+
16+
.. code-block:: php
17+
18+
<?php
19+
namespace OCA\MyApp;
20+
21+
use OCP\AppFramework\Services\IAppConfig;
22+
23+
class MyClass {
24+
public function __construct(
25+
private IAppConfig $appConfig,
26+
) {}
27+
28+
public function getSomeConfig(): string {
29+
return $this->appConfig->getAppValueString('mykey', 'default');
30+
}
31+
}
932
1033
Concept overview
1134
----------------
@@ -22,8 +45,8 @@ To ensure better stability of your code, config values are typed enforced.
2245
Type is set only once, at creation in database, and cannot be changed.
2346

2447
.. note::
25-
- Value stored before Nextcloud 29 are automatically typed as `mixed`. However, it is not possible to manually set a value as `mixed`.
26-
- Value not set as `mixed` must be retrieved using the corresponding method.
48+
- Value stored before Nextcloud 29 are automatically typed as `mixed`. However, it is not possible to manually set a value as `mixed`.
49+
- Value not set as `mixed` must be retrieved using the corresponding method.
2750

2851
Values Sensitivity
2952
^^^^^^^^^^^^^^^^^^
@@ -33,15 +56,15 @@ Configuration values set as `sensitive` are hidden from system reports and store
3356

3457
.. code-block:: php
3558
36-
setValueString(
37-
'myapp',
38-
'mykey',
39-
'myvalue',
40-
sensitive: true
41-
);
59+
setValueString(
60+
'myapp',
61+
'mykey',
62+
'myvalue',
63+
sensitive: true
64+
);
4265
4366
.. note::
44-
Once set as `sensitive`, it can only be reverted using ``updateSensitive()``
67+
Once set as `sensitive`, it can only be reverted using ``updateSensitive()``
4568

4669

4770
Lazy Loading
@@ -52,33 +75,33 @@ All `lazy` configuration values are loaded from the database once one is read.
5275

5376
.. code-block:: php
5477
55-
setValueString(
56-
'myapp',
57-
'mykey',
58-
'myvalue',
59-
lazy: true
60-
);
78+
setValueString(
79+
'myapp',
80+
'mykey',
81+
'myvalue',
82+
lazy: true
83+
);
6184
6285
.. note::
63-
- Flag as `lazy` as much 'large block of text' entries (json, key pairs, ...) as possible,
64-
- flag as `lazy` entries that are needed on quiet endpoints,
65-
- do **not** flag as `lazy` part of code that might be called during the global loading of the instance and its apps.
86+
- Flag as `lazy` as much 'large block of text' entries (json, key pairs, ...) as possible,
87+
- flag as `lazy` entries that are needed on quiet endpoints,
88+
- do **not** flag as `lazy` part of code that might be called during the global loading of the instance and its apps.
6689

6790

6891
Retrieving the configuration value will require to specify the fact that it is stored as `lazy`.
6992

7093
.. code-block:: php
7194
72-
getValueString(
73-
'myapp',
74-
'mykey',
75-
'default',
76-
lazy: true
77-
);
95+
getValueString(
96+
'myapp',
97+
'mykey',
98+
'default',
99+
lazy: true
100+
);
78101
79102
.. note::
80-
- Requesting with ``1azy: false`` will returns the default value if configuration value is stored as `lazy`.
81-
- Requesting with ``lazy: true`` will returns the correct value even if configuration value is stored as `non-lazy (as there is a huge probability that the `non-lazy` value are already loaded)
103+
- Requesting with ``1azy: false`` will returns the default value if configuration value is stored as `lazy`.
104+
- Requesting with ``lazy: true`` will returns the correct value even if configuration value is stored as `non-lazy (as there is a huge probability that the `non-lazy` value are already loaded)
82105

83106
Consuming the AppConfig API
84107
---------------------------
@@ -134,7 +157,7 @@ Managing config keys
134157
* ``deleteApp(string $app)`` delete all config keys from an app (using app id)
135158

136159
.. note::
137-
Some method allows ``$lazy`` to be ``null``, meaning that the search will be extended to all configuration values, `lazy` or not.
160+
Some method allows ``$lazy`` to be ``null``, meaning that the search will be extended to all configuration values, `lazy` or not.
138161

139162
Miscellaneous
140163
^^^^^^^^^^^^^

0 commit comments

Comments
 (0)