application.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Georg Ehrke <georg@owncloud.com>
  5. * @author Joas Schilling <nickvergessen@owncloud.com>
  6. * @author Lukas Reschke <lukas@owncloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @copyright Copyright (c) 2015, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OC\Settings;
  27. use OC\Files\View;
  28. use OC\Settings\Controller\AppSettingsController;
  29. use OC\Settings\Controller\CertificateController;
  30. use OC\Settings\Controller\CheckSetupController;
  31. use OC\Settings\Controller\EncryptionController;
  32. use OC\Settings\Controller\GroupsController;
  33. use OC\Settings\Controller\LogSettingsController;
  34. use OC\Settings\Controller\MailSettingsController;
  35. use OC\Settings\Controller\SecuritySettingsController;
  36. use OC\Settings\Controller\UsersController;
  37. use OC\Settings\Middleware\SubadminMiddleware;
  38. use \OCP\AppFramework\App;
  39. use OCP\IContainer;
  40. use \OCP\Util;
  41. use OC\Server;
  42. /**
  43. * @package OC\Settings
  44. */
  45. class Application extends App {
  46. /**
  47. * @param array $urlParams
  48. */
  49. public function __construct(array $urlParams=[]){
  50. parent::__construct('settings', $urlParams);
  51. $container = $this->getContainer();
  52. /**
  53. * Controllers
  54. */
  55. $container->registerService('MailSettingsController', function(IContainer $c) {
  56. return new MailSettingsController(
  57. $c->query('AppName'),
  58. $c->query('Request'),
  59. $c->query('L10N'),
  60. $c->query('Config'),
  61. $c->query('UserSession'),
  62. $c->query('Defaults'),
  63. $c->query('Mailer'),
  64. $c->query('DefaultMailAddress')
  65. );
  66. });
  67. $container->registerService('EncryptionController', function(IContainer $c) {
  68. return new EncryptionController(
  69. $c->query('AppName'),
  70. $c->query('Request'),
  71. $c->query('L10N'),
  72. $c->query('Config'),
  73. $c->query('DatabaseConnection'),
  74. $c->query('UserManager'),
  75. new View(),
  76. $c->query('Logger')
  77. );
  78. });
  79. $container->registerService('AppSettingsController', function(IContainer $c) {
  80. return new AppSettingsController(
  81. $c->query('AppName'),
  82. $c->query('Request'),
  83. $c->query('L10N'),
  84. $c->query('Config'),
  85. $c->query('ICacheFactory'),
  86. $c->query('INavigationManager'),
  87. $c->query('IAppManager'),
  88. $c->query('OcsClient')
  89. );
  90. });
  91. $container->registerService('SecuritySettingsController', function(IContainer $c) {
  92. return new SecuritySettingsController(
  93. $c->query('AppName'),
  94. $c->query('Request'),
  95. $c->query('Config')
  96. );
  97. });
  98. $container->registerService('CertificateController', function(IContainer $c) {
  99. return new CertificateController(
  100. $c->query('AppName'),
  101. $c->query('Request'),
  102. $c->query('CertificateManager'),
  103. $c->query('L10N'),
  104. $c->query('IAppManager')
  105. );
  106. });
  107. $container->registerService('GroupsController', function(IContainer $c) {
  108. return new GroupsController(
  109. $c->query('AppName'),
  110. $c->query('Request'),
  111. $c->query('GroupManager'),
  112. $c->query('UserSession'),
  113. $c->query('IsAdmin'),
  114. $c->query('L10N')
  115. );
  116. });
  117. $container->registerService('UsersController', function(IContainer $c) {
  118. return new UsersController(
  119. $c->query('AppName'),
  120. $c->query('Request'),
  121. $c->query('UserManager'),
  122. $c->query('GroupManager'),
  123. $c->query('UserSession'),
  124. $c->query('Config'),
  125. $c->query('IsAdmin'),
  126. $c->query('L10N'),
  127. $c->query('Logger'),
  128. $c->query('Defaults'),
  129. $c->query('Mailer'),
  130. $c->query('DefaultMailAddress'),
  131. $c->query('URLGenerator'),
  132. $c->query('OCP\\App\\IAppManager')
  133. );
  134. });
  135. $container->registerService('LogSettingsController', function(IContainer $c) {
  136. return new LogSettingsController(
  137. $c->query('AppName'),
  138. $c->query('Request'),
  139. $c->query('Config'),
  140. $c->query('L10N')
  141. );
  142. });
  143. $container->registerService('CheckSetupController', function(IContainer $c) {
  144. return new CheckSetupController(
  145. $c->query('AppName'),
  146. $c->query('Request'),
  147. $c->query('Config'),
  148. $c->query('ClientService'),
  149. $c->query('URLGenerator'),
  150. $c->query('Util'),
  151. $c->query('L10N'),
  152. $c->query('Checker')
  153. );
  154. });
  155. /**
  156. * Middleware
  157. */
  158. $container->registerService('SubadminMiddleware', function(IContainer $c){
  159. return new SubadminMiddleware(
  160. $c->query('ControllerMethodReflector'),
  161. $c->query('IsSubAdmin')
  162. );
  163. });
  164. // Execute middlewares
  165. $container->registerMiddleware('SubadminMiddleware');
  166. /**
  167. * Core class wrappers
  168. */
  169. $container->registerService('Config', function(IContainer $c) {
  170. return $c->query('ServerContainer')->getConfig();
  171. });
  172. $container->registerService('ICacheFactory', function(IContainer $c) {
  173. return $c->query('ServerContainer')->getMemCacheFactory();
  174. });
  175. $container->registerService('L10N', function(IContainer $c) {
  176. return $c->query('ServerContainer')->getL10N('settings');
  177. });
  178. $container->registerService('GroupManager', function(IContainer $c) {
  179. return $c->query('ServerContainer')->getGroupManager();
  180. });
  181. $container->registerService('UserManager', function(IContainer $c) {
  182. return $c->query('ServerContainer')->getUserManager();
  183. });
  184. $container->registerService('UserSession', function(IContainer $c) {
  185. return $c->query('ServerContainer')->getUserSession();
  186. });
  187. /** FIXME: Remove once OC_User is non-static and mockable */
  188. $container->registerService('IsAdmin', function(IContainer $c) {
  189. return \OC_User::isAdminUser(\OC_User::getUser());
  190. });
  191. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  192. $container->registerService('IsSubAdmin', function(IContainer $c) {
  193. $userObject = \OC::$server->getUserSession()->getUser();
  194. $isSubAdmin = false;
  195. if($userObject !== null) {
  196. $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
  197. }
  198. return $isSubAdmin;
  199. });
  200. $container->registerService('Mailer', function(IContainer $c) {
  201. return $c->query('ServerContainer')->getMailer();
  202. });
  203. $container->registerService('Defaults', function(IContainer $c) {
  204. return new \OC_Defaults;
  205. });
  206. $container->registerService('DefaultMailAddress', function(IContainer $c) {
  207. return Util::getDefaultEmailAddress('no-reply');
  208. });
  209. $container->registerService('Logger', function(IContainer $c) {
  210. return $c->query('ServerContainer')->getLogger();
  211. });
  212. $container->registerService('URLGenerator', function(IContainer $c) {
  213. return $c->query('ServerContainer')->getURLGenerator();
  214. });
  215. $container->registerService('ClientService', function(IContainer $c) {
  216. return $c->query('ServerContainer')->getHTTPClientService();
  217. });
  218. $container->registerService('INavigationManager', function(IContainer $c) {
  219. return $c->query('ServerContainer')->getNavigationManager();
  220. });
  221. $container->registerService('IAppManager', function(IContainer $c) {
  222. return $c->query('ServerContainer')->getAppManager();
  223. });
  224. $container->registerService('OcsClient', function(IContainer $c) {
  225. return $c->query('ServerContainer')->getOcsClient();
  226. });
  227. $container->registerService('Util', function(IContainer $c) {
  228. return new \OC_Util();
  229. });
  230. $container->registerService('DatabaseConnection', function(IContainer $c) {
  231. return $c->query('ServerContainer')->getDatabaseConnection();
  232. });
  233. $container->registerService('CertificateManager', function(IContainer $c){
  234. return $c->query('ServerContainer')->getCertificateManager();
  235. });
  236. $container->registerService('Checker', function(IContainer $c) {
  237. /** @var Server $server */
  238. $server = $c->query('ServerContainer');
  239. return $server->getIntegrityCodeChecker();
  240. });
  241. }
  242. }