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

2297 lines
70 KiB

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