Server.php 73 KB

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