Server.php 58 KB

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