IAppManager.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. namespace OCP\App;
  8. use OCP\IGroup;
  9. use OCP\IUser;
  10. /**
  11. * Interface IAppManager
  12. *
  13. * @warning This interface shouldn't be included with dependency injection in
  14. * classes used for installing Nextcloud.
  15. *
  16. * @since 8.0.0
  17. */
  18. interface IAppManager {
  19. /**
  20. * @since 30.0.0
  21. */
  22. public const BACKEND_CALDAV = 'caldav';
  23. /**
  24. * Returns the app information from "appinfo/info.xml" for an app
  25. *
  26. * @param string|null $lang
  27. * @return array|null
  28. * @since 14.0.0
  29. * @since 31.0.0 Usage of $path is discontinued and throws an \InvalidArgumentException, use {@see self::getAppInfoByPath} instead.
  30. */
  31. public function getAppInfo(string $appId, bool $path = false, $lang = null);
  32. /**
  33. * Returns the app information from a given path ending with "/appinfo/info.xml"
  34. *
  35. * @since 31.0.0
  36. */
  37. public function getAppInfoByPath(string $path, ?string $lang = null): ?array;
  38. /**
  39. * Returns the app information from "appinfo/info.xml".
  40. *
  41. * @param string $appId
  42. * @param bool $useCache
  43. * @return string
  44. * @since 14.0.0
  45. */
  46. public function getAppVersion(string $appId, bool $useCache = true): string;
  47. /**
  48. * Returns the app icon or null if none is found
  49. *
  50. * @param string $appId
  51. * @param bool $dark Enable to request a dark icon variant, default is a white icon
  52. * @return string|null
  53. * @since 29.0.0
  54. */
  55. public function getAppIcon(string $appId, bool $dark = false): ?string;
  56. /**
  57. * Check if an app is enabled for user
  58. *
  59. * @param string $appId
  60. * @param \OCP\IUser|null $user (optional) if not defined, the currently loggedin user will be used
  61. * @return bool
  62. * @since 8.0.0
  63. */
  64. public function isEnabledForUser($appId, $user = null);
  65. /**
  66. * Check if an app is enabled in the instance
  67. *
  68. * Notice: This actually checks if the app is enabled and not only if it is installed.
  69. *
  70. * @param string $appId
  71. * @return bool
  72. * @since 8.0.0
  73. */
  74. public function isInstalled($appId);
  75. /**
  76. * Check if an app should be enabled by default
  77. *
  78. * Notice: This actually checks if the app should be enabled by default
  79. * and not if currently installed/enabled
  80. *
  81. * @param string $appId ID of the app
  82. * @since 25.0.0
  83. */
  84. public function isDefaultEnabled(string $appId):bool;
  85. /**
  86. * Load an app, if not already loaded
  87. * @param string $app app id
  88. * @since 27.0.0
  89. */
  90. public function loadApp(string $app): void;
  91. /**
  92. * Check if an app is loaded
  93. * @param string $app app id
  94. * @since 27.0.0
  95. */
  96. public function isAppLoaded(string $app): bool;
  97. /**
  98. * Enable an app for every user
  99. *
  100. * @param string $appId
  101. * @param bool $forceEnable
  102. * @throws AppPathNotFoundException
  103. * @since 8.0.0
  104. */
  105. public function enableApp(string $appId, bool $forceEnable = false): void;
  106. /**
  107. * Whether a list of types contains a protected app type
  108. *
  109. * @param string[] $types
  110. * @return bool
  111. * @since 12.0.0
  112. */
  113. public function hasProtectedAppType($types);
  114. /**
  115. * Enable an app only for specific groups
  116. *
  117. * @param string $appId
  118. * @param \OCP\IGroup[] $groups
  119. * @param bool $forceEnable
  120. * @throws \Exception
  121. * @since 8.0.0
  122. */
  123. public function enableAppForGroups(string $appId, array $groups, bool $forceEnable = false): void;
  124. /**
  125. * Disable an app for every user
  126. *
  127. * @param string $appId
  128. * @param bool $automaticDisabled
  129. * @since 8.0.0
  130. */
  131. public function disableApp($appId, $automaticDisabled = false): void;
  132. /**
  133. * Get the directory for the given app.
  134. *
  135. * @since 11.0.0
  136. * @throws AppPathNotFoundException
  137. */
  138. public function getAppPath(string $appId): string;
  139. /**
  140. * Get the web path for the given app.
  141. *
  142. * @param string $appId
  143. * @return string
  144. * @since 18.0.0
  145. * @throws AppPathNotFoundException
  146. */
  147. public function getAppWebPath(string $appId): string;
  148. /**
  149. * List all apps enabled for a user
  150. *
  151. * @param \OCP\IUser $user
  152. * @return string[]
  153. * @since 8.1.0
  154. */
  155. public function getEnabledAppsForUser(IUser $user);
  156. /**
  157. * List all installed apps
  158. *
  159. * @return string[]
  160. * @since 8.1.0
  161. */
  162. public function getInstalledApps();
  163. /**
  164. * Clear the cached list of apps when enabling/disabling an app
  165. * @since 8.1.0
  166. */
  167. public function clearAppsCache(): void;
  168. /**
  169. * @param string $appId
  170. * @return boolean
  171. * @since 9.0.0
  172. */
  173. public function isShipped($appId);
  174. /**
  175. * Loads all apps
  176. *
  177. * @param string[] $types
  178. * @return bool
  179. *
  180. * This function walks through the Nextcloud directory and loads all apps
  181. * it can find. A directory contains an app if the file `/appinfo/info.xml`
  182. * exists.
  183. *
  184. * if $types is set to non-empty array, only apps of those types will be loaded
  185. * @since 27.0.0
  186. */
  187. public function loadApps(array $types = []): bool;
  188. /**
  189. * Check if an app is of a specific type
  190. * @since 27.0.0
  191. */
  192. public function isType(string $app, array $types): bool;
  193. /**
  194. * @return string[]
  195. * @since 9.0.0
  196. */
  197. public function getAlwaysEnabledApps();
  198. /**
  199. * @return string[] app IDs
  200. * @since 25.0.0
  201. */
  202. public function getDefaultEnabledApps(): array;
  203. /**
  204. * @param \OCP\IGroup $group
  205. * @return String[]
  206. * @since 17.0.0
  207. */
  208. public function getEnabledAppsForGroup(IGroup $group): array;
  209. /**
  210. * @param String $appId
  211. * @return string[]
  212. * @since 17.0.0
  213. */
  214. public function getAppRestriction(string $appId): array;
  215. /**
  216. * Returns the id of the user's default app
  217. *
  218. * If `user` is not passed, the currently logged in user will be used
  219. *
  220. * @param ?IUser $user User to query default app for
  221. * @param bool $withFallbacks Include fallback values if no default app was configured manually
  222. * Before falling back to predefined default apps,
  223. * the user defined app order is considered and the first app would be used as the fallback.
  224. *
  225. * @since 25.0.6
  226. * @since 28.0.0 Added optional $withFallbacks parameter
  227. * @deprecated 31.0.0
  228. * Use @see \OCP\INavigationManager::getDefaultEntryIdForUser() instead
  229. */
  230. public function getDefaultAppForUser(?IUser $user = null, bool $withFallbacks = true): string;
  231. /**
  232. * Get the global default apps with fallbacks
  233. *
  234. * @return string[] The default applications
  235. * @since 28.0.0
  236. * @deprecated 31.0.0
  237. * Use @see \OCP\INavigationManager::getDefaultEntryIds() instead
  238. */
  239. public function getDefaultApps(): array;
  240. /**
  241. * Set the global default apps with fallbacks
  242. *
  243. * @param string[] $defaultApps
  244. * @throws \InvalidArgumentException If any of the apps is not installed
  245. * @since 28.0.0
  246. * @deprecated 31.0.0
  247. * Use @see \OCP\INavigationManager::setDefaultEntryIds() instead
  248. */
  249. public function setDefaultApps(array $defaultApps): void;
  250. /**
  251. * Check whether the given backend is required by at least one app.
  252. *
  253. * @param self::BACKEND_* $backend Name of the backend, one of `self::BACKEND_*`
  254. * @return bool True if at least one app requires the backend
  255. *
  256. * @since 30.0.0
  257. */
  258. public function isBackendRequired(string $backend): bool;
  259. /**
  260. * Clean the appId from forbidden characters
  261. *
  262. * @psalm-taint-escape file
  263. * @psalm-taint-escape include
  264. * @psalm-taint-escape html
  265. * @psalm-taint-escape has_quotes
  266. *
  267. * @since 31.0.0
  268. */
  269. public function cleanAppId(string $app): string;
  270. /**
  271. * Get a list of all apps in the apps folder
  272. *
  273. * @return list<string> an array of app names (string IDs)
  274. * @since 31.0.0
  275. */
  276. public function getAllAppsInAppsFolders(): array;
  277. }