Application.php 9.7 KB

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