You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Server.php 73KB

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