@@ -79,6 +79,13 @@ class UserConfig {
7979 'default ' => true ,
8080 'allowed ' => [true , false ],
8181 ],
82+ [
83+ // Maximum number of files to display in the recent section
84+ 'key ' => 'recent_files_limit ' ,
85+ 'default ' => 100 ,
86+ 'min ' => 1 ,
87+ 'max ' => 100 ,
88+ ],
8289 ];
8390 protected ?IUser $ user = null ;
8491
@@ -118,7 +125,7 @@ private function getAllowedConfigValues(string $key): array {
118125 * Get the default config value for a given key
119126 *
120127 * @param string $key a valid config key
121- * @return string|bool
128+ * @return string|bool|int
122129 */
123130 private function getDefaultConfigValue (string $ key ) {
124131 foreach (self ::ALLOWED_CONFIGS as $ config ) {
@@ -146,7 +153,13 @@ public function setConfig(string $key, $value): void {
146153 throw new \InvalidArgumentException ('Unknown config key ' );
147154 }
148155
149- if (!in_array ($ value , $ this ->getAllowedConfigValues ($ key ))) {
156+ $ config = $ this ->getConfigDefinition ($ key );
157+
158+ if (isset ($ config ['min ' ], $ config ['max ' ])) {
159+ if ((int )$ value < $ config ['min ' ] || (int )$ value > $ config ['max ' ]) {
160+ throw new \InvalidArgumentException ('Invalid config value ' );
161+ }
162+ } elseif (!in_array ($ value , $ this ->getAllowedConfigValues ($ key ))) {
150163 throw new \InvalidArgumentException ('Invalid config value ' );
151164 }
152165
@@ -179,4 +192,19 @@ public function getConfigs(): array {
179192
180193 return array_combine ($ this ->getAllowedConfigKeys (), $ userConfigs );
181194 }
195+
196+ /**
197+ * Get the config definition for a given key
198+ *
199+ * @param string $key
200+ * @return array
201+ */
202+ private function getConfigDefinition (string $ key ): array {
203+ foreach (self ::ALLOWED_CONFIGS as $ config ) {
204+ if ($ config ['key ' ] === $ key ) {
205+ return $ config ;
206+ }
207+ }
208+ return [];
209+ }
182210}
0 commit comments