Server.php 72 KB

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