Server.php 75 KB

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