88
99namespace NCU \Config \Lexicon ;
1010
11+ use Closure ;
1112use NCU \Config \ValueType ;
13+ use OC \Config \ConfigManager ;
1214
1315/**
1416 * Model that represent config values within an app config lexicon.
@@ -24,7 +26,7 @@ class ConfigLexiconEntry {
2426 private ?string $ default = null ;
2527
2628 /**
27- * @param string $key config key
29+ * @param string $key config key, can only contain alphanumerical chars and -._
2830 * @param ValueType $type type of config value
2931 * @param string $definition optional description of config key available when using occ command
3032 * @param bool $lazy set config value as lazy
@@ -39,14 +41,19 @@ class ConfigLexiconEntry {
3941 public function __construct (
4042 private readonly string $ key ,
4143 private readonly ValueType $ type ,
42- private null |string |int |float |bool |array $ defaultRaw = null ,
44+ private null |string |int |float |bool |array | Closure $ defaultRaw = null ,
4345 string $ definition = '' ,
4446 private readonly bool $ lazy = false ,
4547 private readonly int $ flags = 0 ,
4648 private readonly bool $ deprecated = false ,
4749 private readonly ?string $ rename = null ,
4850 private readonly int $ options = 0 ,
4951 ) {
52+ // key can only contain alphanumeric chars, underscore "_" , dash "-" and dot "."
53+ if (preg_match ('/[^[:alnum:]_]/ ' , $ key )) {
54+ throw new \Exception ('invalid config key ' );
55+ }
56+
5057 /** @psalm-suppress UndefinedClass */
5158 if (\OC ::$ CLI ) { // only store definition if ran from CLI
5259 $ this ->definition = $ definition ;
@@ -129,7 +136,13 @@ public function getDefault(): ?string {
129136 return null ;
130137 }
131138
139+ if ($ this ->defaultRaw instanceof Closure) {
140+ /** @psalm-suppress MixedAssignment we expect closure to returns string|int|float|bool|array */
141+ $ this ->defaultRaw = ($ this ->defaultRaw )(ConfigManager::$ preset );
142+ }
143+
132144 if ($ this ->default === null ) {
145+ /** @psalm-suppress MixedArgument closure should be managed previously */
133146 $ this ->default = $ this ->convertToString ($ this ->defaultRaw );
134147 }
135148
0 commit comments