Server.php 76 KB

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