1717use OCP \Config \Lexicon \ILexicon ;
1818use OCP \Config \Lexicon \Preset ;
1919use OCP \Config \Lexicon \Strictness ;
20+ use OCP \Config \ValueType ;
2021use OCP \DB \Exception as DBException ;
2122use OCP \DB \QueryBuilder \IQueryBuilder ;
2223use OCP \Exceptions \AppConfigIncorrectTypeException ;
@@ -1094,6 +1095,49 @@ public function getDetails(string $app, string $key): array {
10941095 ];
10951096 }
10961097
1098+ /**
1099+ * @inheritDoc
1100+ *
1101+ * @param string $app id of the app
1102+ * @param string $key config key
1103+ *
1104+ * @return array{app: string, key: string, lazy?: bool, valueType?: ValueType, valueTypeName?: string, sensitive?: bool, default?: string, definition?: string, note?: string}
1105+ * @since 32.0.0
1106+ */
1107+ public function getKeyDetails (string $ app , string $ key ): array {
1108+ $ this ->assertParams ($ app , $ key );
1109+ try {
1110+ $ details = $ this ->getDetails ($ app , $ key );
1111+ } catch (AppConfigUnknownKeyException $ e ) {
1112+ $ details = [
1113+ 'app ' => $ app ,
1114+ 'key ' => $ key
1115+ ];
1116+ }
1117+
1118+ /** @var Entry $lexiconEntry */
1119+ try {
1120+ $ lazy = false ;
1121+ $ this ->matchAndApplyLexiconDefinition ($ app , $ key , $ lazy , lexiconEntry: $ lexiconEntry );
1122+ } catch (AppConfigTypeConflictException |AppConfigUnknownKeyException ) {
1123+ // can be ignored
1124+ }
1125+
1126+ if ($ lexiconEntry !== null ) {
1127+ $ details = array_merge ($ details , [
1128+ 'lazy ' => $ lexiconEntry ->isLazy (),
1129+ 'valueType ' => $ lexiconEntry ->getValueType (),
1130+ 'valueTypeName ' => $ lexiconEntry ->getValueType ()->name ,
1131+ 'sensitive ' => $ lexiconEntry ->isFlagged (self ::FLAG_SENSITIVE ),
1132+ 'default ' => $ lexiconEntry ->getDefault ($ this ->getLexiconPreset ()),
1133+ 'definition ' => $ lexiconEntry ->getDefinition (),
1134+ 'note ' => $ lexiconEntry ->getNote (),
1135+ ]);
1136+ }
1137+
1138+ return array_filter ($ details );
1139+ }
1140+
10971141 /**
10981142 * @param string $type
10991143 *
@@ -1631,6 +1675,7 @@ private function matchAndApplyLexiconDefinition(
16311675 ?bool &$ lazy = null ,
16321676 int &$ type = self ::VALUE_MIXED ,
16331677 ?string &$ default = null ,
1678+ ?Entry &$ lexiconEntry = null ,
16341679 ): bool {
16351680 if (in_array ($ key ,
16361681 [
@@ -1655,27 +1700,27 @@ private function matchAndApplyLexiconDefinition(
16551700 return true ;
16561701 }
16571702
1658- /** @var Entry $configValue */
1659- $ configValue = $ configDetails ['entries ' ][$ key ];
1703+ /** @var Entry $lexiconEntry */
1704+ $ lexiconEntry = $ configDetails ['entries ' ][$ key ];
16601705 $ type &= ~self ::VALUE_SENSITIVE ;
16611706
1662- $ appConfigValueType = $ configValue ->getValueType ()->toAppConfigFlag ();
1707+ $ appConfigValueType = $ lexiconEntry ->getValueType ()->toAppConfigFlag ();
16631708 if ($ type === self ::VALUE_MIXED ) {
16641709 $ type = $ appConfigValueType ; // we overwrite if value was requested as mixed
16651710 } elseif ($ appConfigValueType !== $ type ) {
16661711 throw new AppConfigTypeConflictException ('The app config key ' . $ app . '/ ' . $ key . ' is typed incorrectly in relation to the config lexicon ' );
16671712 }
16681713
1669- $ lazy = $ configValue ->isLazy ();
1714+ $ lazy = $ lexiconEntry ->isLazy ();
16701715 // only look for default if needed, default from Lexicon got priority
16711716 if ($ default !== null ) {
1672- $ default = $ configValue ->getDefault ($ this ->getLexiconPreset ()) ?? $ default ;
1717+ $ default = $ lexiconEntry ->getDefault ($ this ->getLexiconPreset ()) ?? $ default ;
16731718 }
16741719
1675- if ($ configValue ->isFlagged (self ::FLAG_SENSITIVE )) {
1720+ if ($ lexiconEntry ->isFlagged (self ::FLAG_SENSITIVE )) {
16761721 $ type |= self ::VALUE_SENSITIVE ;
16771722 }
1678- if ($ configValue ->isDeprecated ()) {
1723+ if ($ lexiconEntry ->isDeprecated ()) {
16791724 $ this ->logger ->notice ('App config key ' . $ app . '/ ' . $ key . ' is set as deprecated. ' );
16801725 }
16811726
0 commit comments