Application.php 6.6 KB

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