IConfig.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP;
  10. /**
  11. * Access to all the configuration options Nextcloud offers.
  12. * @since 6.0.0
  13. */
  14. interface IConfig {
  15. /**
  16. * @since 8.2.0
  17. */
  18. public const SENSITIVE_VALUE = '***REMOVED SENSITIVE VALUE***';
  19. /**
  20. * Sets and deletes system wide values
  21. *
  22. * @param array $configs Associative array with `key => value` pairs
  23. * If value is null, the config key will be deleted
  24. * @throws HintException if config file is read-only
  25. * @since 8.0.0
  26. */
  27. public function setSystemValues(array $configs);
  28. /**
  29. * Sets a new system wide value
  30. *
  31. * @param string $key the key of the value, under which will be saved
  32. * @param mixed $value the value that should be stored
  33. * @throws HintException if config file is read-only
  34. * @since 8.0.0
  35. */
  36. public function setSystemValue($key, $value);
  37. /**
  38. * Looks up a system wide defined value
  39. *
  40. * @param string $key the key of the value, under which it was saved
  41. * @param mixed $default the default value to be returned if the value isn't set
  42. * @return mixed the value or $default
  43. * @since 6.0.0 - parameter $default was added in 7.0.0
  44. */
  45. public function getSystemValue($key, $default = '');
  46. /**
  47. * Looks up a boolean system wide defined value
  48. *
  49. * @param string $key the key of the value, under which it was saved
  50. * @param bool $default the default value to be returned if the value isn't set
  51. * @return bool the value or $default
  52. * @since 16.0.0
  53. */
  54. public function getSystemValueBool(string $key, bool $default = false): bool;
  55. /**
  56. * Looks up an integer system wide defined value
  57. *
  58. * @param string $key the key of the value, under which it was saved
  59. * @param int $default the default value to be returned if the value isn't set
  60. * @return int the value or $default
  61. * @since 16.0.0
  62. */
  63. public function getSystemValueInt(string $key, int $default = 0): int;
  64. /**
  65. * Looks up a string system wide defined value
  66. *
  67. * @param string $key the key of the value, under which it was saved
  68. * @param string $default the default value to be returned if the value isn't set
  69. * @return string the value or $default
  70. * @since 16.0.0
  71. */
  72. public function getSystemValueString(string $key, string $default = ''): string;
  73. /**
  74. * Looks up a system wide defined value and filters out sensitive data
  75. *
  76. * @param string $key the key of the value, under which it was saved
  77. * @param mixed $default the default value to be returned if the value isn't set
  78. * @return mixed the value or $default
  79. * @since 8.2.0
  80. */
  81. public function getFilteredSystemValue($key, $default = '');
  82. /**
  83. * Delete a system wide defined value
  84. *
  85. * @param string $key the key of the value, under which it was saved
  86. * @since 8.0.0
  87. */
  88. public function deleteSystemValue($key);
  89. /**
  90. * Get all keys stored for an app
  91. *
  92. * @param string $appName the appName that we stored the value under
  93. * @return string[] the keys stored for the app
  94. * @since 8.0.0
  95. * @deprecated 29.0.0 Use {@see IAppConfig} directly
  96. */
  97. public function getAppKeys($appName);
  98. /**
  99. * Writes a new app wide value
  100. *
  101. * @param string $appName the appName that we want to store the value under
  102. * @param string|float|int $key the key of the value, under which will be saved
  103. * @param string $value the value that should be stored
  104. * @return void
  105. * @since 6.0.0
  106. * @deprecated 29.0.0 Use {@see IAppConfig} directly
  107. */
  108. public function setAppValue($appName, $key, $value);
  109. /**
  110. * Looks up an app wide defined value
  111. *
  112. * @param string $appName the appName that we stored the value under
  113. * @param string $key the key of the value, under which it was saved
  114. * @param string $default the default value to be returned if the value isn't set
  115. *
  116. * @return string the saved value
  117. * @since 6.0.0 - parameter $default was added in 7.0.0
  118. * @deprecated 29.0.0 Use {@see IAppConfig} directly
  119. */
  120. public function getAppValue($appName, $key, $default = '');
  121. /**
  122. * Delete an app wide defined value
  123. *
  124. * @param string $appName the appName that we stored the value under
  125. * @param string $key the key of the value, under which it was saved
  126. * @since 8.0.0
  127. * @deprecated 29.0.0 Use {@see IAppConfig} directly
  128. */
  129. public function deleteAppValue($appName, $key);
  130. /**
  131. * Removes all keys in appconfig belonging to the app
  132. *
  133. * @param string $appName the appName the configs are stored under
  134. * @since 8.0.0
  135. * @deprecated 29.0.0 Use {@see IAppConfig} directly
  136. */
  137. public function deleteAppValues($appName);
  138. /**
  139. * Set a user defined value
  140. *
  141. * @param string $userId the userId of the user that we want to store the value under
  142. * @param string $appName the appName that we want to store the value under
  143. * @param string $key the key under which the value is being stored
  144. * @param string $value the value that you want to store
  145. * @param string $preCondition only update if the config value was previously the value passed as $preCondition
  146. * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
  147. * @throws \UnexpectedValueException when trying to store an unexpected value
  148. * @since 6.0.0 - parameter $precondition was added in 8.0.0
  149. */
  150. public function setUserValue($userId, $appName, $key, $value, $preCondition = null);
  151. /**
  152. * Shortcut for getting a user defined value
  153. *
  154. * @param ?string $userId the userId of the user that we want to store the value under
  155. * @param string $appName the appName that we stored the value under
  156. * @param string $key the key under which the value is being stored
  157. * @param mixed $default the default value to be returned if the value isn't set
  158. * @return string
  159. * @since 6.0.0 - parameter $default was added in 7.0.0
  160. */
  161. public function getUserValue($userId, $appName, $key, $default = '');
  162. /**
  163. * Fetches a mapped list of userId -> value, for a specified app and key and a list of user IDs.
  164. *
  165. * @param string $appName app to get the value for
  166. * @param string $key the key to get the value for
  167. * @param array $userIds the user IDs to fetch the values for
  168. * @return array Mapped values: userId => value
  169. * @since 8.0.0
  170. */
  171. public function getUserValueForUsers($appName, $key, $userIds);
  172. /**
  173. * Get the keys of all stored by an app for the user
  174. *
  175. * @param string $userId the userId of the user that we want to store the value under
  176. * @param string $appName the appName that we stored the value under
  177. * @return string[]
  178. * @since 8.0.0
  179. */
  180. public function getUserKeys($userId, $appName);
  181. /**
  182. * Get all user configs sorted by app of one user
  183. *
  184. * @param string $userId the userId of the user that we want to get all values from
  185. * @psalm-return array<string, array<string, string>>
  186. * @return array[] - 2 dimensional array with the following structure:
  187. * [ $appId =>
  188. * [ $key => $value ]
  189. * ]
  190. * @since 24.0.0
  191. */
  192. public function getAllUserValues(string $userId): array;
  193. /**
  194. * Delete a user value
  195. *
  196. * @param string $userId the userId of the user that we want to store the value under
  197. * @param string $appName the appName that we stored the value under
  198. * @param string $key the key under which the value is being stored
  199. * @since 8.0.0
  200. */
  201. public function deleteUserValue($userId, $appName, $key);
  202. /**
  203. * Delete all user values
  204. *
  205. * @param string $userId the userId of the user that we want to remove all values from
  206. * @since 8.0.0
  207. */
  208. public function deleteAllUserValues($userId);
  209. /**
  210. * Delete all user related values of one app
  211. *
  212. * @param string $appName the appName of the app that we want to remove all values from
  213. * @since 8.0.0
  214. */
  215. public function deleteAppFromAllUsers($appName);
  216. /**
  217. * Determines the users that have the given value set for a specific app-key-pair
  218. *
  219. * @param string $appName the app to get the user for
  220. * @param string $key the key to get the user for
  221. * @param string $value the value to get the user for
  222. * @return array of user IDs
  223. * @since 8.0.0
  224. */
  225. public function getUsersForUserValue($appName, $key, $value);
  226. }