Passed
Push — master ( 5d4c4b...c43189 )
by Roeland
12:22 queued 10s
created
lib/private/Settings/Manager.php 2 patches
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -45,271 +45,271 @@
 block discarded – undo
45 45
 
46 46
 class Manager implements IManager {
47 47
 
48
-	/** @var ILogger */
49
-	private $log;
50
-
51
-	/** @var IL10N */
52
-	private $l;
53
-
54
-	/** @var IFactory */
55
-	private $l10nFactory;
56
-
57
-	/** @var IURLGenerator */
58
-	private $url;
59
-
60
-	/** @var IServerContainer */
61
-	private $container;
62
-
63
-	public function __construct(
64
-		ILogger $log,
65
-		IFactory $l10nFactory,
66
-		IURLGenerator $url,
67
-		IServerContainer $container
68
-	) {
69
-		$this->log = $log;
70
-		$this->l10nFactory = $l10nFactory;
71
-		$this->url = $url;
72
-		$this->container = $container;
73
-	}
74
-
75
-	/** @var array */
76
-	protected $sectionClasses = [];
77
-
78
-	/** @var array */
79
-	protected $sections = [];
80
-
81
-	/**
82
-	 * @param string $type 'admin' or 'personal'
83
-	 * @param string $section Class must implement OCP\Settings\ISection
84
-	 *
85
-	 * @return void
86
-	 */
87
-	public function registerSection(string $type, string $section) {
88
-		if (!isset($this->sectionClasses[$type])) {
89
-			$this->sectionClasses[$type] = [];
90
-		}
91
-
92
-		$this->sectionClasses[$type][] = $section;
93
-	}
94
-
95
-	/**
96
-	 * @param string $type 'admin' or 'personal'
97
-	 *
98
-	 * @return ISection[]
99
-	 */
100
-	protected function getSections(string $type): array {
101
-		if (!isset($this->sections[$type])) {
102
-			$this->sections[$type] = [];
103
-		}
104
-
105
-		if (!isset($this->sectionClasses[$type])) {
106
-			return $this->sections[$type];
107
-		}
108
-
109
-		foreach (array_unique($this->sectionClasses[$type]) as $index => $class) {
110
-			try {
111
-				/** @var ISection $section */
112
-				$section = \OC::$server->query($class);
113
-			} catch (QueryException $e) {
114
-				$this->log->logException($e, ['level' => ILogger::INFO]);
115
-				continue;
116
-			}
117
-
118
-			if (!$section instanceof ISection) {
119
-				$this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]);
120
-				continue;
121
-			}
122
-
123
-			$sectionID = $section->getID();
124
-
125
-			if (isset($this->sections[$type][$sectionID])) {
126
-				$this->log->logException(new \InvalidArgumentException('Section with the same ID already registered: ' . $sectionID . ', class: ' . $class), ['level' => ILogger::INFO]);
127
-				continue;
128
-			}
129
-
130
-			$this->sections[$type][$sectionID] = $section;
131
-
132
-			unset($this->sectionClasses[$type][$index]);
133
-		}
134
-
135
-		return $this->sections[$type];
136
-	}
137
-
138
-	/** @var array */
139
-	protected $settingClasses = [];
140
-
141
-	/** @var array */
142
-	protected $settings = [];
143
-
144
-	/**
145
-	 * @param string $type 'admin' or 'personal'
146
-	 * @param string $setting Class must implement OCP\Settings\ISetting
147
-	 *
148
-	 * @return void
149
-	 */
150
-	public function registerSetting(string $type, string $setting) {
151
-		$this->settingClasses[$setting] = $type;
152
-	}
153
-
154
-	/**
155
-	 * @param string $type 'admin' or 'personal'
156
-	 * @param string $section
157
-	 * @param Closure $filter optional filter to apply on all loaded ISettings
158
-	 *
159
-	 * @return ISettings[]
160
-	 */
161
-	protected function getSettings(string $type, string $section, Closure $filter = null): array {
162
-		if (!isset($this->settings[$type])) {
163
-			$this->settings[$type] = [];
164
-		}
165
-		if (!isset($this->settings[$type][$section])) {
166
-			$this->settings[$type][$section] = [];
167
-		}
168
-
169
-		foreach ($this->settingClasses as $class => $settingsType) {
170
-			if ($type !== $settingsType) {
171
-				continue;
172
-			}
173
-
174
-			try {
175
-				/** @var ISettings $setting */
176
-				$setting = $this->container->query($class);
177
-			} catch (QueryException $e) {
178
-				$this->log->logException($e, ['level' => ILogger::INFO]);
179
-				continue;
180
-			}
181
-
182
-			if (!$setting instanceof ISettings) {
183
-				$this->log->logException(new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'), ['level' => ILogger::INFO]);
184
-				continue;
185
-			}
186
-
187
-			if ($filter !== null && !$filter($setting)) {
188
-				continue;
189
-			}
190
-			if ($setting->getSection() === null) {
191
-				continue;
192
-			}
193
-
194
-			if (!isset($this->settings[$settingsType][$setting->getSection()])) {
195
-				$this->settings[$settingsType][$setting->getSection()] = [];
196
-			}
197
-			$this->settings[$settingsType][$setting->getSection()][] = $setting;
198
-
199
-			unset($this->settingClasses[$class]);
200
-		}
201
-
202
-		return $this->settings[$type][$section];
203
-	}
204
-
205
-	/**
206
-	 * @inheritdoc
207
-	 */
208
-	public function getAdminSections(): array {
209
-		// built-in sections
210
-		$sections = [];
211
-
212
-		$appSections = $this->getSections('admin');
213
-
214
-		foreach ($appSections as $section) {
215
-			/** @var ISection $section */
216
-			if (!isset($sections[$section->getPriority()])) {
217
-				$sections[$section->getPriority()] = [];
218
-			}
219
-
220
-			$sections[$section->getPriority()][] = $section;
221
-		}
222
-
223
-		ksort($sections);
224
-
225
-		return $sections;
226
-	}
227
-
228
-	/**
229
-	 * @inheritdoc
230
-	 */
231
-	public function getAdminSettings($section, bool $subAdminOnly = false): array {
232
-		if ($subAdminOnly) {
233
-			$subAdminSettingsFilter = function (ISettings $settings) {
234
-				return $settings instanceof ISubAdminSettings;
235
-			};
236
-			$appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter);
237
-		} else {
238
-			$appSettings = $this->getSettings('admin', $section);
239
-		}
240
-
241
-		$settings = [];
242
-		foreach ($appSettings as $setting) {
243
-			if (!isset($settings[$setting->getPriority()])) {
244
-				$settings[$setting->getPriority()] = [];
245
-			}
246
-			$settings[$setting->getPriority()][] = $setting;
247
-		}
248
-
249
-		ksort($settings);
250
-		return $settings;
251
-	}
252
-
253
-	/**
254
-	 * @inheritdoc
255
-	 */
256
-	public function getPersonalSections(): array {
257
-		if ($this->l === null) {
258
-			$this->l = $this->l10nFactory->get('lib');
259
-		}
260
-
261
-		$sections = [];
262
-
263
-		$legacyForms = \OC_App::getForms('personal');
264
-		if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
265
-			$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
266
-		}
267
-
268
-		$appSections = $this->getSections('personal');
269
-
270
-		foreach ($appSections as $section) {
271
-			/** @var ISection $section */
272
-			if (!isset($sections[$section->getPriority()])) {
273
-				$sections[$section->getPriority()] = [];
274
-			}
275
-
276
-			$sections[$section->getPriority()][] = $section;
277
-		}
278
-
279
-		ksort($sections);
280
-
281
-		return $sections;
282
-	}
283
-
284
-	/**
285
-	 * @param string[] $forms
286
-	 *
287
-	 * @return bool
288
-	 */
289
-	private function hasLegacyPersonalSettingsToRender(array $forms): bool {
290
-		foreach ($forms as $form) {
291
-			if (trim($form) !== '') {
292
-				return true;
293
-			}
294
-		}
295
-		return false;
296
-	}
297
-
298
-	/**
299
-	 * @inheritdoc
300
-	 */
301
-	public function getPersonalSettings($section): array {
302
-		$settings = [];
303
-		$appSettings = $this->getSettings('personal', $section);
304
-
305
-		foreach ($appSettings as $setting) {
306
-			if (!isset($settings[$setting->getPriority()])) {
307
-				$settings[$setting->getPriority()] = [];
308
-			}
309
-			$settings[$setting->getPriority()][] = $setting;
310
-		}
311
-
312
-		ksort($settings);
313
-		return $settings;
314
-	}
48
+    /** @var ILogger */
49
+    private $log;
50
+
51
+    /** @var IL10N */
52
+    private $l;
53
+
54
+    /** @var IFactory */
55
+    private $l10nFactory;
56
+
57
+    /** @var IURLGenerator */
58
+    private $url;
59
+
60
+    /** @var IServerContainer */
61
+    private $container;
62
+
63
+    public function __construct(
64
+        ILogger $log,
65
+        IFactory $l10nFactory,
66
+        IURLGenerator $url,
67
+        IServerContainer $container
68
+    ) {
69
+        $this->log = $log;
70
+        $this->l10nFactory = $l10nFactory;
71
+        $this->url = $url;
72
+        $this->container = $container;
73
+    }
74
+
75
+    /** @var array */
76
+    protected $sectionClasses = [];
77
+
78
+    /** @var array */
79
+    protected $sections = [];
80
+
81
+    /**
82
+     * @param string $type 'admin' or 'personal'
83
+     * @param string $section Class must implement OCP\Settings\ISection
84
+     *
85
+     * @return void
86
+     */
87
+    public function registerSection(string $type, string $section) {
88
+        if (!isset($this->sectionClasses[$type])) {
89
+            $this->sectionClasses[$type] = [];
90
+        }
91
+
92
+        $this->sectionClasses[$type][] = $section;
93
+    }
94
+
95
+    /**
96
+     * @param string $type 'admin' or 'personal'
97
+     *
98
+     * @return ISection[]
99
+     */
100
+    protected function getSections(string $type): array {
101
+        if (!isset($this->sections[$type])) {
102
+            $this->sections[$type] = [];
103
+        }
104
+
105
+        if (!isset($this->sectionClasses[$type])) {
106
+            return $this->sections[$type];
107
+        }
108
+
109
+        foreach (array_unique($this->sectionClasses[$type]) as $index => $class) {
110
+            try {
111
+                /** @var ISection $section */
112
+                $section = \OC::$server->query($class);
113
+            } catch (QueryException $e) {
114
+                $this->log->logException($e, ['level' => ILogger::INFO]);
115
+                continue;
116
+            }
117
+
118
+            if (!$section instanceof ISection) {
119
+                $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]);
120
+                continue;
121
+            }
122
+
123
+            $sectionID = $section->getID();
124
+
125
+            if (isset($this->sections[$type][$sectionID])) {
126
+                $this->log->logException(new \InvalidArgumentException('Section with the same ID already registered: ' . $sectionID . ', class: ' . $class), ['level' => ILogger::INFO]);
127
+                continue;
128
+            }
129
+
130
+            $this->sections[$type][$sectionID] = $section;
131
+
132
+            unset($this->sectionClasses[$type][$index]);
133
+        }
134
+
135
+        return $this->sections[$type];
136
+    }
137
+
138
+    /** @var array */
139
+    protected $settingClasses = [];
140
+
141
+    /** @var array */
142
+    protected $settings = [];
143
+
144
+    /**
145
+     * @param string $type 'admin' or 'personal'
146
+     * @param string $setting Class must implement OCP\Settings\ISetting
147
+     *
148
+     * @return void
149
+     */
150
+    public function registerSetting(string $type, string $setting) {
151
+        $this->settingClasses[$setting] = $type;
152
+    }
153
+
154
+    /**
155
+     * @param string $type 'admin' or 'personal'
156
+     * @param string $section
157
+     * @param Closure $filter optional filter to apply on all loaded ISettings
158
+     *
159
+     * @return ISettings[]
160
+     */
161
+    protected function getSettings(string $type, string $section, Closure $filter = null): array {
162
+        if (!isset($this->settings[$type])) {
163
+            $this->settings[$type] = [];
164
+        }
165
+        if (!isset($this->settings[$type][$section])) {
166
+            $this->settings[$type][$section] = [];
167
+        }
168
+
169
+        foreach ($this->settingClasses as $class => $settingsType) {
170
+            if ($type !== $settingsType) {
171
+                continue;
172
+            }
173
+
174
+            try {
175
+                /** @var ISettings $setting */
176
+                $setting = $this->container->query($class);
177
+            } catch (QueryException $e) {
178
+                $this->log->logException($e, ['level' => ILogger::INFO]);
179
+                continue;
180
+            }
181
+
182
+            if (!$setting instanceof ISettings) {
183
+                $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'), ['level' => ILogger::INFO]);
184
+                continue;
185
+            }
186
+
187
+            if ($filter !== null && !$filter($setting)) {
188
+                continue;
189
+            }
190
+            if ($setting->getSection() === null) {
191
+                continue;
192
+            }
193
+
194
+            if (!isset($this->settings[$settingsType][$setting->getSection()])) {
195
+                $this->settings[$settingsType][$setting->getSection()] = [];
196
+            }
197
+            $this->settings[$settingsType][$setting->getSection()][] = $setting;
198
+
199
+            unset($this->settingClasses[$class]);
200
+        }
201
+
202
+        return $this->settings[$type][$section];
203
+    }
204
+
205
+    /**
206
+     * @inheritdoc
207
+     */
208
+    public function getAdminSections(): array {
209
+        // built-in sections
210
+        $sections = [];
211
+
212
+        $appSections = $this->getSections('admin');
213
+
214
+        foreach ($appSections as $section) {
215
+            /** @var ISection $section */
216
+            if (!isset($sections[$section->getPriority()])) {
217
+                $sections[$section->getPriority()] = [];
218
+            }
219
+
220
+            $sections[$section->getPriority()][] = $section;
221
+        }
222
+
223
+        ksort($sections);
224
+
225
+        return $sections;
226
+    }
227
+
228
+    /**
229
+     * @inheritdoc
230
+     */
231
+    public function getAdminSettings($section, bool $subAdminOnly = false): array {
232
+        if ($subAdminOnly) {
233
+            $subAdminSettingsFilter = function (ISettings $settings) {
234
+                return $settings instanceof ISubAdminSettings;
235
+            };
236
+            $appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter);
237
+        } else {
238
+            $appSettings = $this->getSettings('admin', $section);
239
+        }
240
+
241
+        $settings = [];
242
+        foreach ($appSettings as $setting) {
243
+            if (!isset($settings[$setting->getPriority()])) {
244
+                $settings[$setting->getPriority()] = [];
245
+            }
246
+            $settings[$setting->getPriority()][] = $setting;
247
+        }
248
+
249
+        ksort($settings);
250
+        return $settings;
251
+    }
252
+
253
+    /**
254
+     * @inheritdoc
255
+     */
256
+    public function getPersonalSections(): array {
257
+        if ($this->l === null) {
258
+            $this->l = $this->l10nFactory->get('lib');
259
+        }
260
+
261
+        $sections = [];
262
+
263
+        $legacyForms = \OC_App::getForms('personal');
264
+        if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
265
+            $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
266
+        }
267
+
268
+        $appSections = $this->getSections('personal');
269
+
270
+        foreach ($appSections as $section) {
271
+            /** @var ISection $section */
272
+            if (!isset($sections[$section->getPriority()])) {
273
+                $sections[$section->getPriority()] = [];
274
+            }
275
+
276
+            $sections[$section->getPriority()][] = $section;
277
+        }
278
+
279
+        ksort($sections);
280
+
281
+        return $sections;
282
+    }
283
+
284
+    /**
285
+     * @param string[] $forms
286
+     *
287
+     * @return bool
288
+     */
289
+    private function hasLegacyPersonalSettingsToRender(array $forms): bool {
290
+        foreach ($forms as $form) {
291
+            if (trim($form) !== '') {
292
+                return true;
293
+            }
294
+        }
295
+        return false;
296
+    }
297
+
298
+    /**
299
+     * @inheritdoc
300
+     */
301
+    public function getPersonalSettings($section): array {
302
+        $settings = [];
303
+        $appSettings = $this->getSettings('personal', $section);
304
+
305
+        foreach ($appSettings as $setting) {
306
+            if (!isset($settings[$setting->getPriority()])) {
307
+                $settings[$setting->getPriority()] = [];
308
+            }
309
+            $settings[$setting->getPriority()][] = $setting;
310
+        }
311
+
312
+        ksort($settings);
313
+        return $settings;
314
+    }
315 315
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 			$sectionID = $section->getID();
124 124
 
125 125
 			if (isset($this->sections[$type][$sectionID])) {
126
-				$this->log->logException(new \InvalidArgumentException('Section with the same ID already registered: ' . $sectionID . ', class: ' . $class), ['level' => ILogger::INFO]);
126
+				$this->log->logException(new \InvalidArgumentException('Section with the same ID already registered: '.$sectionID.', class: '.$class), ['level' => ILogger::INFO]);
127 127
 				continue;
128 128
 			}
129 129
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 			}
181 181
 
182 182
 			if (!$setting instanceof ISettings) {
183
-				$this->log->logException(new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'), ['level' => ILogger::INFO]);
183
+				$this->log->logException(new \InvalidArgumentException('Invalid settings setting registered ('.$class.')'), ['level' => ILogger::INFO]);
184 184
 				continue;
185 185
 			}
186 186
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 */
231 231
 	public function getAdminSettings($section, bool $subAdminOnly = false): array {
232 232
 		if ($subAdminOnly) {
233
-			$subAdminSettingsFilter = function (ISettings $settings) {
233
+			$subAdminSettingsFilter = function(ISettings $settings) {
234 234
 				return $settings instanceof ISubAdminSettings;
235 235
 			};
236 236
 			$appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter);
Please login to merge, or discard this patch.