Server.php 74 KB

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