You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Server.php 74KB

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