1
0

IConfig.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. // use OCP namespace for all classes that are considered public.
  31. // This means that they should be used by apps instead of the internal Nextcloud classes
  32. namespace OCP;
  33. /**
  34. * Access to all the configuration options Nextcloud offers.
  35. * @since 6.0.0
  36. */
  37. interface IConfig {
  38. /**
  39. * @since 8.2.0
  40. */
  41. public const SENSITIVE_VALUE = '***REMOVED SENSITIVE VALUE***';
  42. /**
  43. * Sets and deletes system wide values
  44. *
  45. * @param array $configs Associative array with `key => value` pairs
  46. * If value is null, the config key will be deleted
  47. * @throws HintException if config file is read-only
  48. * @since 8.0.0
  49. */
  50. public function setSystemValues(array $configs);
  51. /**
  52. * Sets a new system wide value
  53. *
  54. * @param string $key the key of the value, under which will be saved
  55. * @param mixed $value the value that should be stored
  56. * @throws HintException if config file is read-only
  57. * @since 8.0.0
  58. */
  59. public function setSystemValue($key, $value);
  60. /**
  61. * Looks up a system wide defined value
  62. *
  63. * @param string $key the key of the value, under which it was saved
  64. * @param mixed $default the default value to be returned if the value isn't set
  65. * @return mixed the value or $default
  66. * @since 6.0.0 - parameter $default was added in 7.0.0
  67. */
  68. public function getSystemValue($key, $default = '');
  69. /**
  70. * Looks up a boolean system wide defined value
  71. *
  72. * @param string $key the key of the value, under which it was saved
  73. * @param bool $default the default value to be returned if the value isn't set
  74. * @return bool the value or $default
  75. * @since 16.0.0
  76. */
  77. public function getSystemValueBool(string $key, bool $default = false): bool;
  78. /**
  79. * Looks up an integer system wide defined value
  80. *
  81. * @param string $key the key of the value, under which it was saved
  82. * @param int $default the default value to be returned if the value isn't set
  83. * @return int the value or $default
  84. * @since 16.0.0
  85. */
  86. public function getSystemValueInt(string $key, int $default = 0): int;
  87. /**
  88. * Looks up a string system wide defined value
  89. *
  90. * @param string $key the key of the value, under which it was saved
  91. * @param string $default the default value to be returned if the value isn't set
  92. * @return string the value or $default
  93. * @since 16.0.0
  94. */
  95. public function getSystemValueString(string $key, string $default = ''): string;
  96. /**
  97. * Looks up a system wide defined value and filters out sensitive data
  98. *
  99. * @param string $key the key of the value, under which it was saved
  100. * @param mixed $default the default value to be returned if the value isn't set
  101. * @return mixed the value or $default
  102. * @since 8.2.0
  103. */
  104. public function getFilteredSystemValue($key, $default = '');
  105. /**
  106. * Delete a system wide defined value
  107. *
  108. * @param string $key the key of the value, under which it was saved
  109. * @since 8.0.0
  110. */
  111. public function deleteSystemValue($key);
  112. /**
  113. * Get all keys stored for an app
  114. *
  115. * @param string $appName the appName that we stored the value under
  116. * @return string[] the keys stored for the app
  117. * @since 8.0.0
  118. */
  119. public function getAppKeys($appName);
  120. /**
  121. * Writes a new app wide value
  122. *
  123. * @param string $appName the appName that we want to store the value under
  124. * @param string|float|int $key the key of the value, under which will be saved
  125. * @param string $value the value that should be stored
  126. * @return void
  127. * @since 6.0.0
  128. */
  129. public function setAppValue($appName, $key, $value);
  130. /**
  131. * Looks up an app wide defined value
  132. *
  133. * @param string $appName the appName that we stored the value under
  134. * @param string $key the key of the value, under which it was saved
  135. * @param string $default the default value to be returned if the value isn't set
  136. * @return string the saved value
  137. * @since 6.0.0 - parameter $default was added in 7.0.0
  138. */
  139. public function getAppValue($appName, $key, $default = '');
  140. /**
  141. * Delete an app wide defined value
  142. *
  143. * @param string $appName the appName that we stored the value under
  144. * @param string $key the key of the value, under which it was saved
  145. * @since 8.0.0
  146. */
  147. public function deleteAppValue($appName, $key);
  148. /**
  149. * Removes all keys in appconfig belonging to the app
  150. *
  151. * @param string $appName the appName the configs are stored under
  152. * @since 8.0.0
  153. */
  154. public function deleteAppValues($appName);
  155. /**
  156. * Set a user defined value
  157. *
  158. * @param string $userId the userId of the user that we want to store the value under
  159. * @param string $appName the appName that we want to store the value under
  160. * @param string $key the key under which the value is being stored
  161. * @param string $value the value that you want to store
  162. * @param string $preCondition only update if the config value was previously the value passed as $preCondition
  163. * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
  164. * @throws \UnexpectedValueException when trying to store an unexpected value
  165. * @since 6.0.0 - parameter $precondition was added in 8.0.0
  166. */
  167. public function setUserValue($userId, $appName, $key, $value, $preCondition = null);
  168. /**
  169. * Shortcut for getting a user defined value
  170. *
  171. * @param ?string $userId the userId of the user that we want to store the value under
  172. * @param string $appName the appName that we stored the value under
  173. * @param string $key the key under which the value is being stored
  174. * @param mixed $default the default value to be returned if the value isn't set
  175. * @return string
  176. * @since 6.0.0 - parameter $default was added in 7.0.0
  177. */
  178. public function getUserValue($userId, $appName, $key, $default = '');
  179. /**
  180. * Fetches a mapped list of userId -> value, for a specified app and key and a list of user IDs.
  181. *
  182. * @param string $appName app to get the value for
  183. * @param string $key the key to get the value for
  184. * @param array $userIds the user IDs to fetch the values for
  185. * @return array Mapped values: userId => value
  186. * @since 8.0.0
  187. */
  188. public function getUserValueForUsers($appName, $key, $userIds);
  189. /**
  190. * Get the keys of all stored by an app for the user
  191. *
  192. * @param string $userId the userId of the user that we want to store the value under
  193. * @param string $appName the appName that we stored the value under
  194. * @return string[]
  195. * @since 8.0.0
  196. */
  197. public function getUserKeys($userId, $appName);
  198. /**
  199. * Get all user configs sorted by app of one user
  200. *
  201. * @param string $userId the userId of the user that we want to get all values from
  202. * @psalm-return array<string, array<string, string>>
  203. * @return array[] - 2 dimensional array with the following structure:
  204. * [ $appId =>
  205. * [ $key => $value ]
  206. * ]
  207. * @since 24.0.0
  208. */
  209. public function getAllUserValues(string $userId): array;
  210. /**
  211. * Delete a user value
  212. *
  213. * @param string $userId the userId of the user that we want to store the value under
  214. * @param string $appName the appName that we stored the value under
  215. * @param string $key the key under which the value is being stored
  216. * @since 8.0.0
  217. */
  218. public function deleteUserValue($userId, $appName, $key);
  219. /**
  220. * Delete all user values
  221. *
  222. * @param string $userId the userId of the user that we want to remove all values from
  223. * @since 8.0.0
  224. */
  225. public function deleteAllUserValues($userId);
  226. /**
  227. * Delete all user related values of one app
  228. *
  229. * @param string $appName the appName of the app that we want to remove all values from
  230. * @since 8.0.0
  231. */
  232. public function deleteAppFromAllUsers($appName);
  233. /**
  234. * Determines the users that have the given value set for a specific app-key-pair
  235. *
  236. * @param string $appName the app to get the user for
  237. * @param string $key the key to get the user for
  238. * @param string $value the value to get the user for
  239. * @return array of user IDs
  240. * @since 8.0.0
  241. */
  242. public function getUsersForUserValue($appName, $key, $value);
  243. }