application.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * @author Georg Ehrke <georg@owncloud.com>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Settings;
  24. use OC\Settings\Controller\AppSettingsController;
  25. use OC\Settings\Controller\CheckSetupController;
  26. use OC\Settings\Controller\GroupsController;
  27. use OC\Settings\Controller\LogSettingsController;
  28. use OC\Settings\Controller\MailSettingsController;
  29. use OC\Settings\Controller\SecuritySettingsController;
  30. use OC\Settings\Controller\UsersController;
  31. use OC\Settings\Factory\SubAdminFactory;
  32. use OC\Settings\Middleware\SubadminMiddleware;
  33. use \OCP\AppFramework\App;
  34. use OCP\IContainer;
  35. use \OCP\Util;
  36. /**
  37. * @package OC\Settings
  38. */
  39. class Application extends App {
  40. /**
  41. * @param array $urlParams
  42. */
  43. public function __construct(array $urlParams=[]){
  44. parent::__construct('settings', $urlParams);
  45. $container = $this->getContainer();
  46. /**
  47. * Controllers
  48. */
  49. $container->registerService('MailSettingsController', function(IContainer $c) {
  50. return new MailSettingsController(
  51. $c->query('AppName'),
  52. $c->query('Request'),
  53. $c->query('L10N'),
  54. $c->query('Config'),
  55. $c->query('UserSession'),
  56. $c->query('Defaults'),
  57. $c->query('Mailer'),
  58. $c->query('DefaultMailAddress')
  59. );
  60. });
  61. $container->registerService('AppSettingsController', function(IContainer $c) {
  62. return new AppSettingsController(
  63. $c->query('AppName'),
  64. $c->query('Request'),
  65. $c->query('L10N'),
  66. $c->query('Config'),
  67. $c->query('ICacheFactory')
  68. );
  69. });
  70. $container->registerService('SecuritySettingsController', function(IContainer $c) {
  71. return new SecuritySettingsController(
  72. $c->query('AppName'),
  73. $c->query('Request'),
  74. $c->query('Config')
  75. );
  76. });
  77. $container->registerService('GroupsController', function(IContainer $c) {
  78. return new GroupsController(
  79. $c->query('AppName'),
  80. $c->query('Request'),
  81. $c->query('GroupManager'),
  82. $c->query('UserSession'),
  83. $c->query('IsAdmin'),
  84. $c->query('L10N')
  85. );
  86. });
  87. $container->registerService('UsersController', function(IContainer $c) {
  88. return new UsersController(
  89. $c->query('AppName'),
  90. $c->query('Request'),
  91. $c->query('UserManager'),
  92. $c->query('GroupManager'),
  93. $c->query('UserSession'),
  94. $c->query('Config'),
  95. $c->query('IsAdmin'),
  96. $c->query('L10N'),
  97. $c->query('Logger'),
  98. $c->query('Defaults'),
  99. $c->query('Mailer'),
  100. $c->query('DefaultMailAddress'),
  101. $c->query('URLGenerator'),
  102. $c->query('OCP\\App\\IAppManager'),
  103. $c->query('SubAdminFactory')
  104. );
  105. });
  106. $container->registerService('LogSettingsController', function(IContainer $c) {
  107. return new LogSettingsController(
  108. $c->query('AppName'),
  109. $c->query('Request'),
  110. $c->query('Config'),
  111. $c->query('L10N')
  112. );
  113. });
  114. $container->registerService('CheckSetupController', function(IContainer $c) {
  115. return new CheckSetupController(
  116. $c->query('AppName'),
  117. $c->query('Request'),
  118. $c->query('Config'),
  119. $c->query('ClientService'),
  120. $c->query('URLGenerator'),
  121. $c->query('Util')
  122. );
  123. });
  124. /**
  125. * Middleware
  126. */
  127. $container->registerService('SubadminMiddleware', function(IContainer $c){
  128. return new SubadminMiddleware(
  129. $c->query('ControllerMethodReflector'),
  130. $c->query('IsSubAdmin')
  131. );
  132. });
  133. // Execute middlewares
  134. $container->registerMiddleware('SubadminMiddleware');
  135. /**
  136. * Core class wrappers
  137. */
  138. $container->registerService('Config', function(IContainer $c) {
  139. return $c->query('ServerContainer')->getConfig();
  140. });
  141. $container->registerService('ICacheFactory', function(IContainer $c) {
  142. return $c->query('ServerContainer')->getMemCacheFactory();
  143. });
  144. $container->registerService('L10N', function(IContainer $c) {
  145. return $c->query('ServerContainer')->getL10N('settings');
  146. });
  147. $container->registerService('GroupManager', function(IContainer $c) {
  148. return $c->query('ServerContainer')->getGroupManager();
  149. });
  150. $container->registerService('UserManager', function(IContainer $c) {
  151. return $c->query('ServerContainer')->getUserManager();
  152. });
  153. $container->registerService('UserSession', function(IContainer $c) {
  154. return $c->query('ServerContainer')->getUserSession();
  155. });
  156. /** FIXME: Remove once OC_User is non-static and mockable */
  157. $container->registerService('IsAdmin', function(IContainer $c) {
  158. return \OC_User::isAdminUser(\OC_User::getUser());
  159. });
  160. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  161. $container->registerService('IsSubAdmin', function(IContainer $c) {
  162. return \OC_Subadmin::isSubAdmin(\OC_User::getUser());
  163. });
  164. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  165. $container->registerService('SubAdminFactory', function(IContainer $c) {
  166. return new SubAdminFactory();
  167. });
  168. $container->registerService('Mailer', function(IContainer $c) {
  169. return $c->query('ServerContainer')->getMailer();
  170. });
  171. $container->registerService('Defaults', function(IContainer $c) {
  172. return new \OC_Defaults;
  173. });
  174. $container->registerService('DefaultMailAddress', function(IContainer $c) {
  175. return Util::getDefaultEmailAddress('no-reply');
  176. });
  177. $container->registerService('Logger', function(IContainer $c) {
  178. return $c->query('ServerContainer')->getLogger();
  179. });
  180. $container->registerService('URLGenerator', function(IContainer $c) {
  181. return $c->query('ServerContainer')->getURLGenerator();
  182. });
  183. $container->registerService('ClientService', function(IContainer $c) {
  184. return $c->query('ServerContainer')->getHTTPClientService();
  185. });
  186. $container->registerService('Util', function(IContainer $c) {
  187. return new \OC_Util();
  188. });
  189. }
  190. }