Server.php 66 KB

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