Server.php 73 KB

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