diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-07-16 17:08:03 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-07-21 20:43:18 +0200 |
commit | 91e7f12088cb87ffef5660429ece404364167978 (patch) | |
tree | baf44ebc7b240bd49eb0f6bf615cbb1ed99d13db /apps | |
parent | e029055e766298c5852eedabf06ff42b06a50198 (diff) | |
download | nextcloud-server-91e7f12088cb87ffef5660429ece404364167978.tar.gz nextcloud-server-91e7f12088cb87ffef5660429ece404364167978.zip |
Adjust apps' code to use the ContainerInterface
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/admin_audit/lib/AppInfo/Application.php | 41 | ||||
-rw-r--r-- | apps/comments/lib/AppInfo/Application.php | 11 | ||||
-rw-r--r-- | apps/comments/lib/JSSettingsHelper.php | 8 | ||||
-rw-r--r-- | apps/comments/tests/Unit/JSSettingsHelperTest.php | 16 | ||||
-rw-r--r-- | apps/federatedfilesharing/lib/AppInfo/Application.php | 20 | ||||
-rw-r--r-- | apps/files/lib/AppInfo/Application.php | 34 | ||||
-rw-r--r-- | apps/lookup_server_connector/lib/AppInfo/Application.php | 19 | ||||
-rw-r--r-- | apps/settings/lib/AppInfo/Application.php | 55 | ||||
-rw-r--r-- | apps/systemtags/lib/AppInfo/Application.php | 56 | ||||
-rw-r--r-- | apps/twofactor_backupcodes/lib/AppInfo/Application.php | 5 | ||||
-rw-r--r-- | apps/updatenotification/lib/AppInfo/Application.php | 62 | ||||
-rw-r--r-- | apps/user_ldap/lib/AppInfo/Application.php | 70 | ||||
-rw-r--r-- | apps/workflowengine/lib/AppInfo/Application.php | 7 |
13 files changed, 215 insertions, 189 deletions
diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index 6c79aef84c8..81aeada2aaf 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -59,11 +59,12 @@ use OCP\IConfig; use OCP\IGroupManager; use OCP\ILogger; use OCP\IPreview; -use OCP\IServerContainer; use OCP\IUserSession; use OCP\Log\ILogFactory; use OCP\Share; use OCP\Util; +use Psr\Container\ContainerInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App implements IBootstrap { @@ -107,25 +108,25 @@ class Application extends App implements IBootstrap { * Register hooks in order to log them */ private function registerHooks(ILogger $logger, - IServerContainer $serverContainer) { - $this->userManagementHooks($logger, $serverContainer); - $this->groupHooks($logger, $serverContainer); + ContainerInterface $container) { + $this->userManagementHooks($logger, $container); + $this->groupHooks($logger, $container); $this->authHooks($logger); - $this->consoleHooks($logger, $serverContainer); - $this->appHooks($logger, $serverContainer); + $this->consoleHooks($logger, $container); + $this->appHooks($logger, $container); $this->sharingHooks($logger); - $this->fileHooks($logger, $serverContainer); + $this->fileHooks($logger, $container); $this->trashbinHooks($logger); $this->versionsHooks($logger); - $this->securityHooks($logger, $serverContainer); + $this->securityHooks($logger, $container); } private function userManagementHooks(ILogger $logger, - IServerContainer $serverContainer) { + ContainerInterface $container) { $userActions = new UserManagement($logger); Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); @@ -133,18 +134,18 @@ class Application extends App implements IBootstrap { Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); /** @var IUserSession|Session $userSession */ - $userSession = $serverContainer->getUserSession(); + $userSession = $container->get(IUserSession::class); $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']); $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); } private function groupHooks(ILogger $logger, - IServerContainer $serverContainer) { + ContainerInterface $container) { $groupActions = new GroupManagement($logger); /** @var IGroupManager|Manager $groupManager */ - $groupManager = $serverContainer->getGroupManager(); + $groupManager = $container->getGroupManager(IGroupManager::class); $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); @@ -172,8 +173,8 @@ class Application extends App implements IBootstrap { } private function appHooks(ILogger $logger, - IServerContainer $serverContainer) { - $eventDispatcher = $serverContainer->getEventDispatcher(); + ContainerInterface $container) { + $eventDispatcher = $container->get(EventDispatcherInterface::class); $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { $appActions = new AppManagement($logger); $appActions->enableApp($event->getAppID()); @@ -189,8 +190,8 @@ class Application extends App implements IBootstrap { } private function consoleHooks(ILogger $logger, - IServerContainer $serverContainer) { - $eventDispatcher = $serverContainer->getEventDispatcher(); + ContainerInterface $container) { + $eventDispatcher = $container->get(EventDispatcherInterface::class); $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { $appActions = new Console($logger); $appActions->runCommand($event->getArguments()); @@ -198,9 +199,9 @@ class Application extends App implements IBootstrap { } private function fileHooks(ILogger $logger, - IServerContainer $serverContainer) { + ContainerInterface $container) { $fileActions = new Files($logger); - $eventDispatcher = $serverContainer->getEventDispatcher(); + $eventDispatcher = $container->get(EventDispatcherInterface::class); $eventDispatcher->addListener( IPreview::EVENT, function (GenericEvent $event) use ($fileActions) { @@ -273,8 +274,8 @@ class Application extends App implements IBootstrap { } private function securityHooks(ILogger $logger, - IServerContainer $serverContainer) { - $eventDispatcher = $serverContainer->getEventDispatcher(); + ContainerInterface $container) { + $eventDispatcher = $container->get(EventDispatcherInterface::class); $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { $security = new Security($logger); $security->twofactorSuccess($event->getSubject(), $event->getArguments()); diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php index fafac0c6040..247ba034107 100644 --- a/apps/comments/lib/AppInfo/Application.php +++ b/apps/comments/lib/AppInfo/Application.php @@ -27,6 +27,7 @@ namespace OCA\Comments\AppInfo; +use Closure; use OCA\Comments\Capabilities; use OCA\Comments\Controller\Notifications; use OCA\Comments\EventHandler; @@ -44,6 +45,8 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Comments\CommentsEntityEvent; +use OCP\IConfig; +use OCP\ISearch; use OCP\IServerContainer; use OCP\Util; @@ -75,13 +78,13 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $this->registerNotifier($context->getServerContainer()); - $this->registerCommentsEventHandler($context->getServerContainer()); + $context->injectFn(Closure::fromCallable([$this, 'registerNotifier'])); + $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler'])); - $jsSettingsHelper = new JSSettingsHelper($context->getServerContainer()); + $jsSettingsHelper = new JSSettingsHelper($context->getAppContainer()->get(IConfig::class)); Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); - $context->getServerContainer()->getSearch()->registerProvider(LegacyProvider::class, ['apps' => ['files']]); + $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]); } protected function registerNotifier(IServerContainer $container) { diff --git a/apps/comments/lib/JSSettingsHelper.php b/apps/comments/lib/JSSettingsHelper.php index 4c54bb07c1c..93578e06295 100644 --- a/apps/comments/lib/JSSettingsHelper.php +++ b/apps/comments/lib/JSSettingsHelper.php @@ -23,20 +23,20 @@ namespace OCA\Comments; -use OCP\IServerContainer; +use OCP\IConfig; class JSSettingsHelper { - /** @var IServerContainer */ + /** @var IConfig */ private $c; - public function __construct(IServerContainer $c) { + public function __construct(IConfig $c) { $this->c = $c; } public function extend(array $settings) { $appConfig = json_decode($settings['array']['oc_appconfig'], true); - $value = (int)$this->c->getConfig()->getAppValue('comments', 'maxAutoCompleteResults', 10); + $value = (int)$this->c->getAppValue('comments', 'maxAutoCompleteResults', 10); $appConfig['comments']['maxAutoCompleteResults'] = $value; $settings['array']['oc_appconfig'] = json_encode($appConfig); diff --git a/apps/comments/tests/Unit/JSSettingsHelperTest.php b/apps/comments/tests/Unit/JSSettingsHelperTest.php index 26cdee1f26b..94d13a77d94 100644 --- a/apps/comments/tests/Unit/JSSettingsHelperTest.php +++ b/apps/comments/tests/Unit/JSSettingsHelperTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> * @@ -26,11 +29,11 @@ namespace OCA\Comments\Tests\Unit; use OCA\Comments\JSSettingsHelper; use OCP\IConfig; -use OCP\IServerContainer; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class JSSettingsHelperTest extends TestCase { - /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IConfig|MockObject */ protected $c; /** @var JSSettingsHelper */ protected $helper; @@ -38,22 +41,17 @@ class JSSettingsHelperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->c = $this->createMock(IServerContainer::class); + $this->c = $this->createMock(IConfig::class); $this->helper = new JSSettingsHelper($this->c); } public function testExtend() { - $config = $this->createMock(IConfig::class); - $config->expects($this->once()) + $this->c->expects($this->once()) ->method('getAppValue') ->with('comments', 'maxAutoCompleteResults') ->willReturn(13); - $this->c->expects($this->once()) - ->method('getConfig') - ->willReturn($config); - $config = [ 'oc_appconfig' => json_encode([ 'anotherapp' => [ diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index 09f881d5bb8..1afaa01a48f 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -28,6 +28,7 @@ namespace OCA\FederatedFileSharing\AppInfo; +use Closure; use OCA\FederatedFileSharing\Listeners\LoadAdditionalScriptsListener; use OCA\FederatedFileSharing\Notifier; use OCA\FederatedFileSharing\OCM\CloudFederationProviderFiles; @@ -36,6 +37,9 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\Federation\ICloudFederationProviderManager; +use OCP\Notification\IManager as INotifiactionManager; +use Psr\Container\ContainerInterface; class Application extends App implements IBootstrap { public function __construct() { @@ -47,16 +51,20 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $server = $context->getServerContainer(); + $context->injectFn(Closure::fromCallable([$this, 'registerCloudFederationProvider'])); + $context->injectFn(Closure::fromCallable([$this, 'registerNotificationManager'])); + } - $cloudFederationManager = $server->getCloudFederationProviderManager(); - $cloudFederationManager->addCloudFederationProvider('file', + private function registerCloudFederationProvider(ICloudFederationProviderManager $manager, + ContainerInterface $container): void { + $manager->addCloudFederationProvider('file', 'Federated Files Sharing', - function () use ($server) { - return $server->query(CloudFederationProviderFiles::class); + function () use ($container) { + return $container->get(CloudFederationProviderFiles::class); }); + } - $manager = $server->getNotificationManager(); + private function registerNotificationManager(INotifiactionManager $manager): void { $manager->registerNotifierService(Notifier::class); } } diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 9500f91fdf9..08ec9fbbcc4 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -34,6 +34,7 @@ declare(strict_types=1); namespace OCA\Files\AppInfo; +use Closure; use OC\Search\Provider\File; use OCA\Files\Capabilities; use OCA\Files\Collaboration\Resources\Listener; @@ -53,6 +54,7 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Collaboration\Resources\IProviderManager; use OCP\IContainer; use OCP\IL10N; +use OCP\ISearch; use OCP\IServerContainer; use OCP\Notification\IManager; use OCP\Util; @@ -112,35 +114,25 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $this->registerCollaboration($context); - Listener::register($context->getServerContainer()->getEventDispatcher()); - $this->registerNotification($context); - $this->registerSearchProvider($context); + $context->injectFn(Closure::fromCallable([$this, 'registerCollaboration'])); + $context->injectFn([Listener::class, 'register']); + $context->injectFn(Closure::fromCallable([$this, 'registerNotification'])); + $context->injectFn(Closure::fromCallable([$this, 'registerSearchProvider'])); $this->registerTemplates(); - $this->registerNavigation($context); + $context->injectFn(Closure::fromCallable([$this, 'registerNavigation'])); $this->registerHooks(); } - /** - * Register Collaboration ResourceProvider - */ - private function registerCollaboration(IBootContext $context): void { - /** @var IProviderManager $providerManager */ - $providerManager = $context->getAppContainer()->query(IProviderManager::class); + private function registerCollaboration(IProviderManager $providerManager): void { $providerManager->registerResourceProvider(ResourceProvider::class); } - private function registerNotification(IBootContext $context): void { - /** @var IManager $notifications */ - $notifications = $context->getAppContainer()->query(IManager::class); + private function registerNotification(IManager $notifications): void { $notifications->registerNotifierService(Notifier::class); } - /** - * @param IBootContext $context - */ - private function registerSearchProvider(IBootContext $context): void { - $context->getServerContainer()->getSearch()->registerProvider(File::class, ['apps' => ['files']]); + private function registerSearchProvider(ISearch $search): void { + $search->registerProvider(File::class, ['apps' => ['files']]); } private function registerTemplates(): void { @@ -150,9 +142,7 @@ class Application extends App implements IBootstrap { $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); } - private function registerNavigation(IBootContext $context): void { - /** @var IL10N $l10n */ - $l10n = $context->getAppContainer()->query(IL10N::class); + private function registerNavigation(IL10N $l10n): void { \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { return [ 'id' => 'files', diff --git a/apps/lookup_server_connector/lib/AppInfo/Application.php b/apps/lookup_server_connector/lib/AppInfo/Application.php index c2bb61000c1..df5ddcbab87 100644 --- a/apps/lookup_server_connector/lib/AppInfo/Application.php +++ b/apps/lookup_server_connector/lib/AppInfo/Application.php @@ -28,12 +28,15 @@ declare(strict_types=1); namespace OCA\LookupServerConnector\AppInfo; +use Closure; use OCA\LookupServerConnector\UpdateLookupServer; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IUser; +use Psr\Container\ContainerInterface; use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App implements IBootstrap { @@ -47,16 +50,20 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - /* - * @todo move the OCP events and then move the registration to `register` - */ - $dispatcher = $context->getServerContainer()->getEventDispatcher(); - $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($context) { + $context->injectFn(Closure::fromCallable([$this, 'registerEventListeners'])); + } + + /** + * @todo move the OCP events and then move the registration to `register` + */ + private function registerEventListeners(IEventDispatcher $dispatcher, + ContainerInterface $container): void { + $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) { /** @var IUser $user */ $user = $event->getSubject(); /** @var UpdateLookupServer $updateLookupServer */ - $updateLookupServer = $context->getServerContainer()->query(UpdateLookupServer::class); + $updateLookupServer = $container->get(UpdateLookupServer::class); $updateLookupServer->userUpdated($user); }); } diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index 73db869bc6a..3ea4d6bc080 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -40,6 +40,7 @@ use BadMethodCallException; use OC\AppFramework\Utility\TimeFactory; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; +use OC\Group\Manager; use OC\Server; use OCA\Settings\Activity\Provider; use OCA\Settings\Hooks; @@ -52,6 +53,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Defaults; use OCP\IGroup; +use OCP\IGroupManager; use OCP\ILogger; use OCP\IServerContainer; use OCP\IUser; @@ -134,38 +136,39 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - /** @var EventDispatcherInterface $eventDispatcher */ - $eventDispatcher = $context->getServerContainer()->getEventDispatcher(); - $container = $context->getAppContainer(); - $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { - if (($token = $event->getSubject()) instanceof IToken) { - /** @var IActivityManager $activityManager */ - $activityManager = $container->query(IActivityManager::class); - /** @var ILogger $logger */ - $logger = $container->query(ILogger::class); - - $activity = $activityManager->generateEvent(); - $activity->setApp('settings') - ->setType('security') - ->setAffectedUser($token->getUID()) - ->setAuthor($token->getUID()) - ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) - ->setObject('app_token', $token->getId()); - - try { - $activityManager->publish($activity); - } catch (BadMethodCallException $e) { - $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); + $context->injectFn(function (EventDispatcherInterface $dispatcher, ContainerInterface $container) { + $dispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { + if (($token = $event->getSubject()) instanceof IToken) { + /** @var IActivityManager $activityManager */ + $activityManager = $container->get(IActivityManager::class); + /** @var ILogger $logger */ + $logger = $container->get(ILogger::class); + + $activity = $activityManager->generateEvent(); + $activity->setApp('settings') + ->setType('security') + ->setAffectedUser($token->getUID()) + ->setAuthor($token->getUID()) + ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) + ->setObject('app_token', $token->getId()); + + try { + $activityManager->publish($activity); + } catch (BadMethodCallException $e) { + $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); + } } - } + }); }); Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); - $groupManager = $context->getServerContainer()->getGroupManager(); - $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); - $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); + $context->injectFn(function (IGroupManager $groupManager) { + /** @var IGroupManager|Manager $groupManager */ + $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); + $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); + }); Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); } diff --git a/apps/systemtags/lib/AppInfo/Application.php b/apps/systemtags/lib/AppInfo/Application.php index 45ac2dc1e84..ca18165680b 100644 --- a/apps/systemtags/lib/AppInfo/Application.php +++ b/apps/systemtags/lib/AppInfo/Application.php @@ -32,6 +32,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\SystemTag\ManagerEvent; use OCP\SystemTag\MapperEvent; +use Symfony\Component\EventDispatcher\EventDispatcher; class Application extends App implements IBootstrap { public const APP_ID = 'systemtags'; @@ -44,35 +45,36 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - /* - * @todo move the OCP events and then move the registration to `register` - */ - $eventDispatcher = $context->getServerContainer()->getEventDispatcher(); - $eventDispatcher->addListener( - 'OCA\Files::loadAdditionalScripts', - function () { - // FIXME: no public API for these ? - \OCP\Util::addScript('dist/systemtags'); - \OCP\Util::addScript(self::APP_ID, 'systemtags'); - } - ); + $context->injectFn(function (EventDispatcher $dispatcher) use ($context) { + /* + * @todo move the OCP events and then move the registration to `register` + */ + $dispatcher->addListener( + 'OCA\Files::loadAdditionalScripts', + function () { + // FIXME: no public API for these ? + \OCP\Util::addScript('dist/systemtags'); + \OCP\Util::addScript(self::APP_ID, 'systemtags'); + } + ); - $managerListener = function (ManagerEvent $event) use ($context) { - /** @var \OCA\SystemTags\Activity\Listener $listener */ - $listener = $context->getServerContainer()->query(Listener::class); - $listener->event($event); - }; - $eventDispatcher->addListener(ManagerEvent::EVENT_CREATE, $managerListener); - $eventDispatcher->addListener(ManagerEvent::EVENT_DELETE, $managerListener); - $eventDispatcher->addListener(ManagerEvent::EVENT_UPDATE, $managerListener); + $managerListener = function (ManagerEvent $event) use ($context) { + /** @var \OCA\SystemTags\Activity\Listener $listener */ + $listener = $context->getServerContainer()->query(Listener::class); + $listener->event($event); + }; + $dispatcher->addListener(ManagerEvent::EVENT_CREATE, $managerListener); + $dispatcher->addListener(ManagerEvent::EVENT_DELETE, $managerListener); + $dispatcher->addListener(ManagerEvent::EVENT_UPDATE, $managerListener); - $mapperListener = function (MapperEvent $event) use ($context) { - /** @var \OCA\SystemTags\Activity\Listener $listener */ - $listener = $context->getServerContainer()->query(Listener::class); - $listener->mapperEvent($event); - }; - $eventDispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener); - $eventDispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); + $mapperListener = function (MapperEvent $event) use ($context) { + /** @var \OCA\SystemTags\Activity\Listener $listener */ + $listener = $context->getServerContainer()->query(Listener::class); + $listener->mapperEvent($event); + }; + $dispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener); + $dispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); + }); \OCA\Files\App::getNavigationManager()->add(function () { $l = \OC::$server->getL10N(self::APP_ID); diff --git a/apps/twofactor_backupcodes/lib/AppInfo/Application.php b/apps/twofactor_backupcodes/lib/AppInfo/Application.php index 1941cb545ad..4ac5016f925 100644 --- a/apps/twofactor_backupcodes/lib/AppInfo/Application.php +++ b/apps/twofactor_backupcodes/lib/AppInfo/Application.php @@ -28,6 +28,7 @@ declare(strict_types=1); namespace OCA\TwoFactorBackupCodes\AppInfo; +use Closure; use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper; use OCA\TwoFactorBackupCodes\Event\CodesGenerated; use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher; @@ -58,9 +59,7 @@ class Application extends App implements IBootstrap { public function boot(IBootContext $context): void { Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser'); - $this->registerNotification( - $context->getAppContainer()->query(IManager::class) - ); + $context->injectFn(Closure::fromCallable([$this, 'registerNotification'])); } /** diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php index 12d5cd9e626..c369c957442 100644 --- a/apps/updatenotification/lib/AppInfo/Application.php +++ b/apps/updatenotification/lib/AppInfo/Application.php @@ -30,13 +30,20 @@ namespace OCA\UpdateNotification\AppInfo; use OCA\UpdateNotification\Notification\Notifier; use OCA\UpdateNotification\UpdateChecker; +use OCP\App\IAppManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\QueryException; +use OCP\IConfig; +use OCP\IGroupManager; +use OCP\ILogger; use OCP\IUser; +use OCP\IUserSession; +use OCP\Notification\IManager as INotificationManager; use OCP\Util; +use Psr\Container\ContainerInterface; class Application extends App implements IBootstrap { public function __construct() { @@ -47,36 +54,41 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $server = $context->getServerContainer(); - - if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) { - // Updater check is disabled - return; - } - - // Always register the notifier, so background jobs (without a user) can send push notifications - $notificationsManager = $server->getNotificationManager(); - $notificationsManager->registerNotifierService(Notifier::class); + $context->injectFn(function (IConfig $config, + INotificationManager $notificationsManager, + IUserSession $userSession, + IAppManager $appManager, + IGroupManager $groupManager, + ContainerInterface $container, + ILogger $logger) { + if ($config->getSystemValue('updatechecker', true) !== true) { + // Updater check is disabled + return; + } - $user = $server->getUserSession()->getUser(); - if (!$user instanceof IUser) { - // Nothing to do for guests - return; - } + // Always register the notifier, so background jobs (without a user) can send push notifications + $notificationsManager->registerNotifierService(Notifier::class); - if (!$server->getAppManager()->isEnabledForUser('notifications') && - $server->getGroupManager()->isAdmin($user->getUID())) { - try { - $updateChecker = $server->query(UpdateChecker::class); - } catch (QueryException $e) { - $server->getLogger()->logException($e); + $user = $userSession->getUser(); + if (!$user instanceof IUser) { + // Nothing to do for guests return; } - if ($updateChecker->getUpdateState() !== []) { - Util::addScript('updatenotification', 'legacy-notification'); - \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); + if (!$appManager->isEnabledForUser('notifications') && + $groupManager->isAdmin($user->getUID())) { + try { + $updateChecker = $container->get(UpdateChecker::class); + } catch (QueryException $e) { + $logger->logException($e); + return; + } + + if ($updateChecker->getUpdateState() !== []) { + Util::addScript('updatenotification', 'legacy-notification'); + \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); + } } - } + }); } } diff --git a/apps/user_ldap/lib/AppInfo/Application.php b/apps/user_ldap/lib/AppInfo/Application.php index a97b9c3fef9..fb501eedd79 100644 --- a/apps/user_ldap/lib/AppInfo/Application.php +++ b/apps/user_ldap/lib/AppInfo/Application.php @@ -26,6 +26,7 @@ namespace OCA\User_LDAP\AppInfo; +use Closure; use OCA\Files_External\Service\BackendService; use OCA\User_LDAP\Controller\RenewPasswordController; use OCA\User_LDAP\Group_Proxy; @@ -41,9 +42,14 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\IConfig; +use OCP\IGroupManager; use OCP\IL10N; use OCP\IServerContainer; +use OCP\IUserSession; +use OCP\Notification\IManager as INotificationManager; use Psr\Container\ContainerInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class Application extends App implements IBootstrap { public function __construct() { @@ -77,35 +83,37 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $server = $context->getServerContainer(); - $config = $server->getConfig(); - - $helper = new Helper($config); - $configPrefixes = $helper->getServerConfigurationPrefixes(true); - if (count($configPrefixes) > 0) { - $ldapWrapper = new LDAP(); - - $notificationManager = $server->getNotificationManager(); - $notificationManager->registerNotifierService(Notifier::class); - $userSession = $server->getUserSession(); - - $userPluginManager = $server->query(UserPluginManager::class); - $groupPluginManager = $server->query(GroupPluginManager::class); - - $userBackend = new User_Proxy( - $configPrefixes, $ldapWrapper, $config, $notificationManager, $userSession, $userPluginManager - ); - $groupBackend = new Group_Proxy($configPrefixes, $ldapWrapper, $groupPluginManager); - // register user backend - \OC_User::useBackend($userBackend); - - // Hook to allow plugins to work on registered backends - $server->getEventDispatcher()->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded'); - - $server->getGroupManager()->addBackend($groupBackend); + $context->injectFn(function (IConfig $config, + INotificationManager $notificationManager, + IUserSession $userSession, + ContainerInterface $container, + EventDispatcherInterface $dispatcher, + IGroupManager $groupManager) { + $helper = new Helper($config); + $configPrefixes = $helper->getServerConfigurationPrefixes(true); + if (count($configPrefixes) > 0) { + $ldapWrapper = new LDAP(); + + $notificationManager->registerNotifierService(Notifier::class); + + $userPluginManager = $container->get(UserPluginManager::class); + $groupPluginManager = $container->get(GroupPluginManager::class); + + $userBackend = new User_Proxy( + $configPrefixes, $ldapWrapper, $config, $notificationManager, $userSession, $userPluginManager + ); + $groupBackend = new Group_Proxy($configPrefixes, $ldapWrapper, $groupPluginManager); + // register user backend + \OC_User::useBackend($userBackend); + + // Hook to allow plugins to work on registered backends + $dispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded'); + + $groupManager->addBackend($groupBackend); + } + }); - $this->registerBackendDependents($context->getAppContainer()); - } + $context->injectFn(Closure::fromCallable([$this, 'registerBackendDependents'])); \OCP\Util::connectHook( '\OCA\Files_Sharing\API\Server2Server', @@ -115,10 +123,8 @@ class Application extends App implements IBootstrap { ); } - public function registerBackendDependents(ContainerInterface $appContainer) { - /** @var IServerContainer $serverContainer */ - $serverContainer = $appContainer->get(IServerContainer::class); - $serverContainer->getEventDispatcher()->addListener( + private function registerBackendDependents(ContainerInterface $appContainer, EventDispatcherInterface $dispatcher) { + $dispatcher->addListener( 'OCA\\Files_External::loadAdditionalBackends', function () use ($appContainer) { $storagesBackendService = $appContainer->get(BackendService::class); diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php index 2fd38c5f1ba..ddac4a74e28 100644 --- a/apps/workflowengine/lib/AppInfo/Application.php +++ b/apps/workflowengine/lib/AppInfo/Application.php @@ -21,6 +21,7 @@ namespace OCA\WorkflowEngine\AppInfo; +use Closure; use OCA\WorkflowEngine\Controller\RequestTime; use OCA\WorkflowEngine\Helper\LogContext; use OCA\WorkflowEngine\Listener\LoadAdditionalSettingsScriptsListener; @@ -57,11 +58,7 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $this->registerRuleListeners( - $context->getAppContainer()->query(IEventDispatcher::class), - $context->getServerContainer(), - $context->getAppContainer()->query(ILogger::class) - ); + $context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners'])); } private function registerRuleListeners(IEventDispatcher $dispatcher, |