Application.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  6. * @author Christoph Wurst <christoph@owncloud.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OC\Core;
  30. use OC\AppFramework\Utility\SimpleContainer;
  31. use OC\AppFramework\Utility\TimeFactory;
  32. use OC\Core\Controller\AvatarController;
  33. use OC\Core\Controller\LoginController;
  34. use OC\Core\Controller\LostController;
  35. use OC\Core\Controller\TokenController;
  36. use OC\Core\Controller\TwoFactorChallengeController;
  37. use OC\Core\Controller\UserController;
  38. use OCP\Defaults;
  39. use OCP\AppFramework\App;
  40. use OCP\Util;
  41. /**
  42. * Class Application
  43. *
  44. * @package OC\Core
  45. */
  46. class Application extends App {
  47. /**
  48. * @param array $urlParams
  49. */
  50. public function __construct(array $urlParams=array()){
  51. parent::__construct('core', $urlParams);
  52. $container = $this->getContainer();
  53. /**
  54. * Controllers
  55. */
  56. $container->registerService('LostController', function(SimpleContainer $c) {
  57. return new LostController(
  58. $c->query('AppName'),
  59. $c->query('Request'),
  60. $c->query('URLGenerator'),
  61. $c->query('UserManager'),
  62. $c->query('Defaults'),
  63. $c->query('L10N'),
  64. $c->query('Config'),
  65. $c->query('SecureRandom'),
  66. $c->query('DefaultEmailAddress'),
  67. $c->query('IsEncryptionEnabled'),
  68. $c->query('Mailer'),
  69. $c->query('TimeFactory')
  70. );
  71. });
  72. $container->registerService('UserController', function(SimpleContainer $c) {
  73. return new UserController(
  74. $c->query('AppName'),
  75. $c->query('Request'),
  76. $c->query('UserManager'),
  77. $c->query('Defaults')
  78. );
  79. });
  80. $container->registerService('AvatarController', function(SimpleContainer $c) {
  81. return new AvatarController(
  82. $c->query('AppName'),
  83. $c->query('Request'),
  84. $c->query('AvatarManager'),
  85. $c->query('Cache'),
  86. $c->query('L10N'),
  87. $c->query('UserManager'),
  88. $c->query('UserSession'),
  89. $c->query('UserFolder'),
  90. $c->query('Logger')
  91. );
  92. });
  93. $container->registerService('LoginController', function(SimpleContainer $c) {
  94. return new LoginController(
  95. $c->query('AppName'),
  96. $c->query('Request'),
  97. $c->query('UserManager'),
  98. $c->query('Config'),
  99. $c->query('Session'),
  100. $c->query('UserSession'),
  101. $c->query('URLGenerator'),
  102. $c->query('TwoFactorAuthManager'),
  103. $c->query('ServerContainer')->getBruteforceThrottler()
  104. );
  105. });
  106. $container->registerService('TwoFactorChallengeController', function (SimpleContainer $c) {
  107. return new TwoFactorChallengeController(
  108. $c->query('AppName'),
  109. $c->query('Request'),
  110. $c->query('TwoFactorAuthManager'),
  111. $c->query('UserSession'),
  112. $c->query('Session'),
  113. $c->query('URLGenerator'));
  114. });
  115. $container->registerService('TokenController', function(SimpleContainer $c) {
  116. return new TokenController(
  117. $c->query('AppName'),
  118. $c->query('Request'),
  119. $c->query('UserManager'),
  120. $c->query('ServerContainer')->query('OC\Authentication\Token\IProvider'),
  121. $c->query('TwoFactorAuthManager'),
  122. $c->query('SecureRandom')
  123. );
  124. });
  125. /**
  126. * Core class wrappers
  127. */
  128. $container->registerService('IsEncryptionEnabled', function(SimpleContainer $c) {
  129. return $c->query('ServerContainer')->getEncryptionManager()->isEnabled();
  130. });
  131. $container->registerService('URLGenerator', function(SimpleContainer $c) {
  132. return $c->query('ServerContainer')->getURLGenerator();
  133. });
  134. $container->registerService('UserManager', function(SimpleContainer $c) {
  135. return $c->query('ServerContainer')->getUserManager();
  136. });
  137. $container->registerService('Config', function(SimpleContainer $c) {
  138. return $c->query('ServerContainer')->getConfig();
  139. });
  140. $container->registerService('L10N', function(SimpleContainer $c) {
  141. return $c->query('ServerContainer')->getL10N('core');
  142. });
  143. $container->registerService('SecureRandom', function(SimpleContainer $c) {
  144. return $c->query('ServerContainer')->getSecureRandom();
  145. });
  146. $container->registerService('AvatarManager', function(SimpleContainer $c) {
  147. return $c->query('ServerContainer')->getAvatarManager();
  148. });
  149. $container->registerService('Session', function(SimpleContainer $c) {
  150. return $c->query('ServerContainer')->getSession();
  151. });
  152. $container->registerService('UserSession', function(SimpleContainer $c) {
  153. return $c->query('ServerContainer')->getUserSession();
  154. });
  155. $container->registerService('Session', function(SimpleContainer $c) {
  156. return $c->query('ServerContainer')->getSession();
  157. });
  158. $container->registerService('Cache', function(SimpleContainer $c) {
  159. return $c->query('ServerContainer')->getCache();
  160. });
  161. $container->registerService('UserFolder', function(SimpleContainer $c) {
  162. return $c->query('ServerContainer')->getUserFolder();
  163. });
  164. $container->registerService('Defaults', function(SimpleContainer $c) {
  165. return $c->query('ServerContainer')->getThemingDefaults();
  166. });
  167. $container->registerService('Mailer', function(SimpleContainer $c) {
  168. return $c->query('ServerContainer')->getMailer();
  169. });
  170. $container->registerService('Logger', function(SimpleContainer $c) {
  171. return $c->query('ServerContainer')->getLogger();
  172. });
  173. $container->registerService('TimeFactory', function(SimpleContainer $c) {
  174. return new TimeFactory();
  175. });
  176. $container->registerService('DefaultEmailAddress', function() {
  177. return Util::getDefaultEmailAddress('lostpassword-noreply');
  178. });
  179. $container->registerService('TwoFactorAuthManager', function(SimpleContainer $c) {
  180. return $c->query('ServerContainer')->getTwoFactorAuthManager();
  181. });
  182. }
  183. }