Server.php 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC;
  8. use bantu\IniGetWrapper\IniGetWrapper;
  9. use OC\Accounts\AccountManager;
  10. use OC\App\AppManager;
  11. use OC\App\AppStore\Bundles\BundleFetcher;
  12. use OC\App\AppStore\Fetcher\AppFetcher;
  13. use OC\AppFramework\Bootstrap\Coordinator;
  14. use OC\AppFramework\Http\Request;
  15. use OC\AppFramework\Http\RequestId;
  16. use OC\AppFramework\Utility\TimeFactory;
  17. use OC\Authentication\Events\LoginFailed;
  18. use OC\Authentication\Listeners\LoginFailedListener;
  19. use OC\Authentication\Listeners\UserLoggedInListener;
  20. use OC\Authentication\LoginCredentials\Store;
  21. use OC\Authentication\Token\IProvider;
  22. use OC\Avatar\AvatarManager;
  23. use OC\Blurhash\Listener\GenerateBlurhashMetadata;
  24. use OC\Collaboration\Collaborators\GroupPlugin;
  25. use OC\Collaboration\Collaborators\MailPlugin;
  26. use OC\Collaboration\Collaborators\RemoteGroupPlugin;
  27. use OC\Collaboration\Collaborators\RemotePlugin;
  28. use OC\Collaboration\Collaborators\UserPlugin;
  29. use OC\Collaboration\Reference\ReferenceManager;
  30. use OC\Command\CronBus;
  31. use OC\Comments\ManagerFactory as CommentsManagerFactory;
  32. use OC\Contacts\ContactsMenu\ActionFactory;
  33. use OC\Contacts\ContactsMenu\ContactsStore;
  34. use OC\DB\Connection;
  35. use OC\DB\ConnectionAdapter;
  36. use OC\Diagnostics\EventLogger;
  37. use OC\Diagnostics\QueryLogger;
  38. use OC\Federation\CloudFederationFactory;
  39. use OC\Federation\CloudFederationProviderManager;
  40. use OC\Federation\CloudIdManager;
  41. use OC\Files\Cache\FileAccess;
  42. use OC\Files\Config\MountProviderCollection;
  43. use OC\Files\Config\UserMountCache;
  44. use OC\Files\Config\UserMountCacheListener;
  45. use OC\Files\Lock\LockManager;
  46. use OC\Files\Mount\CacheMountProvider;
  47. use OC\Files\Mount\LocalHomeMountProvider;
  48. use OC\Files\Mount\ObjectHomeMountProvider;
  49. use OC\Files\Mount\ObjectStorePreviewCacheMountProvider;
  50. use OC\Files\Mount\RootMountProvider;
  51. use OC\Files\Node\HookConnector;
  52. use OC\Files\Node\LazyRoot;
  53. use OC\Files\Node\Root;
  54. use OC\Files\SetupManager;
  55. use OC\Files\Storage\StorageFactory;
  56. use OC\Files\Template\TemplateManager;
  57. use OC\Files\Type\Loader;
  58. use OC\Files\View;
  59. use OC\FilesMetadata\FilesMetadataManager;
  60. use OC\FullTextSearch\FullTextSearchManager;
  61. use OC\Http\Client\ClientService;
  62. use OC\Http\Client\NegativeDnsCache;
  63. use OC\IntegrityCheck\Checker;
  64. use OC\IntegrityCheck\Helpers\AppLocator;
  65. use OC\IntegrityCheck\Helpers\EnvironmentHelper;
  66. use OC\IntegrityCheck\Helpers\FileAccessHelper;
  67. use OC\KnownUser\KnownUserService;
  68. use OC\LDAP\NullLDAPProviderFactory;
  69. use OC\Lock\DBLockingProvider;
  70. use OC\Lock\MemcacheLockingProvider;
  71. use OC\Lock\NoopLockingProvider;
  72. use OC\Lockdown\LockdownManager;
  73. use OC\Log\LogFactory;
  74. use OC\Log\PsrLoggerAdapter;
  75. use OC\Mail\Mailer;
  76. use OC\Memcache\ArrayCache;
  77. use OC\Memcache\Factory;
  78. use OC\Notification\Manager;
  79. use OC\OCM\Model\OCMProvider;
  80. use OC\OCM\OCMDiscoveryService;
  81. use OC\OCS\DiscoveryService;
  82. use OC\Preview\GeneratorHelper;
  83. use OC\Preview\IMagickSupport;
  84. use OC\Preview\MimeIconProvider;
  85. use OC\Profile\ProfileManager;
  86. use OC\Profiler\Profiler;
  87. use OC\Remote\Api\ApiFactory;
  88. use OC\Remote\InstanceFactory;
  89. use OC\RichObjectStrings\Validator;
  90. use OC\Route\CachingRouter;
  91. use OC\Route\Router;
  92. use OC\Security\Bruteforce\Throttler;
  93. use OC\Security\CertificateManager;
  94. use OC\Security\CredentialsManager;
  95. use OC\Security\Crypto;
  96. use OC\Security\CSP\ContentSecurityPolicyManager;
  97. use OC\Security\CSP\ContentSecurityPolicyNonceManager;
  98. use OC\Security\CSRF\CsrfTokenManager;
  99. use OC\Security\CSRF\TokenStorage\SessionStorage;
  100. use OC\Security\Hasher;
  101. use OC\Security\Ip\RemoteAddress;
  102. use OC\Security\RateLimiting\Limiter;
  103. use OC\Security\SecureRandom;
  104. use OC\Security\TrustedDomainHelper;
  105. use OC\Security\VerificationToken\VerificationToken;
  106. use OC\Session\CryptoWrapper;
  107. use OC\Settings\DeclarativeManager;
  108. use OC\SetupCheck\SetupCheckManager;
  109. use OC\Share20\ProviderFactory;
  110. use OC\Share20\ShareHelper;
  111. use OC\SpeechToText\SpeechToTextManager;
  112. use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
  113. use OC\Talk\Broker;
  114. use OC\Teams\TeamManager;
  115. use OC\Template\JSCombiner;
  116. use OC\Translation\TranslationManager;
  117. use OC\User\AvailabilityCoordinator;
  118. use OC\User\DisplayNameCache;
  119. use OC\User\Listeners\BeforeUserDeletedListener;
  120. use OC\User\Listeners\UserChangedListener;
  121. use OC\User\Session;
  122. use OCA\Files_External\Service\BackendService;
  123. use OCA\Files_External\Service\GlobalStoragesService;
  124. use OCA\Files_External\Service\UserGlobalStoragesService;
  125. use OCA\Files_External\Service\UserStoragesService;
  126. use OCA\Theming\ImageManager;
  127. use OCA\Theming\Service\BackgroundService;
  128. use OCA\Theming\ThemingDefaults;
  129. use OCA\Theming\Util;
  130. use OCP\Accounts\IAccountManager;
  131. use OCP\App\IAppManager;
  132. use OCP\AppFramework\Utility\ITimeFactory;
  133. use OCP\Authentication\LoginCredentials\IStore;
  134. use OCP\Authentication\Token\IProvider as OCPIProvider;
  135. use OCP\BackgroundJob\IJobList;
  136. use OCP\Collaboration\AutoComplete\IManager;
  137. use OCP\Collaboration\Reference\IReferenceManager;
  138. use OCP\Command\IBus;
  139. use OCP\Comments\ICommentsManager;
  140. use OCP\Contacts\ContactsMenu\IActionFactory;
  141. use OCP\Contacts\ContactsMenu\IContactsStore;
  142. use OCP\Defaults;
  143. use OCP\Diagnostics\IEventLogger;
  144. use OCP\Diagnostics\IQueryLogger;
  145. use OCP\Encryption\IFile;
  146. use OCP\Encryption\Keys\IStorage;
  147. use OCP\EventDispatcher\IEventDispatcher;
  148. use OCP\Federation\ICloudFederationFactory;
  149. use OCP\Federation\ICloudFederationProviderManager;
  150. use OCP\Federation\ICloudIdManager;
  151. use OCP\Files\Cache\IFileAccess;
  152. use OCP\Files\Config\IMountProviderCollection;
  153. use OCP\Files\Config\IUserMountCache;
  154. use OCP\Files\IMimeTypeDetector;
  155. use OCP\Files\IMimeTypeLoader;
  156. use OCP\Files\IRootFolder;
  157. use OCP\Files\Lock\ILockManager;
  158. use OCP\Files\Mount\IMountManager;
  159. use OCP\Files\Storage\IStorageFactory;
  160. use OCP\Files\Template\ITemplateManager;
  161. use OCP\FilesMetadata\IFilesMetadataManager;
  162. use OCP\FullTextSearch\IFullTextSearchManager;
  163. use OCP\GlobalScale\IConfig;
  164. use OCP\Group\ISubAdmin;
  165. use OCP\Http\Client\IClientService;
  166. use OCP\IAppConfig;
  167. use OCP\IAvatarManager;
  168. use OCP\IBinaryFinder;
  169. use OCP\ICache;
  170. use OCP\ICacheFactory;
  171. use OCP\ICertificateManager;
  172. use OCP\IDateTimeFormatter;
  173. use OCP\IDateTimeZone;
  174. use OCP\IDBConnection;
  175. use OCP\IEventSourceFactory;
  176. use OCP\IGroupManager;
  177. use OCP\IInitialStateService;
  178. use OCP\IL10N;
  179. use OCP\INavigationManager;
  180. use OCP\IPhoneNumberUtil;
  181. use OCP\IPreview;
  182. use OCP\IRequest;
  183. use OCP\IRequestId;
  184. use OCP\IServerContainer;
  185. use OCP\ISession;
  186. use OCP\ITagManager;
  187. use OCP\ITempManager;
  188. use OCP\IURLGenerator;
  189. use OCP\IUserManager;
  190. use OCP\IUserSession;
  191. use OCP\L10N\IFactory;
  192. use OCP\LDAP\ILDAPProvider;
  193. use OCP\LDAP\ILDAPProviderFactory;
  194. use OCP\Lock\ILockingProvider;
  195. use OCP\Lockdown\ILockdownManager;
  196. use OCP\Log\ILogFactory;
  197. use OCP\Mail\IMailer;
  198. use OCP\OCM\IOCMDiscoveryService;
  199. use OCP\OCM\IOCMProvider;
  200. use OCP\Preview\IMimeIconProvider;
  201. use OCP\Profile\IProfileManager;
  202. use OCP\Profiler\IProfiler;
  203. use OCP\Remote\Api\IApiFactory;
  204. use OCP\Remote\IInstanceFactory;
  205. use OCP\RichObjectStrings\IRichTextFormatter;
  206. use OCP\RichObjectStrings\IValidator;
  207. use OCP\Route\IRouter;
  208. use OCP\Security\Bruteforce\IThrottler;
  209. use OCP\Security\IContentSecurityPolicyManager;
  210. use OCP\Security\ICredentialsManager;
  211. use OCP\Security\ICrypto;
  212. use OCP\Security\IHasher;
  213. use OCP\Security\Ip\IRemoteAddress;
  214. use OCP\Security\ISecureRandom;
  215. use OCP\Security\ITrustedDomainHelper;
  216. use OCP\Security\RateLimiting\ILimiter;
  217. use OCP\Security\VerificationToken\IVerificationToken;
  218. use OCP\ServerVersion;
  219. use OCP\Settings\IDeclarativeManager;
  220. use OCP\SetupCheck\ISetupCheckManager;
  221. use OCP\Share\IProviderFactory;
  222. use OCP\Share\IShareHelper;
  223. use OCP\SpeechToText\ISpeechToTextManager;
  224. use OCP\SystemTag\ISystemTagManager;
  225. use OCP\SystemTag\ISystemTagObjectMapper;
  226. use OCP\Talk\IBroker;
  227. use OCP\Teams\ITeamManager;
  228. use OCP\Translation\ITranslationManager;
  229. use OCP\User\Events\BeforeUserDeletedEvent;
  230. use OCP\User\Events\BeforeUserLoggedInEvent;
  231. use OCP\User\Events\BeforeUserLoggedInWithCookieEvent;
  232. use OCP\User\Events\BeforeUserLoggedOutEvent;
  233. use OCP\User\Events\PostLoginEvent;
  234. use OCP\User\Events\UserChangedEvent;
  235. use OCP\User\Events\UserLoggedInEvent;
  236. use OCP\User\Events\UserLoggedInWithCookieEvent;
  237. use OCP\User\Events\UserLoggedOutEvent;
  238. use OCP\User\IAvailabilityCoordinator;
  239. use Psr\Container\ContainerExceptionInterface;
  240. use Psr\Container\ContainerInterface;
  241. use Psr\Log\LoggerInterface;
  242. /**
  243. * Class Server
  244. *
  245. * @package OC
  246. *
  247. * TODO: hookup all manager classes
  248. */
  249. class Server extends ServerContainer implements IServerContainer {
  250. /** @var string */
  251. private $webRoot;
  252. /**
  253. * @param string $webRoot
  254. * @param \OC\Config $config
  255. */
  256. public function __construct($webRoot, \OC\Config $config) {
  257. parent::__construct();
  258. $this->webRoot = $webRoot;
  259. // To find out if we are running from CLI or not
  260. $this->registerParameter('isCLI', \OC::$CLI);
  261. $this->registerParameter('serverRoot', \OC::$SERVERROOT);
  262. $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
  263. return $c;
  264. });
  265. $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
  266. return $c;
  267. });
  268. $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
  269. $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
  270. $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
  271. $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
  272. $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
  273. $this->registerAlias(ITemplateManager::class, TemplateManager::class);
  274. $this->registerAlias(IActionFactory::class, ActionFactory::class);
  275. $this->registerService(View::class, function (Server $c) {
  276. return new View();
  277. }, false);
  278. $this->registerService(IPreview::class, function (ContainerInterface $c) {
  279. return new PreviewManager(
  280. $c->get(\OCP\IConfig::class),
  281. $c->get(IRootFolder::class),
  282. new \OC\Preview\Storage\Root(
  283. $c->get(IRootFolder::class),
  284. $c->get(SystemConfig::class)
  285. ),
  286. $c->get(IEventDispatcher::class),
  287. $c->get(GeneratorHelper::class),
  288. $c->get(ISession::class)->get('user_id'),
  289. $c->get(Coordinator::class),
  290. $c->get(IServerContainer::class),
  291. $c->get(IBinaryFinder::class),
  292. $c->get(IMagickSupport::class)
  293. );
  294. });
  295. $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class);
  296. $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
  297. return new \OC\Preview\Watcher(
  298. new \OC\Preview\Storage\Root(
  299. $c->get(IRootFolder::class),
  300. $c->get(SystemConfig::class)
  301. )
  302. );
  303. });
  304. $this->registerService(IProfiler::class, function (Server $c) {
  305. return new Profiler($c->get(SystemConfig::class));
  306. });
  307. $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager {
  308. $view = new View();
  309. $util = new Encryption\Util(
  310. $view,
  311. $c->get(IUserManager::class),
  312. $c->get(IGroupManager::class),
  313. $c->get(\OCP\IConfig::class)
  314. );
  315. return new Encryption\Manager(
  316. $c->get(\OCP\IConfig::class),
  317. $c->get(LoggerInterface::class),
  318. $c->getL10N('core'),
  319. new View(),
  320. $util,
  321. new ArrayCache()
  322. );
  323. });
  324. $this->registerService(IFile::class, function (ContainerInterface $c) {
  325. $util = new Encryption\Util(
  326. new View(),
  327. $c->get(IUserManager::class),
  328. $c->get(IGroupManager::class),
  329. $c->get(\OCP\IConfig::class)
  330. );
  331. return new Encryption\File(
  332. $util,
  333. $c->get(IRootFolder::class),
  334. $c->get(\OCP\Share\IManager::class)
  335. );
  336. });
  337. $this->registerService(IStorage::class, function (ContainerInterface $c) {
  338. $view = new View();
  339. $util = new Encryption\Util(
  340. $view,
  341. $c->get(IUserManager::class),
  342. $c->get(IGroupManager::class),
  343. $c->get(\OCP\IConfig::class)
  344. );
  345. return new Encryption\Keys\Storage(
  346. $view,
  347. $util,
  348. $c->get(ICrypto::class),
  349. $c->get(\OCP\IConfig::class)
  350. );
  351. });
  352. $this->registerAlias(\OCP\ITagManager::class, TagManager::class);
  353. $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
  354. /** @var \OCP\IConfig $config */
  355. $config = $c->get(\OCP\IConfig::class);
  356. $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
  357. return new $factoryClass($this);
  358. });
  359. $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
  360. return $c->get('SystemTagManagerFactory')->getManager();
  361. });
  362. /** @deprecated 19.0.0 */
  363. $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
  364. $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
  365. return $c->get('SystemTagManagerFactory')->getObjectMapper();
  366. });
  367. $this->registerAlias(IFileAccess::class, FileAccess::class);
  368. $this->registerService('RootFolder', function (ContainerInterface $c) {
  369. $manager = \OC\Files\Filesystem::getMountManager();
  370. $view = new View();
  371. /** @var IUserSession $userSession */
  372. $userSession = $c->get(IUserSession::class);
  373. $root = new Root(
  374. $manager,
  375. $view,
  376. $userSession->getUser(),
  377. $c->get(IUserMountCache::class),
  378. $this->get(LoggerInterface::class),
  379. $this->get(IUserManager::class),
  380. $this->get(IEventDispatcher::class),
  381. $this->get(ICacheFactory::class),
  382. );
  383. $previewConnector = new \OC\Preview\WatcherConnector(
  384. $root,
  385. $c->get(SystemConfig::class)
  386. );
  387. $previewConnector->connectWatcher();
  388. return $root;
  389. });
  390. $this->registerService(HookConnector::class, function (ContainerInterface $c) {
  391. return new HookConnector(
  392. $c->get(IRootFolder::class),
  393. new View(),
  394. $c->get(IEventDispatcher::class),
  395. $c->get(LoggerInterface::class)
  396. );
  397. });
  398. $this->registerService(IRootFolder::class, function (ContainerInterface $c) {
  399. return new LazyRoot(function () use ($c) {
  400. return $c->get('RootFolder');
  401. });
  402. });
  403. $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
  404. $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
  405. return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
  406. });
  407. $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
  408. $groupManager = new \OC\Group\Manager(
  409. $this->get(IUserManager::class),
  410. $this->get(IEventDispatcher::class),
  411. $this->get(LoggerInterface::class),
  412. $this->get(ICacheFactory::class),
  413. $this->get(IRemoteAddress::class),
  414. );
  415. return $groupManager;
  416. });
  417. $this->registerService(Store::class, function (ContainerInterface $c) {
  418. $session = $c->get(ISession::class);
  419. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  420. $tokenProvider = $c->get(IProvider::class);
  421. } else {
  422. $tokenProvider = null;
  423. }
  424. $logger = $c->get(LoggerInterface::class);
  425. $crypto = $c->get(ICrypto::class);
  426. return new Store($session, $logger, $crypto, $tokenProvider);
  427. });
  428. $this->registerAlias(IStore::class, Store::class);
  429. $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
  430. $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class);
  431. $this->registerService(\OC\User\Session::class, function (Server $c) {
  432. $manager = $c->get(IUserManager::class);
  433. $session = new \OC\Session\Memory();
  434. $timeFactory = new TimeFactory();
  435. // Token providers might require a working database. This code
  436. // might however be called when Nextcloud is not yet setup.
  437. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  438. $provider = $c->get(IProvider::class);
  439. } else {
  440. $provider = null;
  441. }
  442. $userSession = new \OC\User\Session(
  443. $manager,
  444. $session,
  445. $timeFactory,
  446. $provider,
  447. $c->get(\OCP\IConfig::class),
  448. $c->get(ISecureRandom::class),
  449. $c->get('LockdownManager'),
  450. $c->get(LoggerInterface::class),
  451. $c->get(IEventDispatcher::class),
  452. );
  453. /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
  454. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  455. \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
  456. });
  457. /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
  458. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  459. /** @var \OC\User\User $user */
  460. \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
  461. });
  462. /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
  463. $userSession->listen('\OC\User', 'preDelete', function ($user) {
  464. /** @var \OC\User\User $user */
  465. \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
  466. });
  467. /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
  468. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  469. /** @var \OC\User\User $user */
  470. \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
  471. });
  472. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  473. /** @var \OC\User\User $user */
  474. \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
  475. });
  476. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  477. /** @var \OC\User\User $user */
  478. \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
  479. });
  480. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  481. \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
  482. /** @var IEventDispatcher $dispatcher */
  483. $dispatcher = $this->get(IEventDispatcher::class);
  484. $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
  485. });
  486. $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
  487. /** @var \OC\User\User $user */
  488. \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
  489. /** @var IEventDispatcher $dispatcher */
  490. $dispatcher = $this->get(IEventDispatcher::class);
  491. $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
  492. });
  493. $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
  494. /** @var IEventDispatcher $dispatcher */
  495. $dispatcher = $this->get(IEventDispatcher::class);
  496. $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
  497. });
  498. $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
  499. /** @var \OC\User\User $user */
  500. \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
  501. /** @var IEventDispatcher $dispatcher */
  502. $dispatcher = $this->get(IEventDispatcher::class);
  503. $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
  504. });
  505. $userSession->listen('\OC\User', 'logout', function ($user) {
  506. \OC_Hook::emit('OC_User', 'logout', []);
  507. /** @var IEventDispatcher $dispatcher */
  508. $dispatcher = $this->get(IEventDispatcher::class);
  509. $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
  510. });
  511. $userSession->listen('\OC\User', 'postLogout', function ($user) {
  512. /** @var IEventDispatcher $dispatcher */
  513. $dispatcher = $this->get(IEventDispatcher::class);
  514. $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
  515. });
  516. $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
  517. /** @var \OC\User\User $user */
  518. \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
  519. });
  520. return $userSession;
  521. });
  522. $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
  523. $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
  524. $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
  525. $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
  526. $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
  527. return new \OC\SystemConfig($config);
  528. });
  529. $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
  530. $this->registerService(IFactory::class, function (Server $c) {
  531. return new \OC\L10N\Factory(
  532. $c->get(\OCP\IConfig::class),
  533. $c->getRequest(),
  534. $c->get(IUserSession::class),
  535. $c->get(ICacheFactory::class),
  536. \OC::$SERVERROOT,
  537. $c->get(IAppManager::class),
  538. );
  539. });
  540. $this->registerAlias(IURLGenerator::class, URLGenerator::class);
  541. $this->registerService(ICache::class, function ($c) {
  542. return new Cache\File();
  543. });
  544. $this->registerService(Factory::class, function (Server $c) {
  545. $profiler = $c->get(IProfiler::class);
  546. $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class),
  547. $profiler,
  548. ArrayCache::class,
  549. ArrayCache::class,
  550. ArrayCache::class
  551. );
  552. /** @var SystemConfig $config */
  553. $config = $c->get(SystemConfig::class);
  554. /** @var ServerVersion $serverVersion */
  555. $serverVersion = $c->get(ServerVersion::class);
  556. if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  557. $logQuery = $config->getValue('log_query');
  558. $prefixClosure = function () use ($logQuery, $serverVersion) {
  559. if (!$logQuery) {
  560. try {
  561. $v = \OC_App::getAppVersions();
  562. } catch (\Doctrine\DBAL\Exception $e) {
  563. // Database service probably unavailable
  564. // Probably related to https://github.com/nextcloud/server/issues/37424
  565. return null;
  566. }
  567. } else {
  568. // If the log_query is enabled, we can not get the app versions
  569. // as that does a query, which will be logged and the logging
  570. // depends on redis and here we are back again in the same function.
  571. $v = [
  572. 'log_query' => 'enabled',
  573. ];
  574. }
  575. $v['core'] = implode(',', $serverVersion->getVersion());
  576. $version = implode(',', $v);
  577. $instanceId = \OC_Util::getInstanceId();
  578. $path = \OC::$SERVERROOT;
  579. return md5($instanceId . '-' . $version . '-' . $path);
  580. };
  581. return new \OC\Memcache\Factory($prefixClosure,
  582. $c->get(LoggerInterface::class),
  583. $profiler,
  584. /** @psalm-taint-escape callable */
  585. $config->getValue('memcache.local', null),
  586. /** @psalm-taint-escape callable */
  587. $config->getValue('memcache.distributed', null),
  588. /** @psalm-taint-escape callable */
  589. $config->getValue('memcache.locking', null),
  590. /** @psalm-taint-escape callable */
  591. $config->getValue('redis_log_file')
  592. );
  593. }
  594. return $arrayCacheFactory;
  595. });
  596. $this->registerAlias(ICacheFactory::class, Factory::class);
  597. $this->registerService('RedisFactory', function (Server $c) {
  598. $systemConfig = $c->get(SystemConfig::class);
  599. return new RedisFactory($systemConfig, $c->get(IEventLogger::class));
  600. });
  601. $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
  602. $l10n = $this->get(IFactory::class)->get('lib');
  603. return new \OC\Activity\Manager(
  604. $c->getRequest(),
  605. $c->get(IUserSession::class),
  606. $c->get(\OCP\IConfig::class),
  607. $c->get(IValidator::class),
  608. $c->get(IRichTextFormatter::class),
  609. $l10n
  610. );
  611. });
  612. $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
  613. return new \OC\Activity\EventMerger(
  614. $c->getL10N('lib')
  615. );
  616. });
  617. $this->registerAlias(IValidator::class, Validator::class);
  618. $this->registerService(AvatarManager::class, function (Server $c) {
  619. return new AvatarManager(
  620. $c->get(IUserSession::class),
  621. $c->get(\OC\User\Manager::class),
  622. $c->getAppDataDir('avatar'),
  623. $c->getL10N('lib'),
  624. $c->get(LoggerInterface::class),
  625. $c->get(\OCP\IConfig::class),
  626. $c->get(IAccountManager::class),
  627. $c->get(KnownUserService::class)
  628. );
  629. });
  630. $this->registerAlias(IAvatarManager::class, AvatarManager::class);
  631. $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
  632. $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
  633. $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class);
  634. /** Only used by the PsrLoggerAdapter should not be used by apps */
  635. $this->registerService(\OC\Log::class, function (Server $c) {
  636. $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
  637. $factory = new LogFactory($c, $this->get(SystemConfig::class));
  638. $logger = $factory->get($logType);
  639. $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
  640. return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry);
  641. });
  642. // PSR-3 logger
  643. $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
  644. $this->registerService(ILogFactory::class, function (Server $c) {
  645. return new LogFactory($c, $this->get(SystemConfig::class));
  646. });
  647. $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
  648. $this->registerService(Router::class, function (Server $c) {
  649. $cacheFactory = $c->get(ICacheFactory::class);
  650. if ($cacheFactory->isLocalCacheAvailable()) {
  651. $router = $c->resolve(CachingRouter::class);
  652. } else {
  653. $router = $c->resolve(Router::class);
  654. }
  655. return $router;
  656. });
  657. $this->registerAlias(IRouter::class, Router::class);
  658. $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
  659. $config = $c->get(\OCP\IConfig::class);
  660. if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) {
  661. $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend(
  662. $c->get(AllConfig::class),
  663. $this->get(ICacheFactory::class),
  664. new \OC\AppFramework\Utility\TimeFactory()
  665. );
  666. } else {
  667. $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend(
  668. $c->get(AllConfig::class),
  669. $c->get(IDBConnection::class),
  670. new \OC\AppFramework\Utility\TimeFactory()
  671. );
  672. }
  673. return $backend;
  674. });
  675. $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
  676. $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class);
  677. $this->registerAlias(IVerificationToken::class, VerificationToken::class);
  678. $this->registerAlias(ICrypto::class, Crypto::class);
  679. $this->registerAlias(IHasher::class, Hasher::class);
  680. $this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
  681. $this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
  682. $this->registerService(Connection::class, function (Server $c) {
  683. $systemConfig = $c->get(SystemConfig::class);
  684. $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class));
  685. $type = $systemConfig->getValue('dbtype', 'sqlite');
  686. if (!$factory->isValidType($type)) {
  687. throw new \OC\DatabaseException('Invalid database type');
  688. }
  689. $connection = $factory->getConnection($type, []);
  690. return $connection;
  691. });
  692. $this->registerAlias(ICertificateManager::class, CertificateManager::class);
  693. $this->registerAlias(IClientService::class, ClientService::class);
  694. $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) {
  695. return new NegativeDnsCache(
  696. $c->get(ICacheFactory::class),
  697. );
  698. });
  699. $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
  700. $this->registerService(IEventLogger::class, function (ContainerInterface $c) {
  701. return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class));
  702. });
  703. $this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
  704. $queryLogger = new QueryLogger();
  705. if ($c->get(SystemConfig::class)->getValue('debug', false)) {
  706. // In debug mode, module is being activated by default
  707. $queryLogger->activate();
  708. }
  709. return $queryLogger;
  710. });
  711. $this->registerAlias(ITempManager::class, TempManager::class);
  712. $this->registerService(AppManager::class, function (ContainerInterface $c) {
  713. // TODO: use auto-wiring
  714. return new \OC\App\AppManager(
  715. $c->get(IUserSession::class),
  716. $c->get(\OCP\IConfig::class),
  717. $c->get(IGroupManager::class),
  718. $c->get(ICacheFactory::class),
  719. $c->get(IEventDispatcher::class),
  720. $c->get(LoggerInterface::class),
  721. );
  722. });
  723. $this->registerAlias(IAppManager::class, AppManager::class);
  724. $this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
  725. $this->registerService(IDateTimeFormatter::class, function (Server $c) {
  726. $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
  727. return new DateTimeFormatter(
  728. $c->get(IDateTimeZone::class)->getTimeZone(),
  729. $c->getL10N('lib', $language)
  730. );
  731. });
  732. $this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
  733. $mountCache = $c->get(UserMountCache::class);
  734. $listener = new UserMountCacheListener($mountCache);
  735. $listener->listen($c->get(IUserManager::class));
  736. return $mountCache;
  737. });
  738. $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
  739. $loader = $c->get(IStorageFactory::class);
  740. $mountCache = $c->get(IUserMountCache::class);
  741. $eventLogger = $c->get(IEventLogger::class);
  742. $manager = new MountProviderCollection($loader, $mountCache, $eventLogger);
  743. // builtin providers
  744. $config = $c->get(\OCP\IConfig::class);
  745. $logger = $c->get(LoggerInterface::class);
  746. $manager->registerProvider(new CacheMountProvider($config));
  747. $manager->registerHomeProvider(new LocalHomeMountProvider());
  748. $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
  749. $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class)));
  750. $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
  751. return $manager;
  752. });
  753. $this->registerService(IBus::class, function (ContainerInterface $c) {
  754. $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus');
  755. if ($busClass) {
  756. [$app, $class] = explode('::', $busClass, 2);
  757. if ($c->get(IAppManager::class)->isInstalled($app)) {
  758. \OC_App::loadApp($app);
  759. return $c->get($class);
  760. } else {
  761. throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
  762. }
  763. } else {
  764. $jobList = $c->get(IJobList::class);
  765. return new CronBus($jobList);
  766. }
  767. });
  768. $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
  769. $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
  770. $this->registerAlias(IThrottler::class, Throttler::class);
  771. $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) {
  772. $config = $c->get(\OCP\IConfig::class);
  773. if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false)
  774. && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) {
  775. $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class);
  776. } else {
  777. $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class);
  778. }
  779. return $backend;
  780. });
  781. $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class);
  782. $this->registerService(Checker::class, function (ContainerInterface $c) {
  783. // IConfig and IAppManager requires a working database. This code
  784. // might however be called when ownCloud is not yet setup.
  785. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  786. $config = $c->get(\OCP\IConfig::class);
  787. $appConfig = $c->get(\OCP\IAppConfig::class);
  788. } else {
  789. $config = $appConfig = $appManager = null;
  790. }
  791. $appManager = $c->get(IAppManager::class);
  792. return new Checker(
  793. $c->get(ServerVersion::class),
  794. $c->get(EnvironmentHelper::class),
  795. new FileAccessHelper(),
  796. new AppLocator(),
  797. $config,
  798. $appConfig,
  799. $c->get(ICacheFactory::class),
  800. $appManager,
  801. $c->get(IMimeTypeDetector::class)
  802. );
  803. });
  804. $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
  805. if (isset($this['urlParams'])) {
  806. $urlParams = $this['urlParams'];
  807. } else {
  808. $urlParams = [];
  809. }
  810. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  811. && in_array('fakeinput', stream_get_wrappers())
  812. ) {
  813. $stream = 'fakeinput://data';
  814. } else {
  815. $stream = 'php://input';
  816. }
  817. return new Request(
  818. [
  819. 'get' => $_GET,
  820. 'post' => $_POST,
  821. 'files' => $_FILES,
  822. 'server' => $_SERVER,
  823. 'env' => $_ENV,
  824. 'cookies' => $_COOKIE,
  825. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  826. ? $_SERVER['REQUEST_METHOD']
  827. : '',
  828. 'urlParams' => $urlParams,
  829. ],
  830. $this->get(IRequestId::class),
  831. $this->get(\OCP\IConfig::class),
  832. $this->get(CsrfTokenManager::class),
  833. $stream
  834. );
  835. });
  836. $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId {
  837. return new RequestId(
  838. $_SERVER['UNIQUE_ID'] ?? '',
  839. $this->get(ISecureRandom::class)
  840. );
  841. });
  842. $this->registerService(IMailer::class, function (Server $c) {
  843. return new Mailer(
  844. $c->get(\OCP\IConfig::class),
  845. $c->get(LoggerInterface::class),
  846. $c->get(Defaults::class),
  847. $c->get(IURLGenerator::class),
  848. $c->getL10N('lib'),
  849. $c->get(IEventDispatcher::class),
  850. $c->get(IFactory::class)
  851. );
  852. });
  853. /** @since 30.0.0 */
  854. $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class);
  855. $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
  856. $config = $c->get(\OCP\IConfig::class);
  857. $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
  858. if (is_null($factoryClass) || !class_exists($factoryClass)) {
  859. return new NullLDAPProviderFactory($this);
  860. }
  861. /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
  862. return new $factoryClass($this);
  863. });
  864. $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
  865. $factory = $c->get(ILDAPProviderFactory::class);
  866. return $factory->getLDAPProvider();
  867. });
  868. $this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
  869. $ini = $c->get(IniGetWrapper::class);
  870. $config = $c->get(\OCP\IConfig::class);
  871. $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
  872. if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  873. /** @var \OC\Memcache\Factory $memcacheFactory */
  874. $memcacheFactory = $c->get(ICacheFactory::class);
  875. $memcache = $memcacheFactory->createLocking('lock');
  876. if (!($memcache instanceof \OC\Memcache\NullCache)) {
  877. $timeFactory = $c->get(ITimeFactory::class);
  878. return new MemcacheLockingProvider($memcache, $timeFactory, $ttl);
  879. }
  880. return new DBLockingProvider(
  881. $c->get(IDBConnection::class),
  882. new TimeFactory(),
  883. $ttl,
  884. !\OC::$CLI
  885. );
  886. }
  887. return new NoopLockingProvider();
  888. });
  889. $this->registerService(ILockManager::class, function (Server $c): LockManager {
  890. return new LockManager();
  891. });
  892. $this->registerAlias(ILockdownManager::class, 'LockdownManager');
  893. $this->registerService(SetupManager::class, function ($c) {
  894. // create the setupmanager through the mount manager to resolve the cyclic dependency
  895. return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
  896. });
  897. $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
  898. $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
  899. return new \OC\Files\Type\Detection(
  900. $c->get(IURLGenerator::class),
  901. $c->get(LoggerInterface::class),
  902. \OC::$configDir,
  903. \OC::$SERVERROOT . '/resources/config/'
  904. );
  905. });
  906. $this->registerAlias(IMimeTypeLoader::class, Loader::class);
  907. $this->registerService(BundleFetcher::class, function () {
  908. return new BundleFetcher($this->getL10N('lib'));
  909. });
  910. $this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
  911. $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
  912. $manager = new CapabilitiesManager($c->get(LoggerInterface::class));
  913. $manager->registerCapability(function () use ($c) {
  914. return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
  915. });
  916. $manager->registerCapability(function () use ($c) {
  917. return $c->get(\OC\Security\Bruteforce\Capabilities::class);
  918. });
  919. return $manager;
  920. });
  921. $this->registerService(ICommentsManager::class, function (Server $c) {
  922. $config = $c->get(\OCP\IConfig::class);
  923. $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
  924. /** @var \OCP\Comments\ICommentsManagerFactory $factory */
  925. $factory = new $factoryClass($this);
  926. $manager = $factory->getManager();
  927. $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
  928. $manager = $c->get(IUserManager::class);
  929. $userDisplayName = $manager->getDisplayName($id);
  930. if ($userDisplayName === null) {
  931. $l = $c->get(IFactory::class)->get('core');
  932. return $l->t('Unknown account');
  933. }
  934. return $userDisplayName;
  935. });
  936. return $manager;
  937. });
  938. $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
  939. $this->registerService('ThemingDefaults', function (Server $c) {
  940. try {
  941. $classExists = class_exists('OCA\Theming\ThemingDefaults');
  942. } catch (\OCP\AutoloadNotAllowedException $e) {
  943. // App disabled or in maintenance mode
  944. $classExists = false;
  945. }
  946. if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
  947. $backgroundService = new BackgroundService(
  948. $c->get(IRootFolder::class),
  949. $c->getAppDataDir('theming'),
  950. $c->get(IAppConfig::class),
  951. $c->get(\OCP\IConfig::class),
  952. $c->get(ISession::class)->get('user_id'),
  953. );
  954. $imageManager = new ImageManager(
  955. $c->get(\OCP\IConfig::class),
  956. $c->getAppDataDir('theming'),
  957. $c->get(IURLGenerator::class),
  958. $c->get(ICacheFactory::class),
  959. $c->get(LoggerInterface::class),
  960. $c->get(ITempManager::class),
  961. $backgroundService,
  962. );
  963. return new ThemingDefaults(
  964. $c->get(\OCP\IConfig::class),
  965. $c->get(\OCP\IAppConfig::class),
  966. $c->getL10N('theming'),
  967. $c->get(IUserSession::class),
  968. $c->get(IURLGenerator::class),
  969. $c->get(ICacheFactory::class),
  970. new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager),
  971. $imageManager,
  972. $c->get(IAppManager::class),
  973. $c->get(INavigationManager::class),
  974. $backgroundService,
  975. );
  976. }
  977. return new \OC_Defaults();
  978. });
  979. $this->registerService(JSCombiner::class, function (Server $c) {
  980. return new JSCombiner(
  981. $c->getAppDataDir('js'),
  982. $c->get(IURLGenerator::class),
  983. $this->get(ICacheFactory::class),
  984. $c->get(SystemConfig::class),
  985. $c->get(LoggerInterface::class)
  986. );
  987. });
  988. $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
  989. $this->registerService('CryptoWrapper', function (ContainerInterface $c) {
  990. // FIXME: Instantiated here due to cyclic dependency
  991. $request = new Request(
  992. [
  993. 'get' => $_GET,
  994. 'post' => $_POST,
  995. 'files' => $_FILES,
  996. 'server' => $_SERVER,
  997. 'env' => $_ENV,
  998. 'cookies' => $_COOKIE,
  999. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  1000. ? $_SERVER['REQUEST_METHOD']
  1001. : null,
  1002. ],
  1003. $c->get(IRequestId::class),
  1004. $c->get(\OCP\IConfig::class)
  1005. );
  1006. return new CryptoWrapper(
  1007. $c->get(\OCP\IConfig::class),
  1008. $c->get(ICrypto::class),
  1009. $c->get(ISecureRandom::class),
  1010. $request
  1011. );
  1012. });
  1013. $this->registerService(SessionStorage::class, function (ContainerInterface $c) {
  1014. return new SessionStorage($c->get(ISession::class));
  1015. });
  1016. $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
  1017. $this->registerService(IProviderFactory::class, function (ContainerInterface $c) {
  1018. $config = $c->get(\OCP\IConfig::class);
  1019. $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
  1020. /** @var \OCP\Share\IProviderFactory $factory */
  1021. return new $factoryClass($this);
  1022. });
  1023. $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
  1024. $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
  1025. $instance = new Collaboration\Collaborators\Search($c);
  1026. // register default plugins
  1027. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
  1028. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
  1029. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
  1030. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
  1031. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
  1032. return $instance;
  1033. });
  1034. $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
  1035. $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
  1036. $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
  1037. $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
  1038. $this->registerAlias(IReferenceManager::class, ReferenceManager::class);
  1039. $this->registerAlias(ITeamManager::class, TeamManager::class);
  1040. $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
  1041. $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
  1042. $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
  1043. return new \OC\Files\AppData\Factory(
  1044. $c->get(IRootFolder::class),
  1045. $c->get(SystemConfig::class)
  1046. );
  1047. });
  1048. $this->registerService('LockdownManager', function (ContainerInterface $c) {
  1049. return new LockdownManager(function () use ($c) {
  1050. return $c->get(ISession::class);
  1051. });
  1052. });
  1053. $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
  1054. return new DiscoveryService(
  1055. $c->get(ICacheFactory::class),
  1056. $c->get(IClientService::class)
  1057. );
  1058. });
  1059. $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class);
  1060. $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
  1061. return new CloudIdManager(
  1062. $c->get(\OCP\Contacts\IManager::class),
  1063. $c->get(IURLGenerator::class),
  1064. $c->get(IUserManager::class),
  1065. $c->get(ICacheFactory::class),
  1066. $c->get(IEventDispatcher::class),
  1067. );
  1068. });
  1069. $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
  1070. $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
  1071. return new CloudFederationProviderManager(
  1072. $c->get(\OCP\IConfig::class),
  1073. $c->get(IAppManager::class),
  1074. $c->get(IClientService::class),
  1075. $c->get(ICloudIdManager::class),
  1076. $c->get(IOCMDiscoveryService::class),
  1077. $c->get(LoggerInterface::class)
  1078. );
  1079. });
  1080. $this->registerService(ICloudFederationFactory::class, function (Server $c) {
  1081. return new CloudFederationFactory();
  1082. });
  1083. $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
  1084. $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
  1085. $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class);
  1086. $this->registerService(Defaults::class, function (Server $c) {
  1087. return new Defaults(
  1088. $c->get('ThemingDefaults')
  1089. );
  1090. });
  1091. $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
  1092. return $c->get(\OCP\IUserSession::class)->getSession();
  1093. }, false);
  1094. $this->registerService(IShareHelper::class, function (ContainerInterface $c) {
  1095. return new ShareHelper(
  1096. $c->get(\OCP\Share\IManager::class)
  1097. );
  1098. });
  1099. $this->registerService(Installer::class, function (ContainerInterface $c) {
  1100. return new Installer(
  1101. $c->get(AppFetcher::class),
  1102. $c->get(IClientService::class),
  1103. $c->get(ITempManager::class),
  1104. $c->get(LoggerInterface::class),
  1105. $c->get(\OCP\IConfig::class),
  1106. \OC::$CLI
  1107. );
  1108. });
  1109. $this->registerService(IApiFactory::class, function (ContainerInterface $c) {
  1110. return new ApiFactory($c->get(IClientService::class));
  1111. });
  1112. $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
  1113. $memcacheFactory = $c->get(ICacheFactory::class);
  1114. return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
  1115. });
  1116. $this->registerAlias(IContactsStore::class, ContactsStore::class);
  1117. $this->registerAlias(IAccountManager::class, AccountManager::class);
  1118. $this->registerAlias(IStorageFactory::class, StorageFactory::class);
  1119. $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
  1120. $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
  1121. $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class);
  1122. $this->registerAlias(ISubAdmin::class, SubAdmin::class);
  1123. $this->registerAlias(IInitialStateService::class, InitialStateService::class);
  1124. $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class);
  1125. $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
  1126. $this->registerAlias(IBroker::class, Broker::class);
  1127. $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class);
  1128. $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class);
  1129. $this->registerAlias(IBinaryFinder::class, BinaryFinder::class);
  1130. $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class);
  1131. $this->registerAlias(ITranslationManager::class, TranslationManager::class);
  1132. $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class);
  1133. $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class);
  1134. $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class);
  1135. $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class);
  1136. $this->registerAlias(ILimiter::class, Limiter::class);
  1137. $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class);
  1138. $this->registerAlias(IOCMProvider::class, OCMProvider::class);
  1139. $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class);
  1140. $this->registerAlias(IProfileManager::class, ProfileManager::class);
  1141. $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class);
  1142. $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class);
  1143. $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class);
  1144. $this->registerAlias(IRemoteAddress::class, RemoteAddress::class);
  1145. $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class);
  1146. $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class);
  1147. $this->connectDispatcher();
  1148. }
  1149. public function boot() {
  1150. /** @var HookConnector $hookConnector */
  1151. $hookConnector = $this->get(HookConnector::class);
  1152. $hookConnector->viewToNode();
  1153. }
  1154. /**
  1155. * @return \OCP\Calendar\IManager
  1156. * @deprecated 20.0.0
  1157. */
  1158. public function getCalendarManager() {
  1159. return $this->get(\OC\Calendar\Manager::class);
  1160. }
  1161. /**
  1162. * @return \OCP\Calendar\Resource\IManager
  1163. * @deprecated 20.0.0
  1164. */
  1165. public function getCalendarResourceBackendManager() {
  1166. return $this->get(\OC\Calendar\Resource\Manager::class);
  1167. }
  1168. /**
  1169. * @return \OCP\Calendar\Room\IManager
  1170. * @deprecated 20.0.0
  1171. */
  1172. public function getCalendarRoomBackendManager() {
  1173. return $this->get(\OC\Calendar\Room\Manager::class);
  1174. }
  1175. private function connectDispatcher(): void {
  1176. /** @var IEventDispatcher $eventDispatcher */
  1177. $eventDispatcher = $this->get(IEventDispatcher::class);
  1178. $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class);
  1179. $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
  1180. $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class);
  1181. $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class);
  1182. FilesMetadataManager::loadListeners($eventDispatcher);
  1183. GenerateBlurhashMetadata::loadListeners($eventDispatcher);
  1184. }
  1185. /**
  1186. * @return \OCP\Contacts\IManager
  1187. * @deprecated 20.0.0
  1188. */
  1189. public function getContactsManager() {
  1190. return $this->get(\OCP\Contacts\IManager::class);
  1191. }
  1192. /**
  1193. * @return \OC\Encryption\Manager
  1194. * @deprecated 20.0.0
  1195. */
  1196. public function getEncryptionManager() {
  1197. return $this->get(\OCP\Encryption\IManager::class);
  1198. }
  1199. /**
  1200. * @return \OC\Encryption\File
  1201. * @deprecated 20.0.0
  1202. */
  1203. public function getEncryptionFilesHelper() {
  1204. return $this->get(IFile::class);
  1205. }
  1206. /**
  1207. * @return \OCP\Encryption\Keys\IStorage
  1208. * @deprecated 20.0.0
  1209. */
  1210. public function getEncryptionKeyStorage() {
  1211. return $this->get(IStorage::class);
  1212. }
  1213. /**
  1214. * The current request object holding all information about the request
  1215. * currently being processed is returned from this method.
  1216. * In case the current execution was not initiated by a web request null is returned
  1217. *
  1218. * @return \OCP\IRequest
  1219. * @deprecated 20.0.0
  1220. */
  1221. public function getRequest() {
  1222. return $this->get(IRequest::class);
  1223. }
  1224. /**
  1225. * Returns the preview manager which can create preview images for a given file
  1226. *
  1227. * @return IPreview
  1228. * @deprecated 20.0.0
  1229. */
  1230. public function getPreviewManager() {
  1231. return $this->get(IPreview::class);
  1232. }
  1233. /**
  1234. * Returns the tag manager which can get and set tags for different object types
  1235. *
  1236. * @see \OCP\ITagManager::load()
  1237. * @return ITagManager
  1238. * @deprecated 20.0.0
  1239. */
  1240. public function getTagManager() {
  1241. return $this->get(ITagManager::class);
  1242. }
  1243. /**
  1244. * Returns the system-tag manager
  1245. *
  1246. * @return ISystemTagManager
  1247. *
  1248. * @since 9.0.0
  1249. * @deprecated 20.0.0
  1250. */
  1251. public function getSystemTagManager() {
  1252. return $this->get(ISystemTagManager::class);
  1253. }
  1254. /**
  1255. * Returns the system-tag object mapper
  1256. *
  1257. * @return ISystemTagObjectMapper
  1258. *
  1259. * @since 9.0.0
  1260. * @deprecated 20.0.0
  1261. */
  1262. public function getSystemTagObjectMapper() {
  1263. return $this->get(ISystemTagObjectMapper::class);
  1264. }
  1265. /**
  1266. * Returns the avatar manager, used for avatar functionality
  1267. *
  1268. * @return IAvatarManager
  1269. * @deprecated 20.0.0
  1270. */
  1271. public function getAvatarManager() {
  1272. return $this->get(IAvatarManager::class);
  1273. }
  1274. /**
  1275. * Returns the root folder of ownCloud's data directory
  1276. *
  1277. * @return IRootFolder
  1278. * @deprecated 20.0.0
  1279. */
  1280. public function getRootFolder() {
  1281. return $this->get(IRootFolder::class);
  1282. }
  1283. /**
  1284. * Returns the root folder of ownCloud's data directory
  1285. * This is the lazy variant so this gets only initialized once it
  1286. * is actually used.
  1287. *
  1288. * @return IRootFolder
  1289. * @deprecated 20.0.0
  1290. */
  1291. public function getLazyRootFolder() {
  1292. return $this->get(IRootFolder::class);
  1293. }
  1294. /**
  1295. * Returns a view to ownCloud's files folder
  1296. *
  1297. * @param string $userId user ID
  1298. * @return \OCP\Files\Folder|null
  1299. * @deprecated 20.0.0
  1300. */
  1301. public function getUserFolder($userId = null) {
  1302. if ($userId === null) {
  1303. $user = $this->get(IUserSession::class)->getUser();
  1304. if (!$user) {
  1305. return null;
  1306. }
  1307. $userId = $user->getUID();
  1308. }
  1309. $root = $this->get(IRootFolder::class);
  1310. return $root->getUserFolder($userId);
  1311. }
  1312. /**
  1313. * @return \OC\User\Manager
  1314. * @deprecated 20.0.0
  1315. */
  1316. public function getUserManager() {
  1317. return $this->get(IUserManager::class);
  1318. }
  1319. /**
  1320. * @return \OC\Group\Manager
  1321. * @deprecated 20.0.0
  1322. */
  1323. public function getGroupManager() {
  1324. return $this->get(IGroupManager::class);
  1325. }
  1326. /**
  1327. * @return \OC\User\Session
  1328. * @deprecated 20.0.0
  1329. */
  1330. public function getUserSession() {
  1331. return $this->get(IUserSession::class);
  1332. }
  1333. /**
  1334. * @return \OCP\ISession
  1335. * @deprecated 20.0.0
  1336. */
  1337. public function getSession() {
  1338. return $this->get(Session::class)->getSession();
  1339. }
  1340. /**
  1341. * @param \OCP\ISession $session
  1342. * @return void
  1343. */
  1344. public function setSession(\OCP\ISession $session) {
  1345. $this->get(SessionStorage::class)->setSession($session);
  1346. $this->get(Session::class)->setSession($session);
  1347. $this->get(Store::class)->setSession($session);
  1348. }
  1349. /**
  1350. * @return \OC\Authentication\TwoFactorAuth\Manager
  1351. * @deprecated 20.0.0
  1352. */
  1353. public function getTwoFactorAuthManager() {
  1354. return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
  1355. }
  1356. /**
  1357. * @return \OC\NavigationManager
  1358. * @deprecated 20.0.0
  1359. */
  1360. public function getNavigationManager() {
  1361. return $this->get(INavigationManager::class);
  1362. }
  1363. /**
  1364. * @return \OCP\IConfig
  1365. * @deprecated 20.0.0
  1366. */
  1367. public function getConfig() {
  1368. return $this->get(AllConfig::class);
  1369. }
  1370. /**
  1371. * @return \OC\SystemConfig
  1372. * @deprecated 20.0.0
  1373. */
  1374. public function getSystemConfig() {
  1375. return $this->get(SystemConfig::class);
  1376. }
  1377. /**
  1378. * Returns the app config manager
  1379. *
  1380. * @return IAppConfig
  1381. * @deprecated 20.0.0
  1382. */
  1383. public function getAppConfig() {
  1384. return $this->get(IAppConfig::class);
  1385. }
  1386. /**
  1387. * @return IFactory
  1388. * @deprecated 20.0.0
  1389. */
  1390. public function getL10NFactory() {
  1391. return $this->get(IFactory::class);
  1392. }
  1393. /**
  1394. * get an L10N instance
  1395. *
  1396. * @param string $app appid
  1397. * @param string $lang
  1398. * @return IL10N
  1399. * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort
  1400. */
  1401. public function getL10N($app, $lang = null) {
  1402. return $this->get(IFactory::class)->get($app, $lang);
  1403. }
  1404. /**
  1405. * @return IURLGenerator
  1406. * @deprecated 20.0.0
  1407. */
  1408. public function getURLGenerator() {
  1409. return $this->get(IURLGenerator::class);
  1410. }
  1411. /**
  1412. * @return AppFetcher
  1413. * @deprecated 20.0.0
  1414. */
  1415. public function getAppFetcher() {
  1416. return $this->get(AppFetcher::class);
  1417. }
  1418. /**
  1419. * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
  1420. * getMemCacheFactory() instead.
  1421. *
  1422. * @return ICache
  1423. * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
  1424. */
  1425. public function getCache() {
  1426. return $this->get(ICache::class);
  1427. }
  1428. /**
  1429. * Returns an \OCP\CacheFactory instance
  1430. *
  1431. * @return \OCP\ICacheFactory
  1432. * @deprecated 20.0.0
  1433. */
  1434. public function getMemCacheFactory() {
  1435. return $this->get(ICacheFactory::class);
  1436. }
  1437. /**
  1438. * Returns an \OC\RedisFactory instance
  1439. *
  1440. * @return \OC\RedisFactory
  1441. * @deprecated 20.0.0
  1442. */
  1443. public function getGetRedisFactory() {
  1444. return $this->get('RedisFactory');
  1445. }
  1446. /**
  1447. * Returns the current session
  1448. *
  1449. * @return \OCP\IDBConnection
  1450. * @deprecated 20.0.0
  1451. */
  1452. public function getDatabaseConnection() {
  1453. return $this->get(IDBConnection::class);
  1454. }
  1455. /**
  1456. * Returns the activity manager
  1457. *
  1458. * @return \OCP\Activity\IManager
  1459. * @deprecated 20.0.0
  1460. */
  1461. public function getActivityManager() {
  1462. return $this->get(\OCP\Activity\IManager::class);
  1463. }
  1464. /**
  1465. * Returns an job list for controlling background jobs
  1466. *
  1467. * @return IJobList
  1468. * @deprecated 20.0.0
  1469. */
  1470. public function getJobList() {
  1471. return $this->get(IJobList::class);
  1472. }
  1473. /**
  1474. * @return ILogFactory
  1475. * @throws \OCP\AppFramework\QueryException
  1476. * @deprecated 20.0.0
  1477. */
  1478. public function getLogFactory() {
  1479. return $this->get(ILogFactory::class);
  1480. }
  1481. /**
  1482. * Returns a router for generating and matching urls
  1483. *
  1484. * @return IRouter
  1485. * @deprecated 20.0.0
  1486. */
  1487. public function getRouter() {
  1488. return $this->get(IRouter::class);
  1489. }
  1490. /**
  1491. * Returns a SecureRandom instance
  1492. *
  1493. * @return \OCP\Security\ISecureRandom
  1494. * @deprecated 20.0.0
  1495. */
  1496. public function getSecureRandom() {
  1497. return $this->get(ISecureRandom::class);
  1498. }
  1499. /**
  1500. * Returns a Crypto instance
  1501. *
  1502. * @return ICrypto
  1503. * @deprecated 20.0.0
  1504. */
  1505. public function getCrypto() {
  1506. return $this->get(ICrypto::class);
  1507. }
  1508. /**
  1509. * Returns a Hasher instance
  1510. *
  1511. * @return IHasher
  1512. * @deprecated 20.0.0
  1513. */
  1514. public function getHasher() {
  1515. return $this->get(IHasher::class);
  1516. }
  1517. /**
  1518. * Returns a CredentialsManager instance
  1519. *
  1520. * @return ICredentialsManager
  1521. * @deprecated 20.0.0
  1522. */
  1523. public function getCredentialsManager() {
  1524. return $this->get(ICredentialsManager::class);
  1525. }
  1526. /**
  1527. * Get the certificate manager
  1528. *
  1529. * @return \OCP\ICertificateManager
  1530. */
  1531. public function getCertificateManager() {
  1532. return $this->get(ICertificateManager::class);
  1533. }
  1534. /**
  1535. * Returns an instance of the HTTP client service
  1536. *
  1537. * @return IClientService
  1538. * @deprecated 20.0.0
  1539. */
  1540. public function getHTTPClientService() {
  1541. return $this->get(IClientService::class);
  1542. }
  1543. /**
  1544. * Get the active event logger
  1545. *
  1546. * The returned logger only logs data when debug mode is enabled
  1547. *
  1548. * @return IEventLogger
  1549. * @deprecated 20.0.0
  1550. */
  1551. public function getEventLogger() {
  1552. return $this->get(IEventLogger::class);
  1553. }
  1554. /**
  1555. * Get the active query logger
  1556. *
  1557. * The returned logger only logs data when debug mode is enabled
  1558. *
  1559. * @return IQueryLogger
  1560. * @deprecated 20.0.0
  1561. */
  1562. public function getQueryLogger() {
  1563. return $this->get(IQueryLogger::class);
  1564. }
  1565. /**
  1566. * Get the manager for temporary files and folders
  1567. *
  1568. * @return \OCP\ITempManager
  1569. * @deprecated 20.0.0
  1570. */
  1571. public function getTempManager() {
  1572. return $this->get(ITempManager::class);
  1573. }
  1574. /**
  1575. * Get the app manager
  1576. *
  1577. * @return \OCP\App\IAppManager
  1578. * @deprecated 20.0.0
  1579. */
  1580. public function getAppManager() {
  1581. return $this->get(IAppManager::class);
  1582. }
  1583. /**
  1584. * Creates a new mailer
  1585. *
  1586. * @return IMailer
  1587. * @deprecated 20.0.0
  1588. */
  1589. public function getMailer() {
  1590. return $this->get(IMailer::class);
  1591. }
  1592. /**
  1593. * Get the webroot
  1594. *
  1595. * @return string
  1596. * @deprecated 20.0.0
  1597. */
  1598. public function getWebRoot() {
  1599. return $this->webRoot;
  1600. }
  1601. /**
  1602. * @return \OC\OCSClient
  1603. * @deprecated 20.0.0
  1604. */
  1605. public function getOcsClient() {
  1606. return $this->get('OcsClient');
  1607. }
  1608. /**
  1609. * @return IDateTimeZone
  1610. * @deprecated 20.0.0
  1611. */
  1612. public function getDateTimeZone() {
  1613. return $this->get(IDateTimeZone::class);
  1614. }
  1615. /**
  1616. * @return IDateTimeFormatter
  1617. * @deprecated 20.0.0
  1618. */
  1619. public function getDateTimeFormatter() {
  1620. return $this->get(IDateTimeFormatter::class);
  1621. }
  1622. /**
  1623. * @return IMountProviderCollection
  1624. * @deprecated 20.0.0
  1625. */
  1626. public function getMountProviderCollection() {
  1627. return $this->get(IMountProviderCollection::class);
  1628. }
  1629. /**
  1630. * Get the IniWrapper
  1631. *
  1632. * @return IniGetWrapper
  1633. * @deprecated 20.0.0
  1634. */
  1635. public function getIniWrapper() {
  1636. return $this->get(IniGetWrapper::class);
  1637. }
  1638. /**
  1639. * @return \OCP\Command\IBus
  1640. * @deprecated 20.0.0
  1641. */
  1642. public function getCommandBus() {
  1643. return $this->get(IBus::class);
  1644. }
  1645. /**
  1646. * Get the trusted domain helper
  1647. *
  1648. * @return TrustedDomainHelper
  1649. * @deprecated 20.0.0
  1650. */
  1651. public function getTrustedDomainHelper() {
  1652. return $this->get(TrustedDomainHelper::class);
  1653. }
  1654. /**
  1655. * Get the locking provider
  1656. *
  1657. * @return ILockingProvider
  1658. * @since 8.1.0
  1659. * @deprecated 20.0.0
  1660. */
  1661. public function getLockingProvider() {
  1662. return $this->get(ILockingProvider::class);
  1663. }
  1664. /**
  1665. * @return IMountManager
  1666. * @deprecated 20.0.0
  1667. **/
  1668. public function getMountManager() {
  1669. return $this->get(IMountManager::class);
  1670. }
  1671. /**
  1672. * @return IUserMountCache
  1673. * @deprecated 20.0.0
  1674. */
  1675. public function getUserMountCache() {
  1676. return $this->get(IUserMountCache::class);
  1677. }
  1678. /**
  1679. * Get the MimeTypeDetector
  1680. *
  1681. * @return IMimeTypeDetector
  1682. * @deprecated 20.0.0
  1683. */
  1684. public function getMimeTypeDetector() {
  1685. return $this->get(IMimeTypeDetector::class);
  1686. }
  1687. /**
  1688. * Get the MimeTypeLoader
  1689. *
  1690. * @return IMimeTypeLoader
  1691. * @deprecated 20.0.0
  1692. */
  1693. public function getMimeTypeLoader() {
  1694. return $this->get(IMimeTypeLoader::class);
  1695. }
  1696. /**
  1697. * Get the manager of all the capabilities
  1698. *
  1699. * @return CapabilitiesManager
  1700. * @deprecated 20.0.0
  1701. */
  1702. public function getCapabilitiesManager() {
  1703. return $this->get(CapabilitiesManager::class);
  1704. }
  1705. /**
  1706. * Get the Notification Manager
  1707. *
  1708. * @return \OCP\Notification\IManager
  1709. * @since 8.2.0
  1710. * @deprecated 20.0.0
  1711. */
  1712. public function getNotificationManager() {
  1713. return $this->get(\OCP\Notification\IManager::class);
  1714. }
  1715. /**
  1716. * @return ICommentsManager
  1717. * @deprecated 20.0.0
  1718. */
  1719. public function getCommentsManager() {
  1720. return $this->get(ICommentsManager::class);
  1721. }
  1722. /**
  1723. * @return \OCA\Theming\ThemingDefaults
  1724. * @deprecated 20.0.0
  1725. */
  1726. public function getThemingDefaults() {
  1727. return $this->get('ThemingDefaults');
  1728. }
  1729. /**
  1730. * @return \OC\IntegrityCheck\Checker
  1731. * @deprecated 20.0.0
  1732. */
  1733. public function getIntegrityCodeChecker() {
  1734. return $this->get('IntegrityCodeChecker');
  1735. }
  1736. /**
  1737. * @return \OC\Session\CryptoWrapper
  1738. * @deprecated 20.0.0
  1739. */
  1740. public function getSessionCryptoWrapper() {
  1741. return $this->get('CryptoWrapper');
  1742. }
  1743. /**
  1744. * @return CsrfTokenManager
  1745. * @deprecated 20.0.0
  1746. */
  1747. public function getCsrfTokenManager() {
  1748. return $this->get(CsrfTokenManager::class);
  1749. }
  1750. /**
  1751. * @return IThrottler
  1752. * @deprecated 20.0.0
  1753. */
  1754. public function getBruteForceThrottler() {
  1755. return $this->get(Throttler::class);
  1756. }
  1757. /**
  1758. * @return IContentSecurityPolicyManager
  1759. * @deprecated 20.0.0
  1760. */
  1761. public function getContentSecurityPolicyManager() {
  1762. return $this->get(ContentSecurityPolicyManager::class);
  1763. }
  1764. /**
  1765. * @return ContentSecurityPolicyNonceManager
  1766. * @deprecated 20.0.0
  1767. */
  1768. public function getContentSecurityPolicyNonceManager() {
  1769. return $this->get(ContentSecurityPolicyNonceManager::class);
  1770. }
  1771. /**
  1772. * Not a public API as of 8.2, wait for 9.0
  1773. *
  1774. * @return \OCA\Files_External\Service\BackendService
  1775. * @deprecated 20.0.0
  1776. */
  1777. public function getStoragesBackendService() {
  1778. return $this->get(BackendService::class);
  1779. }
  1780. /**
  1781. * Not a public API as of 8.2, wait for 9.0
  1782. *
  1783. * @return \OCA\Files_External\Service\GlobalStoragesService
  1784. * @deprecated 20.0.0
  1785. */
  1786. public function getGlobalStoragesService() {
  1787. return $this->get(GlobalStoragesService::class);
  1788. }
  1789. /**
  1790. * Not a public API as of 8.2, wait for 9.0
  1791. *
  1792. * @return \OCA\Files_External\Service\UserGlobalStoragesService
  1793. * @deprecated 20.0.0
  1794. */
  1795. public function getUserGlobalStoragesService() {
  1796. return $this->get(UserGlobalStoragesService::class);
  1797. }
  1798. /**
  1799. * Not a public API as of 8.2, wait for 9.0
  1800. *
  1801. * @return \OCA\Files_External\Service\UserStoragesService
  1802. * @deprecated 20.0.0
  1803. */
  1804. public function getUserStoragesService() {
  1805. return $this->get(UserStoragesService::class);
  1806. }
  1807. /**
  1808. * @return \OCP\Share\IManager
  1809. * @deprecated 20.0.0
  1810. */
  1811. public function getShareManager() {
  1812. return $this->get(\OCP\Share\IManager::class);
  1813. }
  1814. /**
  1815. * @return \OCP\Collaboration\Collaborators\ISearch
  1816. * @deprecated 20.0.0
  1817. */
  1818. public function getCollaboratorSearch() {
  1819. return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
  1820. }
  1821. /**
  1822. * @return \OCP\Collaboration\AutoComplete\IManager
  1823. * @deprecated 20.0.0
  1824. */
  1825. public function getAutoCompleteManager() {
  1826. return $this->get(IManager::class);
  1827. }
  1828. /**
  1829. * Returns the LDAP Provider
  1830. *
  1831. * @return \OCP\LDAP\ILDAPProvider
  1832. * @deprecated 20.0.0
  1833. */
  1834. public function getLDAPProvider() {
  1835. return $this->get('LDAPProvider');
  1836. }
  1837. /**
  1838. * @return \OCP\Settings\IManager
  1839. * @deprecated 20.0.0
  1840. */
  1841. public function getSettingsManager() {
  1842. return $this->get(\OC\Settings\Manager::class);
  1843. }
  1844. /**
  1845. * @return \OCP\Files\IAppData
  1846. * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead
  1847. */
  1848. public function getAppDataDir($app) {
  1849. /** @var \OC\Files\AppData\Factory $factory */
  1850. $factory = $this->get(\OC\Files\AppData\Factory::class);
  1851. return $factory->get($app);
  1852. }
  1853. /**
  1854. * @return \OCP\Lockdown\ILockdownManager
  1855. * @deprecated 20.0.0
  1856. */
  1857. public function getLockdownManager() {
  1858. return $this->get('LockdownManager');
  1859. }
  1860. /**
  1861. * @return \OCP\Federation\ICloudIdManager
  1862. * @deprecated 20.0.0
  1863. */
  1864. public function getCloudIdManager() {
  1865. return $this->get(ICloudIdManager::class);
  1866. }
  1867. /**
  1868. * @return \OCP\GlobalScale\IConfig
  1869. * @deprecated 20.0.0
  1870. */
  1871. public function getGlobalScaleConfig() {
  1872. return $this->get(IConfig::class);
  1873. }
  1874. /**
  1875. * @return \OCP\Federation\ICloudFederationProviderManager
  1876. * @deprecated 20.0.0
  1877. */
  1878. public function getCloudFederationProviderManager() {
  1879. return $this->get(ICloudFederationProviderManager::class);
  1880. }
  1881. /**
  1882. * @return \OCP\Remote\Api\IApiFactory
  1883. * @deprecated 20.0.0
  1884. */
  1885. public function getRemoteApiFactory() {
  1886. return $this->get(IApiFactory::class);
  1887. }
  1888. /**
  1889. * @return \OCP\Federation\ICloudFederationFactory
  1890. * @deprecated 20.0.0
  1891. */
  1892. public function getCloudFederationFactory() {
  1893. return $this->get(ICloudFederationFactory::class);
  1894. }
  1895. /**
  1896. * @return \OCP\Remote\IInstanceFactory
  1897. * @deprecated 20.0.0
  1898. */
  1899. public function getRemoteInstanceFactory() {
  1900. return $this->get(IInstanceFactory::class);
  1901. }
  1902. /**
  1903. * @return IStorageFactory
  1904. * @deprecated 20.0.0
  1905. */
  1906. public function getStorageFactory() {
  1907. return $this->get(IStorageFactory::class);
  1908. }
  1909. /**
  1910. * Get the Preview GeneratorHelper
  1911. *
  1912. * @return GeneratorHelper
  1913. * @since 17.0.0
  1914. * @deprecated 20.0.0
  1915. */
  1916. public function getGeneratorHelper() {
  1917. return $this->get(\OC\Preview\GeneratorHelper::class);
  1918. }
  1919. private function registerDeprecatedAlias(string $alias, string $target) {
  1920. $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
  1921. try {
  1922. /** @var LoggerInterface $logger */
  1923. $logger = $container->get(LoggerInterface::class);
  1924. $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
  1925. } catch (ContainerExceptionInterface $e) {
  1926. // Could not get logger. Continue
  1927. }
  1928. return $container->get($target);
  1929. }, false);
  1930. }
  1931. }