1
0

server.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  5. * @author Bernhard Reiter <ockham@raz.or.at>
  6. * @author Björn Schießle <schiessle@owncloud.com>
  7. * @author Christopher Schäpers <kondou@ts.unde.re>
  8. * @author Joas Schilling <nickvergessen@owncloud.com>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Lukas Reschke <lukas@owncloud.com>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <icewind@owncloud.com>
  13. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  14. * @author Sander <brantje@gmail.com>
  15. * @author Thomas Müller <thomas.mueller@tmit.eu>
  16. * @author Thomas Tanghus <thomas@tanghus.net>
  17. * @author Vincent Petry <pvince81@owncloud.com>
  18. *
  19. * @copyright Copyright (c) 2015, ownCloud, Inc.
  20. * @license AGPL-3.0
  21. *
  22. * This code is free software: you can redistribute it and/or modify
  23. * it under the terms of the GNU Affero General Public License, version 3,
  24. * as published by the Free Software Foundation.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU Affero General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Affero General Public License, version 3,
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>
  33. *
  34. */
  35. namespace OC;
  36. use bantu\IniGetWrapper\IniGetWrapper;
  37. use OC\AppFramework\Http\Request;
  38. use OC\AppFramework\Db\Db;
  39. use OC\AppFramework\Utility\SimpleContainer;
  40. use OC\Cache\UserCache;
  41. use OC\Command\AsyncBus;
  42. use OC\Diagnostics\NullQueryLogger;
  43. use OC\Diagnostics\EventLogger;
  44. use OC\Diagnostics\QueryLogger;
  45. use OC\Mail\Mailer;
  46. use OC\Memcache\ArrayCache;
  47. use OC\Http\Client\ClientService;
  48. use OC\Security\CertificateManager;
  49. use OC\Files\Node\Root;
  50. use OC\Files\View;
  51. use OC\Security\Crypto;
  52. use OC\Security\Hasher;
  53. use OC\Security\SecureRandom;
  54. use OC\Diagnostics\NullEventLogger;
  55. use OC\Security\TrustedDomainHelper;
  56. use OCP\IServerContainer;
  57. use OCP\ISession;
  58. use OC\Tagging\TagMapper;
  59. /**
  60. * Class Server
  61. *
  62. * @package OC
  63. *
  64. * TODO: hookup all manager classes
  65. */
  66. class Server extends SimpleContainer implements IServerContainer {
  67. /** @var string */
  68. private $webRoot;
  69. /**
  70. * @param string $webRoot
  71. */
  72. function __construct($webRoot) {
  73. $this->webRoot = $webRoot;
  74. $this->registerService('ContactsManager', function ($c) {
  75. return new ContactsManager();
  76. });
  77. $this->registerService('PreviewManager', function (Server $c) {
  78. return new PreviewManager($c->getConfig());
  79. });
  80. $this->registerService('EncryptionManager', function (Server $c) {
  81. return new Encryption\Manager($c->getConfig());
  82. });
  83. $this->registerService('EncryptionFileHelper', function (Server $c) {
  84. $util = new \OC\Encryption\Util(new \OC\Files\View(), $c->getUserManager(), $c->getConfig());
  85. return new Encryption\File($util);
  86. });
  87. $this->registerService('EncryptionKeyStorageFactory', function ($c) {
  88. return new Encryption\Keys\Factory();
  89. });
  90. $this->registerService('TagMapper', function(Server $c) {
  91. return new TagMapper($c->getDatabaseConnection());
  92. });
  93. $this->registerService('TagManager', function (Server $c) {
  94. $tagMapper = $c->query('TagMapper');
  95. return new TagManager($tagMapper, $c->getUserSession());
  96. });
  97. $this->registerService('RootFolder', function (Server $c) {
  98. // TODO: get user and user manager from container as well
  99. $user = \OC_User::getUser();
  100. /** @var $c SimpleContainer */
  101. $userManager = $c->query('UserManager');
  102. $user = $userManager->get($user);
  103. $manager = \OC\Files\Filesystem::getMountManager();
  104. $view = new View();
  105. return new Root($manager, $view, $user);
  106. });
  107. $this->registerService('UserManager', function (Server $c) {
  108. $config = $c->getConfig();
  109. return new \OC\User\Manager($config);
  110. });
  111. $this->registerService('GroupManager', function (Server $c) {
  112. $groupManager = new \OC\Group\Manager($this->getUserManager());
  113. $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
  114. \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
  115. });
  116. $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
  117. \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
  118. });
  119. $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
  120. \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
  121. });
  122. $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
  123. \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
  124. });
  125. $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  126. \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
  127. });
  128. $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  129. \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
  130. });
  131. return $groupManager;
  132. });
  133. $this->registerService('UserSession', function (Server $c) {
  134. $manager = $c->getUserManager();
  135. $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
  136. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  137. \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
  138. });
  139. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  140. /** @var $user \OC\User\User */
  141. \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
  142. });
  143. $userSession->listen('\OC\User', 'preDelete', function ($user) {
  144. /** @var $user \OC\User\User */
  145. \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
  146. });
  147. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  148. /** @var $user \OC\User\User */
  149. \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
  150. });
  151. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  152. /** @var $user \OC\User\User */
  153. \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  154. });
  155. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  156. /** @var $user \OC\User\User */
  157. \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  158. });
  159. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  160. \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
  161. });
  162. $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
  163. /** @var $user \OC\User\User */
  164. \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
  165. });
  166. $userSession->listen('\OC\User', 'logout', function () {
  167. \OC_Hook::emit('OC_User', 'logout', array());
  168. });
  169. return $userSession;
  170. });
  171. $this->registerService('NavigationManager', function ($c) {
  172. return new \OC\NavigationManager();
  173. });
  174. $this->registerService('AllConfig', function (Server $c) {
  175. return new \OC\AllConfig(
  176. $c->getSystemConfig()
  177. );
  178. });
  179. $this->registerService('SystemConfig', function ($c) {
  180. return new \OC\SystemConfig();
  181. });
  182. $this->registerService('AppConfig', function ($c) {
  183. return new \OC\AppConfig(\OC_DB::getConnection());
  184. });
  185. $this->registerService('L10NFactory', function ($c) {
  186. return new \OC\L10N\Factory();
  187. });
  188. $this->registerService('URLGenerator', function (Server $c) {
  189. $config = $c->getConfig();
  190. $cacheFactory = $c->getMemCacheFactory();
  191. return new \OC\URLGenerator(
  192. $config,
  193. $cacheFactory
  194. );
  195. });
  196. $this->registerService('AppHelper', function ($c) {
  197. return new \OC\AppHelper();
  198. });
  199. $this->registerService('UserCache', function ($c) {
  200. return new UserCache();
  201. });
  202. $this->registerService('MemCacheFactory', function (Server $c) {
  203. $config = $c->getConfig();
  204. if($config->getSystemValue('installed', false)) {
  205. $v = \OC_App::getAppVersions();
  206. $v['core'] = implode('.', \OC_Util::getVersion());
  207. $version = implode(',', $v);
  208. $instanceId = \OC_Util::getInstanceId();
  209. $path = \OC::$SERVERROOT;
  210. $prefix = md5($instanceId.'-'.$version.'-'.$path);
  211. return new \OC\Memcache\Factory($prefix,
  212. $config->getSystemValue('memcache.local', null),
  213. $config->getSystemValue('memcache.distributed', null)
  214. );
  215. }
  216. return new \OC\Memcache\Factory('',
  217. new ArrayCache(),
  218. new ArrayCache()
  219. );
  220. });
  221. $this->registerService('ActivityManager', function ($c) {
  222. return new ActivityManager();
  223. });
  224. $this->registerService('AvatarManager', function ($c) {
  225. return new AvatarManager();
  226. });
  227. $this->registerService('Logger', function (Server $c) {
  228. $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
  229. $logger = 'OC_Log_' . ucfirst($logClass);
  230. call_user_func(array($logger, 'init'));
  231. return new Log($logger);
  232. });
  233. $this->registerService('JobList', function (Server $c) {
  234. $config = $c->getConfig();
  235. return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
  236. });
  237. $this->registerService('Router', function (Server $c) {
  238. $cacheFactory = $c->getMemCacheFactory();
  239. if ($cacheFactory->isAvailable()) {
  240. $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
  241. } else {
  242. $router = new \OC\Route\Router();
  243. }
  244. return $router;
  245. });
  246. $this->registerService('Search', function ($c) {
  247. return new Search();
  248. });
  249. $this->registerService('SecureRandom', function ($c) {
  250. return new SecureRandom();
  251. });
  252. $this->registerService('Crypto', function (Server $c) {
  253. return new Crypto($c->getConfig(), $c->getSecureRandom());
  254. });
  255. $this->registerService('Hasher', function (Server $c) {
  256. return new Hasher($c->getConfig());
  257. });
  258. $this->registerService('DatabaseConnection', function (Server $c) {
  259. $factory = new \OC\DB\ConnectionFactory();
  260. $systemConfig = $c->getSystemConfig();
  261. $type = $systemConfig->getValue('dbtype', 'sqlite');
  262. if (!$factory->isValidType($type)) {
  263. throw new \OC\DatabaseException('Invalid database type');
  264. }
  265. $connectionParams = $factory->createConnectionParams($systemConfig);
  266. $connection = $factory->getConnection($type, $connectionParams);
  267. $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
  268. return $connection;
  269. });
  270. $this->registerService('Db', function (Server $c) {
  271. return new Db($c->getDatabaseConnection());
  272. });
  273. $this->registerService('HTTPHelper', function (Server $c) {
  274. $config = $c->getConfig();
  275. return new HTTPHelper(
  276. $config,
  277. $c->getHTTPClientService()
  278. );
  279. });
  280. $this->registerService('HttpClientService', function (Server $c) {
  281. $user = \OC_User::getUser();
  282. $uid = $user ? $user : null;
  283. return new ClientService(
  284. $c->getConfig(),
  285. new \OC\Security\CertificateManager($uid, new \OC\Files\View())
  286. );
  287. });
  288. $this->registerService('EventLogger', function (Server $c) {
  289. if (defined('DEBUG') and DEBUG) {
  290. return new EventLogger();
  291. } else {
  292. return new NullEventLogger();
  293. }
  294. });
  295. $this->registerService('QueryLogger', function ($c) {
  296. if (defined('DEBUG') and DEBUG) {
  297. return new QueryLogger();
  298. } else {
  299. return new NullQueryLogger();
  300. }
  301. });
  302. $this->registerService('TempManager', function (Server $c) {
  303. return new TempManager(get_temp_dir(), $c->getLogger());
  304. });
  305. $this->registerService('AppManager', function(Server $c) {
  306. return new \OC\App\AppManager(
  307. $c->getUserSession(),
  308. $c->getAppConfig(),
  309. $c->getGroupManager(),
  310. $c->getMemCacheFactory()
  311. );
  312. });
  313. $this->registerService('DateTimeZone', function(Server $c) {
  314. return new DateTimeZone(
  315. $c->getConfig(),
  316. $c->getSession()
  317. );
  318. });
  319. $this->registerService('DateTimeFormatter', function(Server $c) {
  320. $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
  321. return new DateTimeFormatter(
  322. $c->getDateTimeZone()->getTimeZone(),
  323. $c->getL10N('lib', $language)
  324. );
  325. });
  326. $this->registerService('MountConfigManager', function () {
  327. $loader = \OC\Files\Filesystem::getLoader();
  328. return new \OC\Files\Config\MountProviderCollection($loader);
  329. });
  330. $this->registerService('IniWrapper', function ($c) {
  331. return new IniGetWrapper();
  332. });
  333. $this->registerService('AsyncCommandBus', function (Server $c) {
  334. $jobList = $c->getJobList();
  335. return new AsyncBus($jobList);
  336. });
  337. $this->registerService('TrustedDomainHelper', function ($c) {
  338. return new TrustedDomainHelper($this->getConfig());
  339. });
  340. $this->registerService('Request', function ($c) {
  341. if (isset($this['urlParams'])) {
  342. $urlParams = $this['urlParams'];
  343. } else {
  344. $urlParams = [];
  345. }
  346. if ($this->getSession()->exists('requesttoken')) {
  347. $requestToken = $this->getSession()->get('requesttoken');
  348. } else {
  349. $requestToken = false;
  350. }
  351. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  352. && in_array('fakeinput', stream_get_wrappers())
  353. ) {
  354. $stream = 'fakeinput://data';
  355. } else {
  356. $stream = 'php://input';
  357. }
  358. return new Request(
  359. [
  360. 'get' => $_GET,
  361. 'post' => $_POST,
  362. 'files' => $_FILES,
  363. 'server' => $_SERVER,
  364. 'env' => $_ENV,
  365. 'cookies' => $_COOKIE,
  366. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  367. ? $_SERVER['REQUEST_METHOD']
  368. : null,
  369. 'urlParams' => $urlParams,
  370. 'requesttoken' => $requestToken,
  371. ],
  372. $this->getSecureRandom(),
  373. $this->getConfig(),
  374. $stream
  375. );
  376. });
  377. $this->registerService('Mailer', function(Server $c) {
  378. return new Mailer(
  379. $c->getConfig(),
  380. $c->getLogger(),
  381. new \OC_Defaults()
  382. );
  383. });
  384. }
  385. /**
  386. * @return \OCP\Contacts\IManager
  387. */
  388. function getContactsManager() {
  389. return $this->query('ContactsManager');
  390. }
  391. /**
  392. * @return \OC\Encryption\Manager
  393. */
  394. function getEncryptionManager() {
  395. return $this->query('EncryptionManager');
  396. }
  397. /**
  398. * @return \OC\Encryption\File
  399. */
  400. function getEncryptionFilesHelper() {
  401. return $this->query('EncryptionFileHelper');
  402. }
  403. /**
  404. * @param string $encryptionModuleId encryption module ID
  405. *
  406. * @return \OCP\Encryption\Keys\IStorage
  407. */
  408. function getEncryptionKeyStorage($encryptionModuleId) {
  409. $view = new \OC\Files\View();
  410. $util = new \OC\Encryption\Util($view, \OC::$server->getUserManager(), \OC::$server->getConfig());
  411. return $this->query('EncryptionKeyStorageFactory')->get($encryptionModuleId, $view, $util);
  412. }
  413. /**
  414. * The current request object holding all information about the request
  415. * currently being processed is returned from this method.
  416. * In case the current execution was not initiated by a web request null is returned
  417. *
  418. * @return \OCP\IRequest|null
  419. */
  420. function getRequest() {
  421. return $this->query('Request');
  422. }
  423. /**
  424. * Returns the preview manager which can create preview images for a given file
  425. *
  426. * @return \OCP\IPreview
  427. */
  428. function getPreviewManager() {
  429. return $this->query('PreviewManager');
  430. }
  431. /**
  432. * Returns the tag manager which can get and set tags for different object types
  433. *
  434. * @see \OCP\ITagManager::load()
  435. * @return \OCP\ITagManager
  436. */
  437. function getTagManager() {
  438. return $this->query('TagManager');
  439. }
  440. /**
  441. * Returns the avatar manager, used for avatar functionality
  442. *
  443. * @return \OCP\IAvatarManager
  444. */
  445. function getAvatarManager() {
  446. return $this->query('AvatarManager');
  447. }
  448. /**
  449. * Returns the root folder of ownCloud's data directory
  450. *
  451. * @return \OCP\Files\Folder
  452. */
  453. function getRootFolder() {
  454. return $this->query('RootFolder');
  455. }
  456. /**
  457. * Returns a view to ownCloud's files folder
  458. *
  459. * @param string $userId user ID
  460. * @return \OCP\Files\Folder
  461. */
  462. function getUserFolder($userId = null) {
  463. if ($userId === null) {
  464. $user = $this->getUserSession()->getUser();
  465. if (!$user) {
  466. return null;
  467. }
  468. $userId = $user->getUID();
  469. } else {
  470. $user = $this->getUserManager()->get($userId);
  471. }
  472. \OC\Files\Filesystem::initMountPoints($userId);
  473. $dir = '/' . $userId;
  474. $root = $this->getRootFolder();
  475. $folder = null;
  476. if (!$root->nodeExists($dir)) {
  477. $folder = $root->newFolder($dir);
  478. } else {
  479. $folder = $root->get($dir);
  480. }
  481. $dir = '/files';
  482. if (!$folder->nodeExists($dir)) {
  483. $folder = $folder->newFolder($dir);
  484. \OC_Util::copySkeleton($user, $folder);
  485. } else {
  486. $folder = $folder->get($dir);
  487. }
  488. return $folder;
  489. }
  490. /**
  491. * Returns an app-specific view in ownClouds data directory
  492. *
  493. * @return \OCP\Files\Folder
  494. */
  495. function getAppFolder() {
  496. $dir = '/' . \OC_App::getCurrentApp();
  497. $root = $this->getRootFolder();
  498. $folder = null;
  499. if (!$root->nodeExists($dir)) {
  500. $folder = $root->newFolder($dir);
  501. } else {
  502. $folder = $root->get($dir);
  503. }
  504. return $folder;
  505. }
  506. /**
  507. * @return \OC\User\Manager
  508. */
  509. function getUserManager() {
  510. return $this->query('UserManager');
  511. }
  512. /**
  513. * @return \OC\Group\Manager
  514. */
  515. function getGroupManager() {
  516. return $this->query('GroupManager');
  517. }
  518. /**
  519. * @return \OC\User\Session
  520. */
  521. function getUserSession() {
  522. return $this->query('UserSession');
  523. }
  524. /**
  525. * @return \OCP\ISession
  526. */
  527. function getSession() {
  528. return $this->query('UserSession')->getSession();
  529. }
  530. /**
  531. * @param \OCP\ISession $session
  532. */
  533. function setSession(\OCP\ISession $session) {
  534. return $this->query('UserSession')->setSession($session);
  535. }
  536. /**
  537. * @return \OC\NavigationManager
  538. */
  539. function getNavigationManager() {
  540. return $this->query('NavigationManager');
  541. }
  542. /**
  543. * @return \OCP\IConfig
  544. */
  545. function getConfig() {
  546. return $this->query('AllConfig');
  547. }
  548. /**
  549. * For internal use only
  550. *
  551. * @return \OC\SystemConfig
  552. */
  553. function getSystemConfig() {
  554. return $this->query('SystemConfig');
  555. }
  556. /**
  557. * Returns the app config manager
  558. *
  559. * @return \OCP\IAppConfig
  560. */
  561. function getAppConfig() {
  562. return $this->query('AppConfig');
  563. }
  564. /**
  565. * get an L10N instance
  566. *
  567. * @param string $app appid
  568. * @param string $lang
  569. * @return \OC_L10N
  570. */
  571. function getL10N($app, $lang = null) {
  572. return $this->query('L10NFactory')->get($app, $lang);
  573. }
  574. /**
  575. * @return \OCP\IURLGenerator
  576. */
  577. function getURLGenerator() {
  578. return $this->query('URLGenerator');
  579. }
  580. /**
  581. * @return \OCP\IHelper
  582. */
  583. function getHelper() {
  584. return $this->query('AppHelper');
  585. }
  586. /**
  587. * Returns an ICache instance
  588. *
  589. * @return \OCP\ICache
  590. */
  591. function getCache() {
  592. return $this->query('UserCache');
  593. }
  594. /**
  595. * Returns an \OCP\CacheFactory instance
  596. *
  597. * @return \OCP\ICacheFactory
  598. */
  599. function getMemCacheFactory() {
  600. return $this->query('MemCacheFactory');
  601. }
  602. /**
  603. * Returns the current session
  604. *
  605. * @return \OCP\IDBConnection
  606. */
  607. function getDatabaseConnection() {
  608. return $this->query('DatabaseConnection');
  609. }
  610. /**
  611. * Returns the activity manager
  612. *
  613. * @return \OCP\Activity\IManager
  614. */
  615. function getActivityManager() {
  616. return $this->query('ActivityManager');
  617. }
  618. /**
  619. * Returns an job list for controlling background jobs
  620. *
  621. * @return \OCP\BackgroundJob\IJobList
  622. */
  623. function getJobList() {
  624. return $this->query('JobList');
  625. }
  626. /**
  627. * Returns a logger instance
  628. *
  629. * @return \OCP\ILogger
  630. */
  631. function getLogger() {
  632. return $this->query('Logger');
  633. }
  634. /**
  635. * Returns a router for generating and matching urls
  636. *
  637. * @return \OCP\Route\IRouter
  638. */
  639. function getRouter() {
  640. return $this->query('Router');
  641. }
  642. /**
  643. * Returns a search instance
  644. *
  645. * @return \OCP\ISearch
  646. */
  647. function getSearch() {
  648. return $this->query('Search');
  649. }
  650. /**
  651. * Returns a SecureRandom instance
  652. *
  653. * @return \OCP\Security\ISecureRandom
  654. */
  655. function getSecureRandom() {
  656. return $this->query('SecureRandom');
  657. }
  658. /**
  659. * Returns a Crypto instance
  660. *
  661. * @return \OCP\Security\ICrypto
  662. */
  663. function getCrypto() {
  664. return $this->query('Crypto');
  665. }
  666. /**
  667. * Returns a Hasher instance
  668. *
  669. * @return \OCP\Security\IHasher
  670. */
  671. function getHasher() {
  672. return $this->query('Hasher');
  673. }
  674. /**
  675. * Returns an instance of the db facade
  676. * @deprecated use getDatabaseConnection, will be removed in ownCloud 10
  677. * @return \OCP\IDb
  678. */
  679. function getDb() {
  680. return $this->query('Db');
  681. }
  682. /**
  683. * Returns an instance of the HTTP helper class
  684. * @deprecated Use getHTTPClientService()
  685. * @return \OC\HTTPHelper
  686. */
  687. function getHTTPHelper() {
  688. return $this->query('HTTPHelper');
  689. }
  690. /**
  691. * Get the certificate manager for the user
  692. *
  693. * @param string $uid (optional) if not specified the current loggedin user is used
  694. * @return \OCP\ICertificateManager
  695. */
  696. function getCertificateManager($uid = null) {
  697. if (is_null($uid)) {
  698. $userSession = $this->getUserSession();
  699. $user = $userSession->getUser();
  700. if (is_null($user)) {
  701. return null;
  702. }
  703. $uid = $user->getUID();
  704. }
  705. return new CertificateManager($uid, new \OC\Files\View());
  706. }
  707. /**
  708. * Returns an instance of the HTTP client service
  709. *
  710. * @return \OCP\Http\Client\IClientService
  711. */
  712. function getHTTPClientService() {
  713. return $this->query('HttpClientService');
  714. }
  715. /**
  716. * Create a new event source
  717. *
  718. * @return \OCP\IEventSource
  719. */
  720. function createEventSource() {
  721. return new \OC_EventSource();
  722. }
  723. /**
  724. * Get the active event logger
  725. *
  726. * The returned logger only logs data when debug mode is enabled
  727. *
  728. * @return \OCP\Diagnostics\IEventLogger
  729. */
  730. function getEventLogger() {
  731. return $this->query('EventLogger');
  732. }
  733. /**
  734. * Get the active query logger
  735. *
  736. * The returned logger only logs data when debug mode is enabled
  737. *
  738. * @return \OCP\Diagnostics\IQueryLogger
  739. */
  740. function getQueryLogger() {
  741. return $this->query('QueryLogger');
  742. }
  743. /**
  744. * Get the manager for temporary files and folders
  745. *
  746. * @return \OCP\ITempManager
  747. */
  748. function getTempManager() {
  749. return $this->query('TempManager');
  750. }
  751. /**
  752. * Get the app manager
  753. *
  754. * @return \OCP\App\IAppManager
  755. */
  756. function getAppManager() {
  757. return $this->query('AppManager');
  758. }
  759. /**
  760. * Creates a new mailer
  761. *
  762. * @return \OCP\Mail\IMailer
  763. */
  764. function getMailer() {
  765. return $this->query('Mailer');
  766. }
  767. /**
  768. * Get the webroot
  769. *
  770. * @return string
  771. */
  772. function getWebRoot() {
  773. return $this->webRoot;
  774. }
  775. /**
  776. * @return \OCP\IDateTimeZone
  777. */
  778. public function getDateTimeZone() {
  779. return $this->query('DateTimeZone');
  780. }
  781. /**
  782. * @return \OCP\IDateTimeFormatter
  783. */
  784. public function getDateTimeFormatter() {
  785. return $this->query('DateTimeFormatter');
  786. }
  787. /**
  788. * @return \OCP\Files\Config\IMountProviderCollection
  789. */
  790. function getMountProviderCollection(){
  791. return $this->query('MountConfigManager');
  792. }
  793. /**
  794. * Get the IniWrapper
  795. *
  796. * @return IniGetWrapper
  797. */
  798. public function getIniWrapper() {
  799. return $this->query('IniWrapper');
  800. }
  801. /**
  802. * @return \OCP\Command\IBus
  803. */
  804. function getCommandBus(){
  805. return $this->query('AsyncCommandBus');
  806. }
  807. /**
  808. * Get the trusted domain helper
  809. *
  810. * @return TrustedDomainHelper
  811. */
  812. public function getTrustedDomainHelper() {
  813. return $this->query('TrustedDomainHelper');
  814. }
  815. }