Server.php 74 KB

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