Application.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\FederatedFileSharing\AppInfo;
  23. use OC\AppFramework\Utility\SimpleContainer;
  24. use OCA\FederatedFileSharing\AddressHandler;
  25. use OCA\FederatedFileSharing\Controller\RequestHandlerController;
  26. use OCA\FederatedFileSharing\FederatedShareProvider;
  27. use OCA\FederatedFileSharing\Notifications;
  28. use OCP\AppFramework\App;
  29. class Application extends App {
  30. /** @var FederatedShareProvider */
  31. protected $federatedShareProvider;
  32. public function __construct() {
  33. parent::__construct('federatedfilesharing');
  34. $container = $this->getContainer();
  35. $server = $container->getServer();
  36. $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) {
  37. $addressHandler = new AddressHandler(
  38. $server->getURLGenerator(),
  39. $server->getL10N('federatedfilesharing')
  40. );
  41. $notification = new Notifications(
  42. $addressHandler,
  43. $server->getHTTPClientService(),
  44. new \OCA\FederatedFileSharing\DiscoveryManager(
  45. $server->getMemCacheFactory(),
  46. $server->getHTTPClientService()
  47. ),
  48. \OC::$server->getJobList()
  49. );
  50. return new RequestHandlerController(
  51. $c->query('AppName'),
  52. $server->getRequest(),
  53. $this->getFederatedShareProvider(),
  54. $server->getDatabaseConnection(),
  55. $server->getShareManager(),
  56. $notification,
  57. $addressHandler,
  58. $server->getUserManager()
  59. );
  60. });
  61. }
  62. /**
  63. * register personal and admin settings page
  64. */
  65. public function registerSettings() {
  66. \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal');
  67. }
  68. /**
  69. * get instance of federated share provider
  70. *
  71. * @return FederatedShareProvider
  72. */
  73. public function getFederatedShareProvider() {
  74. if ($this->federatedShareProvider === null) {
  75. $this->initFederatedShareProvider();
  76. }
  77. return $this->federatedShareProvider;
  78. }
  79. /**
  80. * initialize federated share provider
  81. */
  82. protected function initFederatedShareProvider() {
  83. $addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
  84. \OC::$server->getURLGenerator(),
  85. \OC::$server->getL10N('federatedfilesharing')
  86. );
  87. $discoveryManager = new \OCA\FederatedFileSharing\DiscoveryManager(
  88. \OC::$server->getMemCacheFactory(),
  89. \OC::$server->getHTTPClientService()
  90. );
  91. $notifications = new \OCA\FederatedFileSharing\Notifications(
  92. $addressHandler,
  93. \OC::$server->getHTTPClientService(),
  94. $discoveryManager,
  95. \OC::$server->getJobList()
  96. );
  97. $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler(
  98. \OC::$server->getSecureRandom()
  99. );
  100. $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider(
  101. \OC::$server->getDatabaseConnection(),
  102. $addressHandler,
  103. $notifications,
  104. $tokenHandler,
  105. \OC::$server->getL10N('federatedfilesharing'),
  106. \OC::$server->getLogger(),
  107. \OC::$server->getLazyRootFolder(),
  108. \OC::$server->getConfig(),
  109. \OC::$server->getUserManager()
  110. );
  111. }
  112. }