Server.php 75 KB

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