summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2018-09-26 16:46:35 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2018-09-27 09:44:21 +0200
commit0259792614e3ed2dd743c2c292d8d90e2b0a05aa (patch)
tree027a4bd7c17368b9ac6110fc8f03bef8131b85dc /lib/private
parentcd05670517da0cecfa8c6277c015fa33fae3394d (diff)
downloadnextcloud-server-0259792614e3ed2dd743c2c292d8d90e2b0a05aa.tar.gz
nextcloud-server-0259792614e3ed2dd743c2c292d8d90e2b0a05aa.zip
Reduce settings manager complexity by loading sections via DI
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Server.php10
-rw-r--r--lib/private/Settings/Manager.php112
2 files changed, 31 insertions, 91 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 5962012604a..533c2c2233f 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1083,16 +1083,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getLogger(),
$c->getDatabaseConnection(),
$c->getL10N('lib'),
- $c->getConfig(),
- $c->getEncryptionManager(),
- $c->getUserManager(),
- $c->getLockingProvider(),
- $c->getRequest(),
$c->getURLGenerator(),
- $c->query(AccountManager::class),
- $c->getGroupManager(),
- $c->getL10NFactory(),
- $c->getAppManager()
+ $c
);
return $manager;
});
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php
index f1baf35b7ab..e3cbc1b672f 100644
--- a/lib/private/Settings/Manager.php
+++ b/lib/private/Settings/Manager.php
@@ -29,96 +29,45 @@
namespace OC\Settings;
-use OC\Accounts\AccountManager;
-use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
-use OCP\Encryption\IManager as EncryptionManager;
-use OCP\IConfig;
use OCP\IDBConnection;
-use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
-use OCP\IRequest;
+use OCP\IServerContainer;
use OCP\IURLGenerator;
-use OCP\IUserManager;
-use OCP\L10N\IFactory;
-use OCP\Lock\ILockingProvider;
use OCP\Settings\ISettings;
use OCP\Settings\IManager;
use OCP\Settings\ISection;
-use OCP\Util;
class Manager implements IManager {
+
/** @var ILogger */
private $log;
+
/** @var IDBConnection */
private $dbc;
+
/** @var IL10N */
private $l;
- /** @var IConfig */
- private $config;
- /** @var EncryptionManager */
- private $encryptionManager;
- /** @var IUserManager */
- private $userManager;
- /** @var ILockingProvider */
- private $lockingProvider;
- /** @var IRequest */
- private $request;
+
/** @var IURLGenerator */
private $url;
- /** @var AccountManager */
- private $accountManager;
- /** @var IGroupManager */
- private $groupManager;
- /** @var IFactory */
- private $l10nFactory;
- /** @var IAppManager */
- private $appManager;
- /**
- * @param ILogger $log
- * @param IDBConnection $dbc
- * @param IL10N $l
- * @param IConfig $config
- * @param EncryptionManager $encryptionManager
- * @param IUserManager $userManager
- * @param ILockingProvider $lockingProvider
- * @param IRequest $request
- * @param IURLGenerator $url
- * @param AccountManager $accountManager
- * @param IGroupManager $groupManager
- * @param IFactory $l10nFactory
- * @param IAppManager $appManager
- */
+ /** @var IServerContainer */
+ private $container;
+
public function __construct(
ILogger $log,
IDBConnection $dbc,
- IL10N $l,
- IConfig $config,
- EncryptionManager $encryptionManager,
- IUserManager $userManager,
- ILockingProvider $lockingProvider,
- IRequest $request,
+ IL10N $l10n,
IURLGenerator $url,
- AccountManager $accountManager,
- IGroupManager $groupManager,
- IFactory $l10nFactory,
- IAppManager $appManager
+ IServerContainer $container
) {
$this->log = $log;
$this->dbc = $dbc;
- $this->l = $l;
- $this->config = $config;
- $this->encryptionManager = $encryptionManager;
- $this->userManager = $userManager;
- $this->lockingProvider = $lockingProvider;
- $this->request = $request;
+ $this->l = $l10n;
$this->url = $url;
- $this->accountManager = $accountManager;
- $this->groupManager = $groupManager;
- $this->l10nFactory = $l10nFactory;
- $this->appManager = $appManager;
+ $this->container = $container;
}
/** @var array */
@@ -130,6 +79,7 @@ class Manager implements IManager {
/**
* @param string $type 'admin' or 'personal'
* @param string $section Class must implement OCP\Settings\ISection
+ *
* @return void
*/
public function registerSection(string $type, string $section) {
@@ -142,6 +92,7 @@ class Manager implements IManager {
/**
* @param string $type 'admin' or 'personal'
+ *
* @return ISection[]
*/
protected function getSections(string $type): array {
@@ -191,6 +142,7 @@ class Manager implements IManager {
/**
* @param string $type 'admin' or 'personal'
* @param string $setting Class must implement OCP\Settings\ISetting
+ *
* @return void
*/
public function registerSetting(string $type, string $setting) {
@@ -200,6 +152,7 @@ class Manager implements IManager {
/**
* @param string $type 'admin' or 'personal'
* @param string $section
+ *
* @return ISettings[]
*/
protected function getSettings(string $type, string $section): array {
@@ -267,6 +220,7 @@ class Manager implements IManager {
/**
* @param string $section
+ *
* @return ISection[]
*/
private function getBuiltInAdminSettings($section): array {
@@ -274,24 +228,24 @@ class Manager implements IManager {
if ($section === 'overview') {
/** @var ISettings $form */
- $form = new Admin\Overview($this->config);
+ $form = $this->container->query(Admin\Overview::class);
$forms[$form->getPriority()] = [$form];
}
if ($section === 'server') {
/** @var ISettings $form */
- $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
+ $form = $this->container->query(Admin\Server::class);
$forms[$form->getPriority()] = [$form];
- $form = new Admin\Mail($this->config);
+ $form = $this->container->query(Admin\Mail::class);
$forms[$form->getPriority()] = [$form];
}
if ($section === 'security') {
/** @var ISettings $form */
- $form = new Admin\Encryption($this->encryptionManager, $this->userManager);
+ $form = $this->container->query(Admin\Encryption::class);
$forms[$form->getPriority()] = [$form];
}
if ($section === 'sharing') {
/** @var ISettings $form */
- $form = new Admin\Sharing($this->config, $this->l);
+ $form = $this->container->query(Admin\Sharing::class);
$forms[$form->getPriority()] = [$form];
}
@@ -300,6 +254,7 @@ class Manager implements IManager {
/**
* @param string $section
+ *
* @return ISection[]
*/
private function getBuiltInPersonalSettings($section): array {
@@ -307,27 +262,19 @@ class Manager implements IManager {
if ($section === 'personal-info') {
/** @var ISettings $form */
- $form = new Personal\PersonalInfo(
- $this->config,
- $this->userManager,
- $this->groupManager,
- $this->accountManager,
- $this->appManager,
- $this->l10nFactory,
- $this->l
- );
+ $form = $this->container->query(Personal\PersonalInfo::class);
$forms[$form->getPriority()] = [$form];
$form = new Personal\ServerDevNotice();
$forms[$form->getPriority()] = [$form];
}
- if($section === 'security') {
+ if ($section === 'security') {
/** @var ISettings $form */
- $form = new Personal\Security($this->userManager);
+ $form = $this->container->query(Personal\Security::class);
$forms[$form->getPriority()] = [$form];
}
if ($section === 'additional') {
/** @var ISettings $form */
- $form = new Personal\Additional();
+ $form = $this->container->query(Personal\Additional::class);
$forms[$form->getPriority()] = [$form];
}
@@ -363,7 +310,7 @@ class Manager implements IManager {
];
$legacyForms = \OC_App::getForms('personal');
- if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
+ if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
}
@@ -385,11 +332,12 @@ class Manager implements IManager {
/**
* @param string[] $forms
+ *
* @return bool
*/
private function hasLegacyPersonalSettingsToRender(array $forms): bool {
foreach ($forms as $form) {
- if(trim($form) !== '') {
+ if (trim($form) !== '') {
return true;
}
}