Server.php 66 KB

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