application.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @copyright Copyright (c) 2015, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_Sharing;
  25. use OC\AppFramework\Utility\SimpleContainer;
  26. use OCA\Files_Sharing\Controllers\ExternalSharesController;
  27. use OCA\Files_Sharing\Controllers\ShareController;
  28. use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
  29. use \OCP\AppFramework\App;
  30. /**
  31. * @package OCA\Files_Sharing
  32. */
  33. class Application extends App {
  34. /**
  35. * @param array $urlParams
  36. */
  37. public function __construct(array $urlParams=array()){
  38. parent::__construct('files_sharing', $urlParams);
  39. $container = $this->getContainer();
  40. $server = $container->getServer();
  41. /**
  42. * Controllers
  43. */
  44. $container->registerService('ShareController', function(SimpleContainer $c) use ($server) {
  45. return new ShareController(
  46. $c->query('AppName'),
  47. $c->query('Request'),
  48. $c->query('UserSession'),
  49. $server->getAppConfig(),
  50. $server->getConfig(),
  51. $c->query('URLGenerator'),
  52. $c->query('UserManager'),
  53. $server->getLogger(),
  54. $server->getActivityManager()
  55. );
  56. });
  57. $container->registerService('ExternalSharesController', function(SimpleContainer $c) {
  58. return new ExternalSharesController(
  59. $c->query('AppName'),
  60. $c->query('Request'),
  61. $c->query('IsIncomingShareEnabled'),
  62. $c->query('ExternalManager')
  63. );
  64. });
  65. /**
  66. * Core class wrappers
  67. */
  68. $container->registerService('UserSession', function(SimpleContainer $c) use ($server) {
  69. return $server->getUserSession();
  70. });
  71. $container->registerService('URLGenerator', function(SimpleContainer $c) use ($server){
  72. return $server->getUrlGenerator();
  73. });
  74. $container->registerService('UserManager', function(SimpleContainer $c) use ($server){
  75. return $server->getUserManager();
  76. });
  77. $container->registerService('IsIncomingShareEnabled', function(SimpleContainer $c) {
  78. return Helper::isIncomingServer2serverShareEnabled();
  79. });
  80. $container->registerService('ExternalManager', function(SimpleContainer $c) use ($server){
  81. $user = $server->getUserSession()->getUser();
  82. $uid = $user ? $user->getUID() : null;
  83. return new \OCA\Files_Sharing\External\Manager(
  84. $server->getDatabaseConnection(),
  85. \OC\Files\Filesystem::getMountManager(),
  86. \OC\Files\Filesystem::getLoader(),
  87. $server->getHTTPHelper(),
  88. $uid
  89. );
  90. });
  91. /**
  92. * Middleware
  93. */
  94. $container->registerService('SharingCheckMiddleware', function(SimpleContainer $c) use ($server){
  95. return new SharingCheckMiddleware(
  96. $c->query('AppName'),
  97. $server->getConfig(),
  98. $server->getAppManager()
  99. );
  100. });
  101. // Execute middlewares
  102. $container->registerMiddleware('SharingCheckMiddleware');
  103. }
  104. }