Server.php 66 KB

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