Skip to content

Commit

Permalink
Move a lot of stuff over to the ServerContainer
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Mar 21, 2017
1 parent 0fb5776 commit 48c3452
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 246 deletions.
224 changes: 20 additions & 204 deletions lib/private/AppFramework/DependencyInjection/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@
use OC\Core\Middleware\TwoFactorMiddleware;
use OC\RichObjectStrings\Validator;
use OC\ServerContainer;
use OCP\AppFramework\Http\IOutput;
use OCP\AppFramework\IApi;
use OCP\AppFramework\IAppContainer;
use OCP\AppFramework\QueryException;
use OCP\Federation\ICloudIdManager;
use OCP\Files\Folder;
use OCP\Files\IAppData;
use OCP\Files\Mount\IMountManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IServerContainer;
use OCP\IUserSession;
use OCP\RichObjectStrings\IValidator;
use OCP\Util;

Expand Down Expand Up @@ -92,233 +94,47 @@ public function __construct($appName, $urlParams = array(), ServerContainer $ser
/**
* Core services
*/
$this->registerService('OCP\\AppFramework\\Http\\IOutput', function($c){
$this->registerService(IOutput::class, function($c){
return new Output($this->getServer()->getWebRoot());
});

$this->registerService(\OCP\Authentication\LoginCredentials\IStore::class, function() {
return $this->getServer()->query(\OCP\Authentication\LoginCredentials\IStore::class);
});

$this->registerService('OCP\\IAvatarManager', function($c) {
return $this->getServer()->getAvatarManager();
});

$this->registerService('OCP\\Activity\\IManager', function($c) {
return $this->getServer()->getActivityManager();
});
$this->registerService(\OCP\Activity\IEventMerger::class, function($c) {
return $this->getServer()->query(\OCP\Activity\IEventMerger::class);
});

$this->registerService('OCP\\ICache', function($c) {
return $this->getServer()->getCache();
});

$this->registerService('OC\\CapabilitiesManager', function($c) {
return $this->getServer()->getCapabilitiesManager();
});

$this->registerService('OCP\Comments\ICommentsManager', function($c) {
return $this->getServer()->getCommentsManager();
});

$this->registerService('OCP\\Contacts\\IManager', function($c) {
return $this->getServer()->getContactsManager();
});

$this->registerService('OCP\\IDateTimeZone', function($c) {
return $this->getServer()->getDateTimeZone();
});

$this->registerService('OCP\\IDateTimeFormatter', function($c) {
return $this->getServer()->getDateTimeFormatter();
});

$this->registerService('OCP\\IDBConnection', function($c) {
return $this->getServer()->getDatabaseConnection();
});

$this->registerService('OCP\\Diagnostics\\IEventLogger', function($c) {
return $this->getServer()->getEventLogger();
});

$this->registerService('OCP\\Diagnostics\\IQueryLogger', function($c) {
return $this->getServer()->getQueryLogger();
});

$this->registerService(ICloudIdManager::class, function($c) {
return $this->getServer()->getCloudIdManager();
});

$this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) {
return $this->getServer()->getMimeTypeDetector();
});

$this->registerService('OCP\\Files\\Config\\IMountProviderCollection', function($c) {
return $this->getServer()->getMountProviderCollection();
});

$this->registerService('OCP\\Files\\Config\\IUserMountCache', function($c) {
return $this->getServer()->getUserMountCache();
});

$this->registerService('OCP\\Files\\IRootFolder', function($c) {
return $this->getServer()->getRootFolder();
});

$this->registerService('OCP\\Files\\Folder', function() {
$this->registerService(Folder::class, function() {
return $this->getServer()->getUserFolder();
});

$this->registerService('OCP\\Http\\Client\\IClientService', function($c) {
return $this->getServer()->getHTTPClientService();
});

$this->registerService(IAppData::class, function (SimpleContainer $c) {
return $this->getServer()->getAppDataDir($c->query('AppName'));
});

$this->registerService('OCP\\IGroupManager', function($c) {
return $this->getServer()->getGroupManager();
});

$this->registerService('OCP\\Http\\Client\\IClientService', function() {
return $this->getServer()->getHTTPClientService();
});

$this->registerService('OCP\\IL10N', function($c) {
$this->registerService(IL10N::class, function($c) {
return $this->getServer()->getL10N($c->query('AppName'));
});

$this->registerService('OCP\\L10N\\IFactory', function($c) {
return $this->getServer()->getL10NFactory();
});

$this->registerService('OCP\\ILogger', function($c) {
return $this->getServer()->getLogger();
});

$this->registerService('OCP\\BackgroundJob\\IJobList', function($c) {
return $this->getServer()->getJobList();
});

$this->registerAlias('OCP\\AppFramework\\Utility\\IControllerMethodReflector', 'OC\AppFramework\Utility\ControllerMethodReflector');
$this->registerAlias('ControllerMethodReflector', 'OCP\\AppFramework\\Utility\\IControllerMethodReflector');

$this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) {
return $this->getServer()->getMimeTypeDetector();
});

$this->registerService('OCP\\Mail\\IMailer', function() {
return $this->getServer()->getMailer();
});

$this->registerService('OCP\\INavigationManager', function($c) {
return $this->getServer()->getNavigationManager();
});

$this->registerService('OCP\\Notification\IManager', function($c) {
return $this->getServer()->getNotificationManager();
});

$this->registerService('OCP\\IPreview', function($c) {
return $this->getServer()->getPreviewManager();
});

$this->registerService('OCP\\IRequest', function () {
return $this->getServer()->getRequest();
});
$this->registerAlias('Request', 'OCP\\IRequest');

$this->registerService('OCP\\ITagManager', function($c) {
return $this->getServer()->getTagManager();
});

$this->registerAlias('OCP\\AppFramework\\Utility\\ITimeFactory', 'OC\AppFramework\Utility\TimeFactory');
$this->registerAlias('TimeFactory', 'OCP\\AppFramework\\Utility\\ITimeFactory');


$this->registerService('OCP\\Route\\IRouter', function($c) {
return $this->getServer()->getRouter();
});

$this->registerService('OCP\\ISearch', function($c) {
return $this->getServer()->getSearch();
});

$this->registerService('OCP\\ISearch', function($c) {
return $this->getServer()->getSearch();
});

$this->registerService('OCP\\Security\\ICrypto', function($c) {
return $this->getServer()->getCrypto();
});

$this->registerService('OCP\\Security\\IHasher', function($c) {
return $this->getServer()->getHasher();
});

$this->registerService('OCP\\Security\\ICredentialsManager', function($c) {
return $this->getServer()->getCredentialsManager();
});

$this->registerService('OCP\\Security\\ISecureRandom', function($c) {
return $this->getServer()->getSecureRandom();
});

$this->registerService('OCP\\Share\\IManager', function($c) {
return $this->getServer()->getShareManager();
});
$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);

$this->registerService('OCP\\SystemTag\\ISystemTagManager', function() {
return $this->getServer()->getSystemTagManager();
$this->registerService(IRequest::class, function() {
return $this->getServer()->query(IRequest::class);
});
$this->registerAlias('Request', IRequest::class);

$this->registerService('OCP\\SystemTag\\ISystemTagObjectMapper', function() {
return $this->getServer()->getSystemTagObjectMapper();
});
$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);

$this->registerService('OCP\\IURLGenerator', function($c) {
return $this->getServer()->getURLGenerator();
});

$this->registerService('OCP\\IUserManager', function($c) {
return $this->getServer()->getUserManager();
});

$this->registerService('OCP\\IUserSession', function($c) {
return $this->getServer()->getUserSession();
});
$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);

$this->registerService('OCP\\ISession', function($c) {
return $this->getServer()->getSession();
});

$this->registerService('OCP\\Security\\IContentSecurityPolicyManager', function($c) {
return $this->getServer()->getContentSecurityPolicyManager();
});

$this->registerService('ServerContainer', function ($c) {
$this->registerService(IServerContainer::class, function ($c) {
return $this->getServer();
});
$this->registerAlias('OCP\\IServerContainer', 'ServerContainer');
$this->registerAlias('ServerContainer', IServerContainer::class);

$this->registerService('Symfony\Component\EventDispatcher\EventDispatcherInterface', function ($c) {
return $this->getServer()->getEventDispatcher();
});

$this->registerService('OCP\WorkflowEngine\IManager', function ($c) {
$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
return $c->query('OCA\WorkflowEngine\Manager');
});

$this->registerService('OCP\\AppFramework\\IAppContainer', function ($c) {
$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
return $c;
});
$this->registerService(IMountManager::class, function () {
return $this->getServer()->getMountManager();
});

// commonly used attributes
$this->registerService('UserId', function ($c) {
Expand Down Expand Up @@ -417,7 +233,7 @@ public function __construct($appName, $urlParams = array(), ServerContainer $ser
return new CORSMiddleware(
$c['Request'],
$c['ControllerMethodReflector'],
$c['OCP\IUserSession'],
$c->query(IUserSession::class),
$c->getServer()->getBruteForceThrottler()
);
});
Expand Down
Loading

0 comments on commit 48c3452

Please sign in to comment.