diff options
Diffstat (limited to 'lib/private/Server.php')
-rw-r--r-- | lib/private/Server.php | 219 |
1 files changed, 170 insertions, 49 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php index dbec71457ef..c21ff650b24 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -42,9 +42,11 @@ namespace OC; use bantu\IniGetWrapper\IniGetWrapper; +use OC\App\AppManager; use OC\App\AppStore\Fetcher\AppFetcher; use OC\App\AppStore\Fetcher\CategoryFetcher; use OC\AppFramework\Http\Request; +use OC\AppFramework\Utility\SimpleContainer; use OC\AppFramework\Utility\TimeFactory; use OC\Authentication\LoginCredentials\Store; use OC\Command\AsyncBus; @@ -73,6 +75,7 @@ use OC\Lock\NoopLockingProvider; use OC\Lockdown\LockdownManager; use OC\Mail\Mailer; use OC\Memcache\ArrayCache; +use OC\Memcache\Factory; use OC\Notification\Manager; use OC\Repair\NC11\CleanPreviewsBackgroundJob; use OC\RichObjectStrings\Validator; @@ -91,10 +94,14 @@ use OC\Security\TrustedDomainHelper; use OC\Session\CryptoWrapper; use OC\Tagging\TagMapper; use OCA\Theming\ThemingDefaults; +use OCP\App\IAppManager; use OCP\Federation\ICloudIdManager; use OCP\Authentication\LoginCredentials\IStore; +use OCP\ICacheFactory; +use OCP\IDBConnection; use OCP\IL10N; use OCP\IServerContainer; +use OCP\ITempManager; use OCP\RichObjectStrings\IValidator; use OCP\Security\IContentSecurityPolicyManager; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -119,11 +126,10 @@ class Server extends ServerContainer implements IServerContainer { parent::__construct(); $this->webRoot = $webRoot; - $this->registerService('ContactsManager', function ($c) { - return new ContactsManager(); - }); + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); - $this->registerService('PreviewManager', function (Server $c) { + $this->registerService(\OCP\IPreview::class, function (Server $c) { return new PreviewManager( $c->getConfig(), $c->getRootFolder(), @@ -132,6 +138,7 @@ class Server extends ServerContainer implements IServerContainer { $c->getSession()->get('user_id') ); }); + $this->registerAlias('PreviewManager', \OCP\IPreview::class); $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { return new \OC\Preview\Watcher( @@ -181,10 +188,13 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService('TagMapper', function (Server $c) { return new TagMapper($c->getDatabaseConnection()); }); - $this->registerService('TagManager', function (Server $c) { + + $this->registerService(\OCP\ITagManager::class, function (Server $c) { $tagMapper = $c->query('TagMapper'); return new TagManager($tagMapper, $c->getUserSession()); }); + $this->registerAlias('TagManager', \OCP\ITagManager::class); + $this->registerService('SystemTagManagerFactory', function (Server $c) { $config = $c->getConfig(); $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); @@ -192,10 +202,12 @@ class Server extends ServerContainer implements IServerContainer { $factory = new $factoryClass($this); return $factory; }); - $this->registerService('SystemTagManager', function (Server $c) { + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { return $c->query('SystemTagManagerFactory')->getManager(); }); - $this->registerService('SystemTagObjectMapper', function (Server $c) { + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); + + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { return $c->query('SystemTagManagerFactory')->getObjectMapper(); }); $this->registerService('RootFolder', function (Server $c) { @@ -217,16 +229,22 @@ class Server extends ServerContainer implements IServerContainer { return $root; }); - $this->registerService('LazyRootFolder', function(Server $c) { + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); + + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { return new LazyRoot(function() use ($c) { return $c->query('RootFolder'); }); }); - $this->registerService('UserManager', function (Server $c) { + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); + + $this->registerService(\OCP\IUserManager::class, function (Server $c) { $config = $c->getConfig(); return new \OC\User\Manager($config); }); - $this->registerService('GroupManager', function (Server $c) { + $this->registerAlias('UserManager', \OCP\IUserManager::class); + + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); @@ -250,6 +268,8 @@ class Server extends ServerContainer implements IServerContainer { }); return $groupManager; }); + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); + $this->registerService(Store::class, function(Server $c) { $session = $c->getSession(); if (\OC::$server->getSystemConfig()->getValue('installed', false)) { @@ -274,7 +294,8 @@ class Server extends ServerContainer implements IServerContainer { return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); }); $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); - $this->registerService('UserSession', function (Server $c) { + + $this->registerService(\OCP\IUserSession::class, function (Server $c) { $manager = $c->getUserManager(); $session = new \OC\Session\Memory(''); $timeFactory = new TimeFactory(); @@ -326,30 +347,40 @@ class Server extends ServerContainer implements IServerContainer { }); return $userSession; }); + $this->registerAlias('UserSession', \OCP\IUserSession::class); $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); }); - $this->registerService('NavigationManager', function (Server $c) { + $this->registerService(\OCP\INavigationManager::class, function (Server $c) { return new \OC\NavigationManager($c->getAppManager(), $c->getURLGenerator(), $c->getL10NFactory(), $c->getUserSession(), $c->getGroupManager()); }); - $this->registerService('AllConfig', function (Server $c) { + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); + + $this->registerService(\OC\AllConfig::class, function (Server $c) { return new \OC\AllConfig( $c->getSystemConfig() ); }); + $this->registerAlias('AllConfig', \OC\AllConfig::class); + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); + $this->registerService('SystemConfig', function ($c) use ($config) { return new \OC\SystemConfig($config); }); - $this->registerService('AppConfig', function (Server $c) { + + $this->registerService(\OC\AppConfig::class, function (Server $c) { return new \OC\AppConfig($c->getDatabaseConnection()); }); - $this->registerService('L10NFactory', function (Server $c) { + $this->registerAlias('AppConfig', \OC\AppConfig::class); + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); + + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { return new \OC\L10N\Factory( $c->getConfig(), $c->getRequest(), @@ -357,7 +388,9 @@ class Server extends ServerContainer implements IServerContainer { \OC::$SERVERROOT ); }); - $this->registerService('URLGenerator', function (Server $c) { + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); + + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { $config = $c->getConfig(); $cacheFactory = $c->getMemCacheFactory(); return new \OC\URLGenerator( @@ -365,6 +398,8 @@ class Server extends ServerContainer implements IServerContainer { $cacheFactory ); }); + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); + $this->registerService('AppHelper', function ($c) { return new \OC\AppHelper(); }); @@ -384,10 +419,13 @@ class Server extends ServerContainer implements IServerContainer { $this->getConfig() ); }); - $this->registerService('UserCache', function ($c) { + + $this->registerService(\OCP\ICache::class, function ($c) { return new Cache\File(); }); - $this->registerService('MemCacheFactory', function (Server $c) { + $this->registerAlias('UserCache', \OCP\ICache::class); + + $this->registerService(Factory::class, function (Server $c) { $config = $c->getConfig(); if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { @@ -410,11 +448,15 @@ class Server extends ServerContainer implements IServerContainer { '\\OC\\Memcache\\ArrayCache' ); }); + $this->registerAlias('MemCacheFactory', Factory::class); + $this->registerAlias(ICacheFactory::class, Factory::class); + $this->registerService('RedisFactory', function (Server $c) { $systemConfig = $c->getSystemConfig(); return new RedisFactory($systemConfig); }); - $this->registerService('ActivityManager', function (Server $c) { + + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { return new \OC\Activity\Manager( $c->getRequest(), $c->getUserSession(), @@ -422,13 +464,16 @@ class Server extends ServerContainer implements IServerContainer { $c->query(IValidator::class) ); }); + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { return new \OC\Activity\EventMerger( $c->getL10N('lib') ); }); $this->registerAlias(IValidator::class, Validator::class); - $this->registerService('AvatarManager', function (Server $c) { + + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { return new AvatarManager( $c->getUserManager(), $c->getAppDataDir('avatar'), @@ -437,14 +482,18 @@ class Server extends ServerContainer implements IServerContainer { $c->getConfig() ); }); - $this->registerService('Logger', function (Server $c) { + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); + + $this->registerService(\OCP\ILogger::class, function (Server $c) { $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); $logger = Log::getLogClass($logType); call_user_func(array($logger, 'init')); return new Log($logger); }); - $this->registerService('JobList', function (Server $c) { + $this->registerAlias('Logger', \OCP\ILogger::class); + + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { $config = $c->getConfig(); return new \OC\BackgroundJob\JobList( $c->getDatabaseConnection(), @@ -452,7 +501,9 @@ class Server extends ServerContainer implements IServerContainer { new TimeFactory() ); }); - $this->registerService('Router', function (Server $c) { + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); + + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { $cacheFactory = $c->getMemCacheFactory(); $logger = $c->getLogger(); if ($cacheFactory->isAvailable()) { @@ -462,22 +513,34 @@ class Server extends ServerContainer implements IServerContainer { } return $router; }); - $this->registerService('Search', function ($c) { + $this->registerAlias('Router', \OCP\Route\IRouter::class); + + $this->registerService(\OCP\ISearch::class, function ($c) { return new Search(); }); - $this->registerService('SecureRandom', function ($c) { + $this->registerAlias('Search', \OCP\ISearch::class); + + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { return new SecureRandom(); }); - $this->registerService('Crypto', function (Server $c) { + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); + + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { return new Crypto($c->getConfig(), $c->getSecureRandom()); }); - $this->registerService('Hasher', function (Server $c) { + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); + + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { return new Hasher($c->getConfig()); }); - $this->registerService('CredentialsManager', function (Server $c) { + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); + + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); }); - $this->registerService('DatabaseConnection', function (Server $c) { + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); + + $this->registerService(IDBConnection::class, function (Server $c) { $systemConfig = $c->getSystemConfig(); $factory = new \OC\DB\ConnectionFactory($systemConfig); $type = $systemConfig->getValue('dbtype', 'sqlite'); @@ -489,6 +552,8 @@ class Server extends ServerContainer implements IServerContainer { $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); return $connection; }); + $this->registerAlias('DatabaseConnection', IDBConnection::class); + $this->registerService('HTTPHelper', function (Server $c) { $config = $c->getConfig(); return new HTTPHelper( @@ -496,7 +561,8 @@ class Server extends ServerContainer implements IServerContainer { $c->getHTTPClientService() ); }); - $this->registerService('HttpClientService', function (Server $c) { + + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { $user = \OC_User::getUser(); $uid = $user ? $user : null; return new ClientService( @@ -504,27 +570,36 @@ class Server extends ServerContainer implements IServerContainer { new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) ); }); - $this->registerService('EventLogger', function (Server $c) { + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); + + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { if ($c->getSystemConfig()->getValue('debug', false)) { return new EventLogger(); } else { return new NullEventLogger(); } }); - $this->registerService('QueryLogger', function (Server $c) { + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); + + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { if ($c->getSystemConfig()->getValue('debug', false)) { return new QueryLogger(); } else { return new NullQueryLogger(); } }); - $this->registerService('TempManager', function (Server $c) { + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); + + $this->registerService(TempManager::class, function (Server $c) { return new TempManager( $c->getLogger(), $c->getConfig() ); }); - $this->registerService('AppManager', function (Server $c) { + $this->registerAlias('TempManager', TempManager::class); + $this->registerAlias(ITempManager::class, TempManager::class); + + $this->registerService(AppManager::class, function (Server $c) { return new \OC\App\AppManager( $c->getUserSession(), $c->getAppConfig(), @@ -533,13 +608,18 @@ class Server extends ServerContainer implements IServerContainer { $c->getEventDispatcher() ); }); - $this->registerService('DateTimeZone', function (Server $c) { + $this->registerAlias('AppManager', AppManager::class); + $this->registerAlias(IAppManager::class, AppManager::class); + + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { return new DateTimeZone( $c->getConfig(), $c->getSession() ); }); - $this->registerService('DateTimeFormatter', function (Server $c) { + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); + + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); return new DateTimeFormatter( @@ -547,13 +627,17 @@ class Server extends ServerContainer implements IServerContainer { $c->getL10N('lib', $language) ); }); - $this->registerService('UserMountCache', function (Server $c) { + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); + + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); $listener = new UserMountCacheListener($mountCache); $listener->listen($c->getUserManager()); return $mountCache; }); - $this->registerService('MountConfigManager', function (Server $c) { + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); + + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { $loader = \OC\Files\Filesystem::getLoader(); $mountCache = $c->query('UserMountCache'); $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); @@ -567,6 +651,8 @@ class Server extends ServerContainer implements IServerContainer { return $manager; }); + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); + $this->registerService('IniWrapper', function ($c) { return new IniGetWrapper(); }); @@ -606,7 +692,7 @@ class Server extends ServerContainer implements IServerContainer { $c->getTempManager() ); }); - $this->registerService('Request', function ($c) { + $this->registerService(\OCP\IRequest::class, function ($c) { if (isset($this['urlParams'])) { $urlParams = $this['urlParams']; } else { @@ -640,13 +726,17 @@ class Server extends ServerContainer implements IServerContainer { $stream ); }); - $this->registerService('Mailer', function (Server $c) { + $this->registerAlias('Request', \OCP\IRequest::class); + + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { return new Mailer( $c->getConfig(), $c->getLogger(), $c->getThemingDefaults() ); }); + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); + $this->registerService('LDAPProvider', function(Server $c) { $config = $c->getConfig(); $factoryClass = $config->getSystemValue('ldapProviderFactory', null); @@ -672,40 +762,53 @@ class Server extends ServerContainer implements IServerContainer { } return new NoopLockingProvider(); }); - $this->registerService('MountManager', function () { + + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { return new \OC\Files\Mount\Manager(); }); - $this->registerService('MimeTypeDetector', function (Server $c) { + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); + + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { return new \OC\Files\Type\Detection( $c->getURLGenerator(), \OC::$configDir, \OC::$SERVERROOT . '/resources/config/' ); }); - $this->registerService('MimeTypeLoader', function (Server $c) { + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); + + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { return new \OC\Files\Type\Loader( $c->getDatabaseConnection() ); }); - $this->registerService('NotificationManager', function (Server $c) { + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); + + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { return new Manager( $c->query(IValidator::class) ); }); - $this->registerService('CapabilitiesManager', function (Server $c) { + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); + + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { $manager = new \OC\CapabilitiesManager($c->getLogger()); $manager->registerCapability(function () use ($c) { return new \OC\OCS\CoreCapabilities($c->getConfig()); }); return $manager; }); - $this->registerService('CommentsManager', function(Server $c) { + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); + + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { $config = $c->getConfig(); $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); /** @var \OCP\Comments\ICommentsManagerFactory $factory */ $factory = new $factoryClass($this); return $factory->getManager(); }); + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); + $this->registerService('ThemingDefaults', function(Server $c) { /* * Dark magic for autoloader. @@ -732,9 +835,12 @@ class Server extends ServerContainer implements IServerContainer { } return new \OC_Defaults(); }); - $this->registerService('EventDispatcher', function () { + $this->registerService(EventDispatcher::class, function () { return new EventDispatcher(); }); + $this->registerAlias('EventDispatcher', EventDispatcher::class); + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); + $this->registerService('CryptoWrapper', function (Server $c) { // FIXME: Instantiiated here due to cyclic dependency $request = new Request( @@ -771,16 +877,19 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService(SessionStorage::class, function (Server $c) { return new SessionStorage($c->getSession()); }); - $this->registerService('ContentSecurityPolicyManager', function (Server $c) { + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { return new ContentSecurityPolicyManager(); }); + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { return new ContentSecurityPolicyNonceManager( $c->getCsrfTokenManager(), $c->getRequest() ); }); - $this->registerService('ShareManager', function(Server $c) { + + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { $config = $c->getConfig(); $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); /** @var \OCP\Share\IProviderFactory $factory */ @@ -802,6 +911,8 @@ class Server extends ServerContainer implements IServerContainer { return $manager; }); + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); + $this->registerService('SettingsManager', function(Server $c) { $manager = new \OC\Settings\Manager( $c->getLogger(), @@ -841,6 +952,16 @@ class Server extends ServerContainer implements IServerContainer { new TimeFactory() ); }); + + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); + + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); + + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { + return $c->query(\OCP\IUserSession::class)->getSession(); + }); } /** |