Server.php 75 KB

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