Application.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCA\Files_Sharing\AppInfo;
  30. use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware;
  31. use OCA\Files_Sharing\Middleware\ShareInfoMiddleware;
  32. use OCA\Files_Sharing\MountProvider;
  33. use OCP\AppFramework\App;
  34. use OC\AppFramework\Utility\SimpleContainer;
  35. use OCA\Files_Sharing\Controller\ExternalSharesController;
  36. use OCA\Files_Sharing\Controller\ShareController;
  37. use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
  38. use OCP\Defaults;
  39. use OCP\Federation\ICloudIdManager;
  40. use \OCP\IContainer;
  41. use OCP\IServerContainer;
  42. class Application extends App {
  43. public function __construct(array $urlParams = array()) {
  44. parent::__construct('files_sharing', $urlParams);
  45. $container = $this->getContainer();
  46. /** @var IServerContainer $server */
  47. $server = $container->getServer();
  48. /**
  49. * Controllers
  50. */
  51. $container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
  52. $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
  53. return new ShareController(
  54. $c->query('AppName'),
  55. $c->query('Request'),
  56. $server->getConfig(),
  57. $server->getURLGenerator(),
  58. $server->getUserManager(),
  59. $server->getLogger(),
  60. $server->getActivityManager(),
  61. $server->getShareManager(),
  62. $server->getSession(),
  63. $server->getPreviewManager(),
  64. $server->getRootFolder(),
  65. $federatedSharingApp->getFederatedShareProvider(),
  66. $server->getEventDispatcher(),
  67. $server->getL10N($c->query('AppName')),
  68. $server->query(Defaults::class)
  69. );
  70. });
  71. $container->registerService('ExternalSharesController', function (SimpleContainer $c) {
  72. return new ExternalSharesController(
  73. $c->query('AppName'),
  74. $c->query('Request'),
  75. $c->query('ExternalManager'),
  76. $c->query('HttpClientService')
  77. );
  78. });
  79. /**
  80. * Core class wrappers
  81. */
  82. $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
  83. return $server->getHTTPClientService();
  84. });
  85. $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
  86. return $server->getCloudIdManager();
  87. });
  88. $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
  89. $user = $server->getUserSession()->getUser();
  90. $uid = $user ? $user->getUID() : null;
  91. return new \OCA\Files_Sharing\External\Manager(
  92. $server->getDatabaseConnection(),
  93. \OC\Files\Filesystem::getMountManager(),
  94. \OC\Files\Filesystem::getLoader(),
  95. $server->getHTTPClientService(),
  96. $server->getNotificationManager(),
  97. $server->query(\OCP\OCS\IDiscoveryService::class),
  98. $uid
  99. );
  100. });
  101. $container->registerAlias('OCA\Files_Sharing\External\Manager', 'ExternalManager');
  102. /**
  103. * Middleware
  104. */
  105. $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
  106. return new SharingCheckMiddleware(
  107. $c->query('AppName'),
  108. $server->getConfig(),
  109. $server->getAppManager(),
  110. $c['ControllerMethodReflector'],
  111. $server->getShareManager(),
  112. $server->getRequest()
  113. );
  114. });
  115. $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
  116. return new OCSShareAPIMiddleware(
  117. $server->getShareManager(),
  118. $server->getL10N($c->query('AppName'))
  119. );
  120. });
  121. $container->registerService(ShareInfoMiddleware::class, function () use ($server) {
  122. return new ShareInfoMiddleware(
  123. $server->getShareManager()
  124. );
  125. });
  126. // Execute middlewares
  127. $container->registerMiddleWare('SharingCheckMiddleware');
  128. $container->registerMiddleWare('OCSShareAPIMiddleware');
  129. $container->registerMiddleWare(ShareInfoMiddleware::class);
  130. $container->registerService('MountProvider', function (IContainer $c) {
  131. /** @var \OCP\IServerContainer $server */
  132. $server = $c->query('ServerContainer');
  133. return new MountProvider(
  134. $server->getConfig(),
  135. $server->getShareManager(),
  136. $server->getLogger()
  137. );
  138. });
  139. $container->registerService('ExternalMountProvider', function (IContainer $c) {
  140. /** @var \OCP\IServerContainer $server */
  141. $server = $c->query('ServerContainer');
  142. return new \OCA\Files_Sharing\External\MountProvider(
  143. $server->getDatabaseConnection(),
  144. function() use ($c) {
  145. return $c->query('ExternalManager');
  146. },
  147. $server->getCloudIdManager()
  148. );
  149. });
  150. /*
  151. * Register capabilities
  152. */
  153. $container->registerCapability('OCA\Files_Sharing\Capabilities');
  154. }
  155. public function registerMountProviders() {
  156. /** @var \OCP\IServerContainer $server */
  157. $server = $this->getContainer()->query('ServerContainer');
  158. $mountProviderCollection = $server->getMountProviderCollection();
  159. $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
  160. $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
  161. }
  162. }