1
0

Server.php 73 KB

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