Server.php 73 KB

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