2013-08-17 13:16:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Thomas Tanghus <thomas@tanghus.net>
|
2013-08-17 13:16:48 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2013-08-17 13:16:48 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2013-08-17 13:16:48 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2013-08-17 13:16:48 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2013-08-17 13:16:48 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2013-08-17 13:16:48 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
|
|
|
|
2013-08-17 13:16:48 +04:00
|
|
|
namespace OC\AppFramework\DependencyInjection;
|
|
|
|
|
2015-01-22 17:33:09 +03:00
|
|
|
use OC;
|
2016-05-11 12:23:25 +03:00
|
|
|
use OC\AppFramework\Core\API;
|
2013-10-23 07:57:34 +04:00
|
|
|
use OC\AppFramework\Http;
|
2013-08-17 13:16:48 +04:00
|
|
|
use OC\AppFramework\Http\Dispatcher;
|
2015-01-22 22:26:46 +03:00
|
|
|
use OC\AppFramework\Http\Output;
|
2013-08-17 13:16:48 +04:00
|
|
|
use OC\AppFramework\Middleware\MiddlewareDispatcher;
|
2014-05-08 13:47:18 +04:00
|
|
|
use OC\AppFramework\Middleware\Security\CORSMiddleware;
|
2016-07-20 10:43:02 +03:00
|
|
|
use OC\AppFramework\Middleware\OCSMiddleware;
|
2016-05-11 12:23:25 +03:00
|
|
|
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
|
2014-10-21 16:53:10 +04:00
|
|
|
use OC\AppFramework\Middleware\SessionMiddleware;
|
2013-08-20 19:21:14 +04:00
|
|
|
use OC\AppFramework\Utility\SimpleContainer;
|
2016-05-11 12:23:25 +03:00
|
|
|
use OC\Core\Middleware\TwoFactorMiddleware;
|
2016-10-12 13:08:42 +03:00
|
|
|
use OC\RichObjectStrings\Validator;
|
2017-03-20 01:14:47 +03:00
|
|
|
use OC\ServerContainer;
|
2013-08-21 03:02:15 +04:00
|
|
|
use OCP\AppFramework\IApi;
|
|
|
|
use OCP\AppFramework\IAppContainer;
|
2017-03-17 16:25:35 +03:00
|
|
|
use OCP\AppFramework\QueryException;
|
2017-02-14 14:47:46 +03:00
|
|
|
use OCP\Federation\ICloudIdManager;
|
2016-09-08 16:20:39 +03:00
|
|
|
use OCP\Files\IAppData;
|
2016-09-30 11:09:52 +03:00
|
|
|
use OCP\Files\Mount\IMountManager;
|
2017-03-20 00:20:56 +03:00
|
|
|
use OCP\IServerContainer;
|
2016-10-12 13:08:42 +03:00
|
|
|
use OCP\RichObjectStrings\IValidator;
|
2017-02-24 09:01:13 +03:00
|
|
|
use OCP\Util;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
class DIContainer extends SimpleContainer implements IAppContainer {
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2013-09-27 19:15:26 +04:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-09-28 22:40:25 +04:00
|
|
|
private $middleWares = array();
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2017-03-20 01:14:47 +03:00
|
|
|
/** @var ServerContainer */
|
2017-03-20 00:20:56 +03:00
|
|
|
private $server;
|
|
|
|
|
2013-08-17 13:16:48 +04:00
|
|
|
/**
|
|
|
|
* Put your class dependencies in here
|
|
|
|
* @param string $appName the name of the app
|
2017-03-20 00:20:56 +03:00
|
|
|
* @param array $urlParams
|
2017-03-20 01:14:47 +03:00
|
|
|
* @param ServerContainer $server
|
2013-08-17 13:16:48 +04:00
|
|
|
*/
|
2017-03-20 01:14:47 +03:00
|
|
|
public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
|
2015-07-24 14:43:50 +03:00
|
|
|
parent::__construct();
|
2013-08-17 13:16:48 +04:00
|
|
|
$this['AppName'] = $appName;
|
2013-10-01 21:01:52 +04:00
|
|
|
$this['urlParams'] = $urlParams;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2015-12-18 13:43:39 +03:00
|
|
|
/** @var \OC\ServerContainer $server */
|
2017-03-20 00:20:56 +03:00
|
|
|
if ($server === null) {
|
2017-03-20 01:14:47 +03:00
|
|
|
$server = \OC::$server;
|
2017-03-20 00:20:56 +03:00
|
|
|
}
|
2017-03-20 01:14:47 +03:00
|
|
|
$this->server = $server;
|
2017-03-20 00:20:56 +03:00
|
|
|
$this->server->registerAppContainer($appName, $this);
|
2015-12-18 13:43:39 +03:00
|
|
|
|
2015-04-29 23:29:45 +03:00
|
|
|
// aliases
|
2015-07-17 18:18:37 +03:00
|
|
|
$this->registerAlias('appName', 'AppName');
|
|
|
|
$this->registerAlias('webRoot', 'WebRoot');
|
|
|
|
$this->registerAlias('userId', 'UserId');
|
2015-04-29 23:29:45 +03:00
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
/**
|
|
|
|
* Core services
|
|
|
|
*/
|
2015-01-22 22:26:46 +03:00
|
|
|
$this->registerService('OCP\\AppFramework\\Http\\IOutput', function($c){
|
2015-10-06 16:24:19 +03:00
|
|
|
return new Output($this->getServer()->getWebRoot());
|
2015-01-22 22:26:46 +03:00
|
|
|
});
|
|
|
|
|
2016-11-08 11:15:02 +03:00
|
|
|
$this->registerService(\OCP\Authentication\LoginCredentials\IStore::class, function() {
|
|
|
|
return $this->getServer()->query(\OCP\Authentication\LoginCredentials\IStore::class);
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\IAvatarManager', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getAvatarManager();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\Activity\\IManager', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getActivityManager();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
2016-11-25 17:21:16 +03:00
|
|
|
$this->registerService(\OCP\Activity\IEventMerger::class, function($c) {
|
|
|
|
return $this->getServer()->query(\OCP\Activity\IEventMerger::class);
|
|
|
|
});
|
2014-12-13 21:28:20 +03:00
|
|
|
|
|
|
|
$this->registerService('OCP\\ICache', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getCache();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2015-07-22 14:04:56 +03:00
|
|
|
$this->registerService('OC\\CapabilitiesManager', function($c) {
|
|
|
|
return $this->getServer()->getCapabilitiesManager();
|
|
|
|
});
|
|
|
|
|
2016-02-05 13:20:16 +03:00
|
|
|
$this->registerService('OCP\Comments\ICommentsManager', function($c) {
|
|
|
|
return $this->getServer()->getCommentsManager();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\Contacts\\IManager', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getContactsManager();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\IDateTimeZone', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getDateTimeZone();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2016-08-10 16:21:25 +03:00
|
|
|
$this->registerService('OCP\\IDateTimeFormatter', function($c) {
|
|
|
|
return $this->getServer()->getDateTimeFormatter();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\IDBConnection', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getDatabaseConnection();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\Diagnostics\\IEventLogger', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getEventLogger();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\Diagnostics\\IQueryLogger', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getQueryLogger();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2017-02-14 14:47:46 +03:00
|
|
|
$this->registerService(ICloudIdManager::class, function($c) {
|
|
|
|
return $this->getServer()->getCloudIdManager();
|
|
|
|
});
|
|
|
|
|
2015-12-01 18:49:20 +03:00
|
|
|
$this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) {
|
|
|
|
return $this->getServer()->getMimeTypeDetector();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\Files\\Config\\IMountProviderCollection', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getMountProviderCollection();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2016-08-15 14:38:02 +03:00
|
|
|
$this->registerService('OCP\\Files\\Config\\IUserMountCache', function($c) {
|
|
|
|
return $this->getServer()->getUserMountCache();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\Files\\IRootFolder', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getRootFolder();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
$this->registerService('OCP\\Files\\Folder', function() {
|
|
|
|
return $this->getServer()->getUserFolder();
|
|
|
|
});
|
|
|
|
|
2016-05-01 16:08:56 +03:00
|
|
|
$this->registerService('OCP\\Http\\Client\\IClientService', function($c) {
|
|
|
|
return $this->getServer()->getHTTPClientService();
|
|
|
|
});
|
|
|
|
|
2016-09-08 16:20:39 +03:00
|
|
|
$this->registerService(IAppData::class, function (SimpleContainer $c) {
|
|
|
|
return $this->getServer()->getAppDataDir($c->query('AppName'));
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\IGroupManager', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getGroupManager();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2016-05-04 16:26:48 +03:00
|
|
|
$this->registerService('OCP\\Http\\Client\\IClientService', function() {
|
|
|
|
return $this->getServer()->getHTTPClientService();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\IL10N', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getL10N($c->query('AppName'));
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2016-02-01 18:57:51 +03:00
|
|
|
$this->registerService('OCP\\L10N\\IFactory', function($c) {
|
|
|
|
return $this->getServer()->getL10NFactory();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\ILogger', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getLogger();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\BackgroundJob\\IJobList', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getJobList();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2015-07-17 18:18:37 +03:00
|
|
|
$this->registerAlias('OCP\\AppFramework\\Utility\\IControllerMethodReflector', 'OC\AppFramework\Utility\ControllerMethodReflector');
|
|
|
|
$this->registerAlias('ControllerMethodReflector', 'OCP\\AppFramework\\Utility\\IControllerMethodReflector');
|
2014-12-13 21:28:20 +03:00
|
|
|
|
2016-01-07 15:20:43 +03:00
|
|
|
$this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) {
|
|
|
|
return $this->getServer()->getMimeTypeDetector();
|
|
|
|
});
|
|
|
|
|
2016-04-25 17:02:57 +03:00
|
|
|
$this->registerService('OCP\\Mail\\IMailer', function() {
|
|
|
|
return $this->getServer()->getMailer();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\INavigationManager', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getNavigationManager();
|
2013-08-17 13:16:48 +04:00
|
|
|
});
|
|
|
|
|
2016-01-22 13:02:40 +03:00
|
|
|
$this->registerService('OCP\\Notification\IManager', function($c) {
|
|
|
|
return $this->getServer()->getNotificationManager();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\IPreview', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getPreviewManager();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2015-07-17 18:18:37 +03:00
|
|
|
$this->registerService('OCP\\IRequest', function () {
|
|
|
|
return $this->getServer()->getRequest();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
2015-07-17 18:18:37 +03:00
|
|
|
$this->registerAlias('Request', 'OCP\\IRequest');
|
2014-12-13 21:28:20 +03:00
|
|
|
|
|
|
|
$this->registerService('OCP\\ITagManager', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getTagManager();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2015-07-17 18:18:37 +03:00
|
|
|
$this->registerAlias('OCP\\AppFramework\\Utility\\ITimeFactory', 'OC\AppFramework\Utility\TimeFactory');
|
|
|
|
$this->registerAlias('TimeFactory', 'OCP\\AppFramework\\Utility\\ITimeFactory');
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
|
|
|
|
$this->registerService('OCP\\Route\\IRouter', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getRouter();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\ISearch', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getSearch();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\ISearch', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getSearch();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\Security\\ICrypto', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getCrypto();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\Security\\IHasher', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getHasher();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2015-08-24 18:13:16 +03:00
|
|
|
$this->registerService('OCP\\Security\\ICredentialsManager', function($c) {
|
|
|
|
return $this->getServer()->getCredentialsManager();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\Security\\ISecureRandom', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getSecureRandom();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
2016-01-27 16:48:52 +03:00
|
|
|
$this->registerService('OCP\\Share\\IManager', function($c) {
|
|
|
|
return $this->getServer()->getShareManager();
|
|
|
|
});
|
|
|
|
|
2015-11-30 19:08:29 +03:00
|
|
|
$this->registerService('OCP\\SystemTag\\ISystemTagManager', function() {
|
|
|
|
return $this->getServer()->getSystemTagManager();
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\SystemTag\\ISystemTagObjectMapper', function() {
|
|
|
|
return $this->getServer()->getSystemTagObjectMapper();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('OCP\\IURLGenerator', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getURLGenerator();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\IUserManager', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getUserManager();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('OCP\\IUserSession', function($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getUserSession();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
2016-09-06 22:41:15 +03:00
|
|
|
$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
|
2014-12-13 21:28:20 +03:00
|
|
|
|
2015-08-07 14:28:57 +03:00
|
|
|
$this->registerService('OCP\\ISession', function($c) {
|
|
|
|
return $this->getServer()->getSession();
|
|
|
|
});
|
|
|
|
|
2016-01-28 16:33:02 +03:00
|
|
|
$this->registerService('OCP\\Security\\IContentSecurityPolicyManager', function($c) {
|
|
|
|
return $this->getServer()->getContentSecurityPolicyManager();
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('ServerContainer', function ($c) {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer();
|
2014-12-13 21:28:20 +03:00
|
|
|
});
|
2015-11-26 20:20:25 +03:00
|
|
|
$this->registerAlias('OCP\\IServerContainer', 'ServerContainer');
|
2014-12-13 21:28:20 +03:00
|
|
|
|
2015-11-16 22:57:41 +03:00
|
|
|
$this->registerService('Symfony\Component\EventDispatcher\EventDispatcherInterface', function ($c) {
|
|
|
|
return $this->getServer()->getEventDispatcher();
|
|
|
|
});
|
|
|
|
|
2016-07-27 12:46:09 +03:00
|
|
|
$this->registerService('OCP\WorkflowEngine\IManager', function ($c) {
|
|
|
|
return $c->query('OCA\WorkflowEngine\Manager');
|
|
|
|
});
|
|
|
|
|
2015-10-20 11:32:53 +03:00
|
|
|
$this->registerService('OCP\\AppFramework\\IAppContainer', function ($c) {
|
|
|
|
return $c;
|
|
|
|
});
|
2016-09-30 11:09:52 +03:00
|
|
|
$this->registerService(IMountManager::class, function () {
|
|
|
|
return $this->getServer()->getMountManager();
|
|
|
|
});
|
2015-10-20 11:32:53 +03:00
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
// commonly used attributes
|
|
|
|
$this->registerService('UserId', function ($c) {
|
|
|
|
return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->registerService('WebRoot', function ($c) {
|
|
|
|
return $c->query('ServerContainer')->getWebRoot();
|
|
|
|
});
|
|
|
|
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->registerService('fromMailAddress', function() {
|
|
|
|
return Util::getDefaultEmailAddress('no-reply');
|
|
|
|
});
|
|
|
|
|
2017-02-24 22:09:09 +03:00
|
|
|
$this->registerService('OC_Defaults', function ($c) {
|
|
|
|
return $c->getServer()->getThemingDefaults();
|
|
|
|
});
|
|
|
|
|
2016-08-13 02:26:11 +03:00
|
|
|
$this->registerService('OCP\Encryption\IManager', function ($c) {
|
|
|
|
return $this->getServer()->getEncryptionManager();
|
2016-08-11 16:50:31 +03:00
|
|
|
});
|
|
|
|
|
2016-10-12 13:08:42 +03:00
|
|
|
$this->registerService(IValidator::class, function($c) {
|
|
|
|
return $c->query(Validator::class);
|
|
|
|
});
|
|
|
|
|
2017-02-08 18:33:58 +03:00
|
|
|
$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
|
|
|
|
return new \OC\Security\IdentityProof\Manager(
|
|
|
|
$this->getServer()->getAppDataDir('identityproof'),
|
|
|
|
$this->getServer()->getCrypto()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-12-13 21:28:20 +03:00
|
|
|
|
2013-08-17 13:16:48 +04:00
|
|
|
/**
|
2014-12-13 21:28:20 +03:00
|
|
|
* App Framework APIs
|
2013-08-17 13:16:48 +04:00
|
|
|
*/
|
2014-12-13 21:28:20 +03:00
|
|
|
$this->registerService('API', function($c){
|
2015-01-06 15:43:40 +03:00
|
|
|
$c->query('OCP\\ILogger')->debug(
|
2014-12-13 21:28:20 +03:00
|
|
|
'Accessing the API class is deprecated! Use the appropriate ' .
|
|
|
|
'services instead!'
|
|
|
|
);
|
|
|
|
return new API($c['AppName']);
|
|
|
|
});
|
|
|
|
|
2014-11-03 15:10:03 +03:00
|
|
|
$this->registerService('Protocol', function($c){
|
2015-10-30 20:05:30 +03:00
|
|
|
/** @var \OC\Server $server */
|
|
|
|
$server = $c->query('ServerContainer');
|
|
|
|
$protocol = $server->getRequest()->getHttpProtocol();
|
|
|
|
return new Http($_SERVER, $protocol);
|
2013-08-17 13:16:48 +04:00
|
|
|
});
|
|
|
|
|
2014-11-03 15:10:03 +03:00
|
|
|
$this->registerService('Dispatcher', function($c) {
|
2014-05-06 18:29:19 +04:00
|
|
|
return new Dispatcher(
|
2014-05-28 04:12:01 +04:00
|
|
|
$c['Protocol'],
|
|
|
|
$c['MiddlewareDispatcher'],
|
2014-05-06 18:31:08 +04:00
|
|
|
$c['ControllerMethodReflector'],
|
|
|
|
$c['Request']
|
2014-05-06 18:29:19 +04:00
|
|
|
);
|
2013-08-17 13:16:48 +04:00
|
|
|
});
|
|
|
|
|
2016-07-22 11:11:53 +03:00
|
|
|
/**
|
|
|
|
* App Framework default arguments
|
|
|
|
*/
|
|
|
|
$this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
|
|
|
|
$this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
|
|
|
|
$this->registerParameter('corsMaxAge', 1728000);
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware
|
|
|
|
*/
|
2013-10-22 11:29:17 +04:00
|
|
|
$app = $this;
|
2014-11-03 15:10:03 +03:00
|
|
|
$this->registerService('SecurityMiddleware', function($c) use ($app){
|
2017-01-17 13:51:10 +03:00
|
|
|
/** @var \OC\Server $server */
|
|
|
|
$server = $app->getServer();
|
|
|
|
|
2014-05-06 18:29:19 +04:00
|
|
|
return new SecurityMiddleware(
|
2014-05-28 04:12:01 +04:00
|
|
|
$c['Request'],
|
|
|
|
$c['ControllerMethodReflector'],
|
2017-01-17 13:51:10 +03:00
|
|
|
$server->getNavigationManager(),
|
|
|
|
$server->getURLGenerator(),
|
|
|
|
$server->getLogger(),
|
|
|
|
$server->getSession(),
|
2014-05-28 04:12:01 +04:00
|
|
|
$c['AppName'],
|
|
|
|
$app->isLoggedIn(),
|
2016-01-28 16:33:02 +03:00
|
|
|
$app->isAdminUser(),
|
2017-01-17 13:51:10 +03:00
|
|
|
$server->getContentSecurityPolicyManager(),
|
|
|
|
$server->getCsrfTokenManager(),
|
|
|
|
$server->getContentSecurityPolicyNonceManager(),
|
|
|
|
$server->getBruteForceThrottler()
|
2014-05-06 18:29:19 +04:00
|
|
|
);
|
2017-01-17 13:51:10 +03:00
|
|
|
|
2013-08-17 13:16:48 +04:00
|
|
|
});
|
|
|
|
|
2014-11-03 15:10:03 +03:00
|
|
|
$this->registerService('CORSMiddleware', function($c) {
|
2014-05-11 19:55:59 +04:00
|
|
|
return new CORSMiddleware(
|
|
|
|
$c['Request'],
|
2015-05-22 14:17:27 +03:00
|
|
|
$c['ControllerMethodReflector'],
|
2016-07-20 19:36:15 +03:00
|
|
|
$c['OCP\IUserSession'],
|
|
|
|
$c->getServer()->getBruteForceThrottler()
|
2014-05-11 19:55:59 +04:00
|
|
|
);
|
2014-05-08 13:47:18 +04:00
|
|
|
});
|
|
|
|
|
2014-11-03 15:10:03 +03:00
|
|
|
$this->registerService('SessionMiddleware', function($c) use ($app) {
|
2014-10-21 16:53:10 +04:00
|
|
|
return new SessionMiddleware(
|
|
|
|
$c['Request'],
|
|
|
|
$c['ControllerMethodReflector'],
|
|
|
|
$app->getServer()->getSession()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-05-11 12:23:25 +03:00
|
|
|
$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
|
|
|
|
$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
|
|
|
|
$userSession = $app->getServer()->getUserSession();
|
|
|
|
$session = $app->getServer()->getSession();
|
|
|
|
$urlGenerator = $app->getServer()->getURLGenerator();
|
|
|
|
$reflector = $c['ControllerMethodReflector'];
|
2016-06-01 14:54:08 +03:00
|
|
|
$request = $app->getServer()->getRequest();
|
|
|
|
return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
|
2016-05-11 12:23:25 +03:00
|
|
|
});
|
|
|
|
|
2016-07-20 10:43:02 +03:00
|
|
|
$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
|
|
|
|
return new OCSMiddleware(
|
|
|
|
$c['Request']
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-11 22:50:49 +04:00
|
|
|
$middleWares = &$this->middleWares;
|
2014-11-03 15:10:03 +03:00
|
|
|
$this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
|
2013-08-17 13:16:48 +04:00
|
|
|
$dispatcher = new MiddlewareDispatcher();
|
2014-05-08 13:47:18 +04:00
|
|
|
$dispatcher->registerMiddleware($c['CORSMiddleware']);
|
2016-08-12 16:15:24 +03:00
|
|
|
$dispatcher->registerMiddleware($c['OCSMiddleware']);
|
2015-05-22 14:17:27 +03:00
|
|
|
$dispatcher->registerMiddleware($c['SecurityMiddleware']);
|
2016-05-11 12:23:25 +03:00
|
|
|
$dispatcher->registerMiddleWare($c['TwoFactorMiddleware']);
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2014-04-11 22:50:49 +04:00
|
|
|
foreach($middleWares as $middleWare) {
|
2014-04-10 01:59:57 +04:00
|
|
|
$dispatcher->registerMiddleware($c[$middleWare]);
|
2013-09-27 19:15:26 +04:00
|
|
|
}
|
|
|
|
|
2014-10-21 16:53:10 +04:00
|
|
|
$dispatcher->registerMiddleware($c['SessionMiddleware']);
|
2013-08-17 13:16:48 +04:00
|
|
|
return $dispatcher;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-21 03:02:15 +04:00
|
|
|
/**
|
2014-12-16 21:50:31 +03:00
|
|
|
* @deprecated implements only deprecated methods
|
2013-08-21 03:02:15 +04:00
|
|
|
* @return IApi
|
|
|
|
*/
|
|
|
|
function getCoreApi()
|
|
|
|
{
|
|
|
|
return $this->query('API');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-31 23:34:29 +04:00
|
|
|
* @return \OCP\IServerContainer
|
2013-08-21 03:02:15 +04:00
|
|
|
*/
|
|
|
|
function getServer()
|
|
|
|
{
|
2017-03-20 00:20:56 +03:00
|
|
|
return $this->server;
|
2013-08-21 03:02:15 +04:00
|
|
|
}
|
2013-09-25 12:30:48 +04:00
|
|
|
|
|
|
|
/**
|
2014-04-10 01:59:57 +04:00
|
|
|
* @param string $middleWare
|
2014-02-06 19:30:58 +04:00
|
|
|
* @return boolean|null
|
2013-09-25 12:30:48 +04:00
|
|
|
*/
|
2014-04-10 01:59:57 +04:00
|
|
|
function registerMiddleWare($middleWare) {
|
2013-09-27 19:15:26 +04:00
|
|
|
array_push($this->middleWares, $middleWare);
|
2013-09-25 12:30:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* used to return the appname of the set application
|
|
|
|
* @return string the name of your application
|
|
|
|
*/
|
|
|
|
function getAppName() {
|
|
|
|
return $this->query('AppName');
|
|
|
|
}
|
2013-10-07 02:33:54 +04:00
|
|
|
|
|
|
|
/**
|
2014-12-16 21:07:14 +03:00
|
|
|
* @deprecated use IUserSession->isLoggedIn()
|
2013-10-07 02:33:54 +04:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function isLoggedIn() {
|
2017-03-02 18:52:05 +03:00
|
|
|
return \OC::$server->getUserSession()->isLoggedIn();
|
2013-10-07 02:33:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-16 22:33:13 +03:00
|
|
|
* @deprecated use IGroupManager->isAdmin($userId)
|
2013-10-07 02:33:54 +04:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function isAdminUser() {
|
|
|
|
$uid = $this->getUserId();
|
|
|
|
return \OC_User::isAdminUser($uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getUserId() {
|
2015-01-22 17:33:09 +03:00
|
|
|
return $this->getServer()->getSession()->get('user_id');
|
2013-10-07 02:33:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-16 21:50:31 +03:00
|
|
|
* @deprecated use the ILogger instead
|
2014-05-12 00:51:30 +04:00
|
|
|
* @param string $message
|
|
|
|
* @param string $level
|
2013-10-07 02:33:54 +04:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function log($message, $level) {
|
|
|
|
switch($level){
|
|
|
|
case 'debug':
|
|
|
|
$level = \OCP\Util::DEBUG;
|
|
|
|
break;
|
|
|
|
case 'info':
|
|
|
|
$level = \OCP\Util::INFO;
|
|
|
|
break;
|
|
|
|
case 'warn':
|
|
|
|
$level = \OCP\Util::WARN;
|
|
|
|
break;
|
|
|
|
case 'fatal':
|
|
|
|
$level = \OCP\Util::FATAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$level = \OCP\Util::ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
\OCP\Util::writeLog($this->getAppName(), $message, $level);
|
|
|
|
}
|
2014-12-13 21:28:20 +03:00
|
|
|
|
2015-07-22 14:04:56 +03:00
|
|
|
/**
|
|
|
|
* Register a capability
|
|
|
|
*
|
|
|
|
* @param string $serviceName e.g. 'OCA\Files\Capabilities'
|
|
|
|
*/
|
|
|
|
public function registerCapability($serviceName) {
|
|
|
|
$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
|
|
|
|
return $this->query($serviceName);
|
|
|
|
});
|
2016-10-28 22:46:28 +03:00
|
|
|
}
|
2014-12-13 21:28:20 +03:00
|
|
|
|
2017-03-20 00:09:47 +03:00
|
|
|
public function query($name) {
|
2017-03-17 16:25:35 +03:00
|
|
|
$name = $this->sanitizeName($name);
|
2017-03-20 00:09:47 +03:00
|
|
|
|
2017-03-20 01:14:47 +03:00
|
|
|
if ($this->offsetExists($name)) {
|
2017-03-17 16:25:35 +03:00
|
|
|
return parent::query($name);
|
2017-03-20 01:14:47 +03:00
|
|
|
} else {
|
2017-03-20 00:09:47 +03:00
|
|
|
if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
|
|
|
|
$segments = explode('\\', $name);
|
|
|
|
if (strtolower($segments[1]) === strtolower($this['AppName'])) {
|
2017-03-20 01:14:47 +03:00
|
|
|
return parent::query($name);
|
2017-03-20 00:09:47 +03:00
|
|
|
}
|
2017-03-20 12:16:56 +03:00
|
|
|
} else if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
|
|
|
|
return parent::query($name);
|
2017-03-17 16:25:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getServer()->query($name);
|
2015-07-22 14:04:56 +03:00
|
|
|
}
|
2013-08-17 13:16:48 +04:00
|
|
|
}
|