application.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * @author Lukas Reschke
  4. * @copyright 2014-2015 Lukas Reschke lukas@owncloud.com
  5. *
  6. * This file is licensed under the Affero General Public License version 3 or
  7. * later.
  8. * See the COPYING-README file.
  9. */
  10. namespace OC\Settings;
  11. use OC\Settings\Controller\AppSettingsController;
  12. use OC\Settings\Controller\GroupsController;
  13. use OC\Settings\Controller\LogSettingsController;
  14. use OC\Settings\Controller\MailSettingsController;
  15. use OC\Settings\Controller\SecuritySettingsController;
  16. use OC\Settings\Controller\UsersController;
  17. use OC\Settings\Factory\SubAdminFactory;
  18. use OC\Settings\Middleware\SubadminMiddleware;
  19. use \OCP\AppFramework\App;
  20. use OCP\IContainer;
  21. use \OCP\Util;
  22. /**
  23. * @package OC\Settings
  24. */
  25. class Application extends App {
  26. /**
  27. * @param array $urlParams
  28. */
  29. public function __construct(array $urlParams=array()){
  30. parent::__construct('settings', $urlParams);
  31. $container = $this->getContainer();
  32. /**
  33. * Controllers
  34. */
  35. $container->registerService('MailSettingsController', function(IContainer $c) {
  36. return new MailSettingsController(
  37. $c->query('AppName'),
  38. $c->query('Request'),
  39. $c->query('L10N'),
  40. $c->query('Config'),
  41. $c->query('UserSession'),
  42. $c->query('Defaults'),
  43. $c->query('Mail'),
  44. $c->query('DefaultMailAddress')
  45. );
  46. });
  47. $container->registerService('AppSettingsController', function(IContainer $c) {
  48. return new AppSettingsController(
  49. $c->query('AppName'),
  50. $c->query('Request'),
  51. $c->query('L10N'),
  52. $c->query('Config'),
  53. $c->query('ICacheFactory')
  54. );
  55. });
  56. $container->registerService('SecuritySettingsController', function(IContainer $c) {
  57. return new SecuritySettingsController(
  58. $c->query('AppName'),
  59. $c->query('Request'),
  60. $c->query('Config')
  61. );
  62. });
  63. $container->registerService('GroupsController', function(IContainer $c) {
  64. return new GroupsController(
  65. $c->query('AppName'),
  66. $c->query('Request'),
  67. $c->query('GroupManager'),
  68. $c->query('UserSession'),
  69. $c->query('IsAdmin'),
  70. $c->query('L10N')
  71. );
  72. });
  73. $container->registerService('UsersController', function(IContainer $c) {
  74. return new UsersController(
  75. $c->query('AppName'),
  76. $c->query('Request'),
  77. $c->query('UserManager'),
  78. $c->query('GroupManager'),
  79. $c->query('UserSession'),
  80. $c->query('Config'),
  81. $c->query('IsAdmin'),
  82. $c->query('L10N'),
  83. $c->query('Logger'),
  84. $c->query('Defaults'),
  85. $c->query('Mail'),
  86. $c->query('DefaultMailAddress'),
  87. $c->query('URLGenerator'),
  88. $c->query('OCP\\App\\IAppManager'),
  89. $c->query('SubAdminFactory')
  90. );
  91. });
  92. $container->registerService('LogSettingsController', function(IContainer $c) {
  93. return new LogSettingsController(
  94. $c->query('AppName'),
  95. $c->query('Request'),
  96. $c->query('Config'),
  97. $c->query('L10N'),
  98. $c->query('TimeFactory')
  99. );
  100. });
  101. /**
  102. * Middleware
  103. */
  104. $container->registerService('SubadminMiddleware', function(IContainer $c){
  105. return new SubadminMiddleware(
  106. $c->query('ControllerMethodReflector'),
  107. $c->query('IsSubAdmin')
  108. );
  109. });
  110. // Execute middlewares
  111. $container->registerMiddleware('SubadminMiddleware');
  112. /**
  113. * Core class wrappers
  114. */
  115. $container->registerService('Config', function(IContainer $c) {
  116. return $c->query('ServerContainer')->getConfig();
  117. });
  118. $container->registerService('ICacheFactory', function(IContainer $c) {
  119. return $c->query('ServerContainer')->getMemCacheFactory();
  120. });
  121. $container->registerService('L10N', function(IContainer $c) {
  122. return $c->query('ServerContainer')->getL10N('settings');
  123. });
  124. $container->registerService('GroupManager', function(IContainer $c) {
  125. return $c->query('ServerContainer')->getGroupManager();
  126. });
  127. $container->registerService('UserManager', function(IContainer $c) {
  128. return $c->query('ServerContainer')->getUserManager();
  129. });
  130. $container->registerService('UserSession', function(IContainer $c) {
  131. return $c->query('ServerContainer')->getUserSession();
  132. });
  133. /** FIXME: Remove once OC_User is non-static and mockable */
  134. $container->registerService('IsAdmin', function(IContainer $c) {
  135. return \OC_User::isAdminUser(\OC_User::getUser());
  136. });
  137. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  138. $container->registerService('IsSubAdmin', function(IContainer $c) {
  139. return \OC_Subadmin::isSubAdmin(\OC_User::getUser());
  140. });
  141. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  142. $container->registerService('SubAdminFactory', function(IContainer $c) {
  143. return new SubAdminFactory();
  144. });
  145. $container->registerService('Mail', function(IContainer $c) {
  146. return new \OC_Mail;
  147. });
  148. $container->registerService('Defaults', function(IContainer $c) {
  149. return new \OC_Defaults;
  150. });
  151. $container->registerService('DefaultMailAddress', function(IContainer $c) {
  152. return Util::getDefaultEmailAddress('no-reply');
  153. });
  154. $container->registerService('Logger', function(IContainer $c) {
  155. return $c->query('ServerContainer')->getLogger();
  156. });
  157. $container->registerService('URLGenerator', function(IContainer $c) {
  158. return $c->query('ServerContainer')->getURLGenerator();
  159. });
  160. }
  161. }