@@ -11,344 +11,344 @@ |
||
| 11 | 11 | use function simplexml_load_string; |
| 12 | 12 | |
| 13 | 13 | class InfoParser { |
| 14 | - /** |
|
| 15 | - * @param ICache|null $cache |
|
| 16 | - */ |
|
| 17 | - public function __construct( |
|
| 18 | - private ?ICache $cache = null, |
|
| 19 | - ) { |
|
| 20 | - } |
|
| 14 | + /** |
|
| 15 | + * @param ICache|null $cache |
|
| 16 | + */ |
|
| 17 | + public function __construct( |
|
| 18 | + private ?ICache $cache = null, |
|
| 19 | + ) { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param string $file the xml file to be loaded |
|
| 24 | - * @return null|array where null is an indicator for an error |
|
| 25 | - */ |
|
| 26 | - public function parse(string $file): ?array { |
|
| 27 | - if (!file_exists($file)) { |
|
| 28 | - return null; |
|
| 29 | - } |
|
| 22 | + /** |
|
| 23 | + * @param string $file the xml file to be loaded |
|
| 24 | + * @return null|array where null is an indicator for an error |
|
| 25 | + */ |
|
| 26 | + public function parse(string $file): ?array { |
|
| 27 | + if (!file_exists($file)) { |
|
| 28 | + return null; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - if ($this->cache !== null) { |
|
| 32 | - $fileCacheKey = $file . filemtime($file); |
|
| 33 | - if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
| 34 | - return json_decode($cachedValue, true); |
|
| 35 | - } |
|
| 36 | - } |
|
| 31 | + if ($this->cache !== null) { |
|
| 32 | + $fileCacheKey = $file . filemtime($file); |
|
| 33 | + if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
| 34 | + return json_decode($cachedValue, true); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - libxml_use_internal_errors(true); |
|
| 39 | - $xml = simplexml_load_string(file_get_contents($file)); |
|
| 38 | + libxml_use_internal_errors(true); |
|
| 39 | + $xml = simplexml_load_string(file_get_contents($file)); |
|
| 40 | 40 | |
| 41 | - if ($xml === false) { |
|
| 42 | - libxml_clear_errors(); |
|
| 43 | - return null; |
|
| 44 | - } |
|
| 45 | - $array = $this->xmlToArray($xml); |
|
| 41 | + if ($xml === false) { |
|
| 42 | + libxml_clear_errors(); |
|
| 43 | + return null; |
|
| 44 | + } |
|
| 45 | + $array = $this->xmlToArray($xml); |
|
| 46 | 46 | |
| 47 | - if (is_string($array)) { |
|
| 48 | - return null; |
|
| 49 | - } |
|
| 47 | + if (is_string($array)) { |
|
| 48 | + return null; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if (!array_key_exists('info', $array)) { |
|
| 52 | - $array['info'] = []; |
|
| 53 | - } |
|
| 54 | - if (!array_key_exists('remote', $array)) { |
|
| 55 | - $array['remote'] = []; |
|
| 56 | - } |
|
| 57 | - if (!array_key_exists('public', $array)) { |
|
| 58 | - $array['public'] = []; |
|
| 59 | - } |
|
| 60 | - if (!array_key_exists('types', $array)) { |
|
| 61 | - $array['types'] = []; |
|
| 62 | - } |
|
| 63 | - if (!array_key_exists('repair-steps', $array)) { |
|
| 64 | - $array['repair-steps'] = []; |
|
| 65 | - } |
|
| 66 | - if (!array_key_exists('install', $array['repair-steps'])) { |
|
| 67 | - $array['repair-steps']['install'] = []; |
|
| 68 | - } |
|
| 69 | - if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
| 70 | - $array['repair-steps']['pre-migration'] = []; |
|
| 71 | - } |
|
| 72 | - if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
| 73 | - $array['repair-steps']['post-migration'] = []; |
|
| 74 | - } |
|
| 75 | - if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
| 76 | - $array['repair-steps']['live-migration'] = []; |
|
| 77 | - } |
|
| 78 | - if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
| 79 | - $array['repair-steps']['uninstall'] = []; |
|
| 80 | - } |
|
| 81 | - if (!array_key_exists('background-jobs', $array)) { |
|
| 82 | - $array['background-jobs'] = []; |
|
| 83 | - } |
|
| 84 | - if (!array_key_exists('two-factor-providers', $array)) { |
|
| 85 | - $array['two-factor-providers'] = []; |
|
| 86 | - } |
|
| 87 | - if (!array_key_exists('commands', $array)) { |
|
| 88 | - $array['commands'] = []; |
|
| 89 | - } |
|
| 90 | - if (!array_key_exists('activity', $array)) { |
|
| 91 | - $array['activity'] = []; |
|
| 92 | - } |
|
| 93 | - if (!array_key_exists('filters', $array['activity'])) { |
|
| 94 | - $array['activity']['filters'] = []; |
|
| 95 | - } |
|
| 96 | - if (!array_key_exists('settings', $array['activity'])) { |
|
| 97 | - $array['activity']['settings'] = []; |
|
| 98 | - } |
|
| 99 | - if (!array_key_exists('providers', $array['activity'])) { |
|
| 100 | - $array['activity']['providers'] = []; |
|
| 101 | - } |
|
| 102 | - if (!array_key_exists('settings', $array)) { |
|
| 103 | - $array['settings'] = []; |
|
| 104 | - } |
|
| 105 | - if (!array_key_exists('admin', $array['settings'])) { |
|
| 106 | - $array['settings']['admin'] = []; |
|
| 107 | - } |
|
| 108 | - if (!array_key_exists('admin-section', $array['settings'])) { |
|
| 109 | - $array['settings']['admin-section'] = []; |
|
| 110 | - } |
|
| 111 | - if (!array_key_exists('personal', $array['settings'])) { |
|
| 112 | - $array['settings']['personal'] = []; |
|
| 113 | - } |
|
| 114 | - if (!array_key_exists('personal-section', $array['settings'])) { |
|
| 115 | - $array['settings']['personal-section'] = []; |
|
| 116 | - } |
|
| 117 | - if (!array_key_exists('dependencies', $array)) { |
|
| 118 | - $array['dependencies'] = []; |
|
| 119 | - } |
|
| 120 | - if (!array_key_exists('backend', $array['dependencies'])) { |
|
| 121 | - $array['dependencies']['backend'] = []; |
|
| 122 | - } |
|
| 51 | + if (!array_key_exists('info', $array)) { |
|
| 52 | + $array['info'] = []; |
|
| 53 | + } |
|
| 54 | + if (!array_key_exists('remote', $array)) { |
|
| 55 | + $array['remote'] = []; |
|
| 56 | + } |
|
| 57 | + if (!array_key_exists('public', $array)) { |
|
| 58 | + $array['public'] = []; |
|
| 59 | + } |
|
| 60 | + if (!array_key_exists('types', $array)) { |
|
| 61 | + $array['types'] = []; |
|
| 62 | + } |
|
| 63 | + if (!array_key_exists('repair-steps', $array)) { |
|
| 64 | + $array['repair-steps'] = []; |
|
| 65 | + } |
|
| 66 | + if (!array_key_exists('install', $array['repair-steps'])) { |
|
| 67 | + $array['repair-steps']['install'] = []; |
|
| 68 | + } |
|
| 69 | + if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
| 70 | + $array['repair-steps']['pre-migration'] = []; |
|
| 71 | + } |
|
| 72 | + if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
| 73 | + $array['repair-steps']['post-migration'] = []; |
|
| 74 | + } |
|
| 75 | + if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
| 76 | + $array['repair-steps']['live-migration'] = []; |
|
| 77 | + } |
|
| 78 | + if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
| 79 | + $array['repair-steps']['uninstall'] = []; |
|
| 80 | + } |
|
| 81 | + if (!array_key_exists('background-jobs', $array)) { |
|
| 82 | + $array['background-jobs'] = []; |
|
| 83 | + } |
|
| 84 | + if (!array_key_exists('two-factor-providers', $array)) { |
|
| 85 | + $array['two-factor-providers'] = []; |
|
| 86 | + } |
|
| 87 | + if (!array_key_exists('commands', $array)) { |
|
| 88 | + $array['commands'] = []; |
|
| 89 | + } |
|
| 90 | + if (!array_key_exists('activity', $array)) { |
|
| 91 | + $array['activity'] = []; |
|
| 92 | + } |
|
| 93 | + if (!array_key_exists('filters', $array['activity'])) { |
|
| 94 | + $array['activity']['filters'] = []; |
|
| 95 | + } |
|
| 96 | + if (!array_key_exists('settings', $array['activity'])) { |
|
| 97 | + $array['activity']['settings'] = []; |
|
| 98 | + } |
|
| 99 | + if (!array_key_exists('providers', $array['activity'])) { |
|
| 100 | + $array['activity']['providers'] = []; |
|
| 101 | + } |
|
| 102 | + if (!array_key_exists('settings', $array)) { |
|
| 103 | + $array['settings'] = []; |
|
| 104 | + } |
|
| 105 | + if (!array_key_exists('admin', $array['settings'])) { |
|
| 106 | + $array['settings']['admin'] = []; |
|
| 107 | + } |
|
| 108 | + if (!array_key_exists('admin-section', $array['settings'])) { |
|
| 109 | + $array['settings']['admin-section'] = []; |
|
| 110 | + } |
|
| 111 | + if (!array_key_exists('personal', $array['settings'])) { |
|
| 112 | + $array['settings']['personal'] = []; |
|
| 113 | + } |
|
| 114 | + if (!array_key_exists('personal-section', $array['settings'])) { |
|
| 115 | + $array['settings']['personal-section'] = []; |
|
| 116 | + } |
|
| 117 | + if (!array_key_exists('dependencies', $array)) { |
|
| 118 | + $array['dependencies'] = []; |
|
| 119 | + } |
|
| 120 | + if (!array_key_exists('backend', $array['dependencies'])) { |
|
| 121 | + $array['dependencies']['backend'] = []; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - if (array_key_exists('types', $array)) { |
|
| 125 | - if (is_array($array['types'])) { |
|
| 126 | - foreach ($array['types'] as $type => $v) { |
|
| 127 | - unset($array['types'][$type]); |
|
| 128 | - if (is_string($type)) { |
|
| 129 | - $array['types'][] = $type; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } else { |
|
| 133 | - $array['types'] = []; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
| 137 | - $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
| 138 | - } |
|
| 139 | - if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
| 140 | - $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
| 141 | - } |
|
| 142 | - if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
| 143 | - $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
| 144 | - } |
|
| 145 | - if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
| 146 | - $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
| 147 | - } |
|
| 148 | - if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
| 149 | - $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
| 150 | - } |
|
| 151 | - if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
| 152 | - $array['background-jobs'] = $array['background-jobs']['job']; |
|
| 153 | - } |
|
| 154 | - if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
| 155 | - $array['commands'] = $array['commands']['command']; |
|
| 156 | - } |
|
| 157 | - if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) { |
|
| 158 | - $array['two-factor-providers'] = $array['two-factor-providers']['provider']; |
|
| 159 | - } |
|
| 160 | - if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
| 161 | - $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
| 162 | - } |
|
| 163 | - if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
| 164 | - $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
| 165 | - } |
|
| 166 | - if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
| 167 | - $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
| 168 | - } |
|
| 169 | - if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 170 | - && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 171 | - && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
| 172 | - ) { |
|
| 173 | - $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
| 174 | - } |
|
| 175 | - if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) { |
|
| 176 | - $array['settings']['admin'] = [$array['settings']['admin']]; |
|
| 177 | - } |
|
| 178 | - if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) { |
|
| 179 | - $array['settings']['admin-section'] = [$array['settings']['admin-section']]; |
|
| 180 | - } |
|
| 181 | - if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) { |
|
| 182 | - $array['settings']['personal'] = [$array['settings']['personal']]; |
|
| 183 | - } |
|
| 184 | - if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) { |
|
| 185 | - $array['settings']['personal-section'] = [$array['settings']['personal-section']]; |
|
| 186 | - } |
|
| 187 | - if (isset($array['settings']['admin-delegation']) && !is_array($array['settings']['admin-delegation'])) { |
|
| 188 | - $array['settings']['admin-delegation'] = [$array['settings']['admin-delegation']]; |
|
| 189 | - } |
|
| 190 | - if (isset($array['settings']['admin-delegation-section']) && !is_array($array['settings']['admin-delegation-section'])) { |
|
| 191 | - $array['settings']['admin-delegation-section'] = [$array['settings']['admin-delegation-section']]; |
|
| 192 | - } |
|
| 193 | - if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { |
|
| 194 | - $array['navigations']['navigation'] = [$array['navigations']['navigation']]; |
|
| 195 | - } |
|
| 196 | - if (isset($array['dependencies']['backend']) && !is_array($array['dependencies']['backend'])) { |
|
| 197 | - $array['dependencies']['backend'] = [$array['dependencies']['backend']]; |
|
| 198 | - } |
|
| 124 | + if (array_key_exists('types', $array)) { |
|
| 125 | + if (is_array($array['types'])) { |
|
| 126 | + foreach ($array['types'] as $type => $v) { |
|
| 127 | + unset($array['types'][$type]); |
|
| 128 | + if (is_string($type)) { |
|
| 129 | + $array['types'][] = $type; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } else { |
|
| 133 | + $array['types'] = []; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
| 137 | + $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
| 138 | + } |
|
| 139 | + if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
| 140 | + $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
| 141 | + } |
|
| 142 | + if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
| 143 | + $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
| 144 | + } |
|
| 145 | + if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
| 146 | + $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
| 147 | + } |
|
| 148 | + if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
| 149 | + $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
| 150 | + } |
|
| 151 | + if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
| 152 | + $array['background-jobs'] = $array['background-jobs']['job']; |
|
| 153 | + } |
|
| 154 | + if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
| 155 | + $array['commands'] = $array['commands']['command']; |
|
| 156 | + } |
|
| 157 | + if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) { |
|
| 158 | + $array['two-factor-providers'] = $array['two-factor-providers']['provider']; |
|
| 159 | + } |
|
| 160 | + if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
| 161 | + $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
| 162 | + } |
|
| 163 | + if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
| 164 | + $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
| 165 | + } |
|
| 166 | + if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
| 167 | + $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
| 168 | + } |
|
| 169 | + if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 170 | + && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 171 | + && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
| 172 | + ) { |
|
| 173 | + $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
| 174 | + } |
|
| 175 | + if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) { |
|
| 176 | + $array['settings']['admin'] = [$array['settings']['admin']]; |
|
| 177 | + } |
|
| 178 | + if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) { |
|
| 179 | + $array['settings']['admin-section'] = [$array['settings']['admin-section']]; |
|
| 180 | + } |
|
| 181 | + if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) { |
|
| 182 | + $array['settings']['personal'] = [$array['settings']['personal']]; |
|
| 183 | + } |
|
| 184 | + if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) { |
|
| 185 | + $array['settings']['personal-section'] = [$array['settings']['personal-section']]; |
|
| 186 | + } |
|
| 187 | + if (isset($array['settings']['admin-delegation']) && !is_array($array['settings']['admin-delegation'])) { |
|
| 188 | + $array['settings']['admin-delegation'] = [$array['settings']['admin-delegation']]; |
|
| 189 | + } |
|
| 190 | + if (isset($array['settings']['admin-delegation-section']) && !is_array($array['settings']['admin-delegation-section'])) { |
|
| 191 | + $array['settings']['admin-delegation-section'] = [$array['settings']['admin-delegation-section']]; |
|
| 192 | + } |
|
| 193 | + if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { |
|
| 194 | + $array['navigations']['navigation'] = [$array['navigations']['navigation']]; |
|
| 195 | + } |
|
| 196 | + if (isset($array['dependencies']['backend']) && !is_array($array['dependencies']['backend'])) { |
|
| 197 | + $array['dependencies']['backend'] = [$array['dependencies']['backend']]; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - // Ensure some fields are always arrays |
|
| 201 | - if (isset($array['screenshot']) && !is_array($array['screenshot'])) { |
|
| 202 | - $array['screenshot'] = [$array['screenshot']]; |
|
| 203 | - } |
|
| 204 | - if (isset($array['author']) && !is_array($array['author'])) { |
|
| 205 | - $array['author'] = [$array['author']]; |
|
| 206 | - } |
|
| 207 | - if (isset($array['category']) && !is_array($array['category'])) { |
|
| 208 | - $array['category'] = [$array['category']]; |
|
| 209 | - } |
|
| 200 | + // Ensure some fields are always arrays |
|
| 201 | + if (isset($array['screenshot']) && !is_array($array['screenshot'])) { |
|
| 202 | + $array['screenshot'] = [$array['screenshot']]; |
|
| 203 | + } |
|
| 204 | + if (isset($array['author']) && !is_array($array['author'])) { |
|
| 205 | + $array['author'] = [$array['author']]; |
|
| 206 | + } |
|
| 207 | + if (isset($array['category']) && !is_array($array['category'])) { |
|
| 208 | + $array['category'] = [$array['category']]; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - if ($this->cache !== null) { |
|
| 212 | - $this->cache->set($fileCacheKey, json_encode($array)); |
|
| 213 | - } |
|
| 214 | - return $array; |
|
| 215 | - } |
|
| 211 | + if ($this->cache !== null) { |
|
| 212 | + $this->cache->set($fileCacheKey, json_encode($array)); |
|
| 213 | + } |
|
| 214 | + return $array; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - private function isNavigationItem(array $data): bool { |
|
| 218 | - // Allow settings navigation items with no route entry |
|
| 219 | - $type = $data['type'] ?? 'link'; |
|
| 220 | - if ($type === 'settings') { |
|
| 221 | - return isset($data['name']); |
|
| 222 | - } |
|
| 223 | - return isset($data['name'], $data['route']); |
|
| 224 | - } |
|
| 217 | + private function isNavigationItem(array $data): bool { |
|
| 218 | + // Allow settings navigation items with no route entry |
|
| 219 | + $type = $data['type'] ?? 'link'; |
|
| 220 | + if ($type === 'settings') { |
|
| 221 | + return isset($data['name']); |
|
| 222 | + } |
|
| 223 | + return isset($data['name'], $data['route']); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - public function xmlToArray(\SimpleXMLElement $xml): array|string { |
|
| 227 | - $children = $xml->children(); |
|
| 228 | - if ($children === null || count($children) === 0) { |
|
| 229 | - return (string)$xml; |
|
| 230 | - } |
|
| 226 | + public function xmlToArray(\SimpleXMLElement $xml): array|string { |
|
| 227 | + $children = $xml->children(); |
|
| 228 | + if ($children === null || count($children) === 0) { |
|
| 229 | + return (string)$xml; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - $array = []; |
|
| 233 | - foreach ($children as $element => $node) { |
|
| 234 | - if ($element === null) { |
|
| 235 | - throw new \InvalidArgumentException('xml contains a null element'); |
|
| 236 | - } |
|
| 237 | - $totalElement = count($xml->{$element}); |
|
| 232 | + $array = []; |
|
| 233 | + foreach ($children as $element => $node) { |
|
| 234 | + if ($element === null) { |
|
| 235 | + throw new \InvalidArgumentException('xml contains a null element'); |
|
| 236 | + } |
|
| 237 | + $totalElement = count($xml->{$element}); |
|
| 238 | 238 | |
| 239 | - if (!isset($array[$element])) { |
|
| 240 | - $array[$element] = $totalElement > 1 ? [] : ''; |
|
| 241 | - } |
|
| 242 | - /** @var \SimpleXMLElement $node */ |
|
| 243 | - // Has attributes |
|
| 244 | - if ($attributes = $node->attributes()) { |
|
| 245 | - $data = [ |
|
| 246 | - '@attributes' => [], |
|
| 247 | - ]; |
|
| 248 | - $converted = $this->xmlToArray($node); |
|
| 249 | - if (is_string($converted)) { |
|
| 250 | - if (!empty($converted)) { |
|
| 251 | - $data['@value'] = $converted; |
|
| 252 | - } |
|
| 253 | - } else { |
|
| 254 | - $data = array_merge($data, $converted); |
|
| 255 | - } |
|
| 256 | - foreach ($attributes as $attr => $value) { |
|
| 257 | - if ($attr === null) { |
|
| 258 | - throw new \InvalidArgumentException('xml contains a null element'); |
|
| 259 | - } |
|
| 260 | - $data['@attributes'][$attr] = (string)$value; |
|
| 261 | - } |
|
| 239 | + if (!isset($array[$element])) { |
|
| 240 | + $array[$element] = $totalElement > 1 ? [] : ''; |
|
| 241 | + } |
|
| 242 | + /** @var \SimpleXMLElement $node */ |
|
| 243 | + // Has attributes |
|
| 244 | + if ($attributes = $node->attributes()) { |
|
| 245 | + $data = [ |
|
| 246 | + '@attributes' => [], |
|
| 247 | + ]; |
|
| 248 | + $converted = $this->xmlToArray($node); |
|
| 249 | + if (is_string($converted)) { |
|
| 250 | + if (!empty($converted)) { |
|
| 251 | + $data['@value'] = $converted; |
|
| 252 | + } |
|
| 253 | + } else { |
|
| 254 | + $data = array_merge($data, $converted); |
|
| 255 | + } |
|
| 256 | + foreach ($attributes as $attr => $value) { |
|
| 257 | + if ($attr === null) { |
|
| 258 | + throw new \InvalidArgumentException('xml contains a null element'); |
|
| 259 | + } |
|
| 260 | + $data['@attributes'][$attr] = (string)$value; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - if ($totalElement > 1) { |
|
| 264 | - $array[$element][] = $data; |
|
| 265 | - } else { |
|
| 266 | - $array[$element] = $data; |
|
| 267 | - } |
|
| 268 | - // Just a value |
|
| 269 | - } else { |
|
| 270 | - if ($totalElement > 1) { |
|
| 271 | - $array[$element][] = $this->xmlToArray($node); |
|
| 272 | - } else { |
|
| 273 | - $array[$element] = $this->xmlToArray($node); |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 263 | + if ($totalElement > 1) { |
|
| 264 | + $array[$element][] = $data; |
|
| 265 | + } else { |
|
| 266 | + $array[$element] = $data; |
|
| 267 | + } |
|
| 268 | + // Just a value |
|
| 269 | + } else { |
|
| 270 | + if ($totalElement > 1) { |
|
| 271 | + $array[$element][] = $this->xmlToArray($node); |
|
| 272 | + } else { |
|
| 273 | + $array[$element] = $this->xmlToArray($node); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - return $array; |
|
| 279 | - } |
|
| 278 | + return $array; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Select the appropriate l10n version for fields name, summary and description |
|
| 283 | - */ |
|
| 284 | - public function applyL10N(array $data, ?string $lang = null): array { |
|
| 285 | - if ($lang !== '' && $lang !== null) { |
|
| 286 | - if (isset($data['name']) && is_array($data['name'])) { |
|
| 287 | - $data['name'] = $this->findBestL10NOption($data['name'], $lang); |
|
| 288 | - } |
|
| 289 | - if (isset($data['summary']) && is_array($data['summary'])) { |
|
| 290 | - $data['summary'] = $this->findBestL10NOption($data['summary'], $lang); |
|
| 291 | - } |
|
| 292 | - if (isset($data['description']) && is_array($data['description'])) { |
|
| 293 | - $data['description'] = trim($this->findBestL10NOption($data['description'], $lang)); |
|
| 294 | - } |
|
| 295 | - } elseif (isset($data['description']) && is_string($data['description'])) { |
|
| 296 | - $data['description'] = trim($data['description']); |
|
| 297 | - } else { |
|
| 298 | - $data['description'] = ''; |
|
| 299 | - } |
|
| 281 | + /** |
|
| 282 | + * Select the appropriate l10n version for fields name, summary and description |
|
| 283 | + */ |
|
| 284 | + public function applyL10N(array $data, ?string $lang = null): array { |
|
| 285 | + if ($lang !== '' && $lang !== null) { |
|
| 286 | + if (isset($data['name']) && is_array($data['name'])) { |
|
| 287 | + $data['name'] = $this->findBestL10NOption($data['name'], $lang); |
|
| 288 | + } |
|
| 289 | + if (isset($data['summary']) && is_array($data['summary'])) { |
|
| 290 | + $data['summary'] = $this->findBestL10NOption($data['summary'], $lang); |
|
| 291 | + } |
|
| 292 | + if (isset($data['description']) && is_array($data['description'])) { |
|
| 293 | + $data['description'] = trim($this->findBestL10NOption($data['description'], $lang)); |
|
| 294 | + } |
|
| 295 | + } elseif (isset($data['description']) && is_string($data['description'])) { |
|
| 296 | + $data['description'] = trim($data['description']); |
|
| 297 | + } else { |
|
| 298 | + $data['description'] = ''; |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - return $data; |
|
| 302 | - } |
|
| 301 | + return $data; |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - protected function findBestL10NOption(array $options, string $lang): string { |
|
| 305 | - // only a single option |
|
| 306 | - if (isset($options['@value'])) { |
|
| 307 | - return $options['@value']; |
|
| 308 | - } |
|
| 304 | + protected function findBestL10NOption(array $options, string $lang): string { |
|
| 305 | + // only a single option |
|
| 306 | + if (isset($options['@value'])) { |
|
| 307 | + return $options['@value']; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
| 310 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
| 311 | 311 | |
| 312 | - $lang = strtolower($lang); |
|
| 313 | - $similarLang = $lang; |
|
| 314 | - $pos = strpos($similarLang, '_'); |
|
| 315 | - if ($pos !== false && $pos > 0) { |
|
| 316 | - // For "de_DE" we want to find "de" and the other way around |
|
| 317 | - $similarLang = substr($lang, 0, $pos); |
|
| 318 | - } |
|
| 312 | + $lang = strtolower($lang); |
|
| 313 | + $similarLang = $lang; |
|
| 314 | + $pos = strpos($similarLang, '_'); |
|
| 315 | + if ($pos !== false && $pos > 0) { |
|
| 316 | + // For "de_DE" we want to find "de" and the other way around |
|
| 317 | + $similarLang = substr($lang, 0, $pos); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - foreach ($options as $option) { |
|
| 321 | - if (is_array($option)) { |
|
| 322 | - if ($fallback === false) { |
|
| 323 | - $fallback = $option['@value']; |
|
| 324 | - } |
|
| 320 | + foreach ($options as $option) { |
|
| 321 | + if (is_array($option)) { |
|
| 322 | + if ($fallback === false) { |
|
| 323 | + $fallback = $option['@value']; |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - if (!isset($option['@attributes']['lang'])) { |
|
| 327 | - continue; |
|
| 328 | - } |
|
| 326 | + if (!isset($option['@attributes']['lang'])) { |
|
| 327 | + continue; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
| 331 | - if ($attributeLang === $lang) { |
|
| 332 | - return $option['@value']; |
|
| 333 | - } |
|
| 330 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
| 331 | + if ($attributeLang === $lang) { |
|
| 332 | + return $option['@value']; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if ($attributeLang === $similarLang) { |
|
| 336 | - $similarLangFallback = $option['@value']; |
|
| 337 | - } elseif (str_starts_with($attributeLang, $similarLang . '_')) { |
|
| 338 | - if ($similarLangFallback === false) { |
|
| 339 | - $similarLangFallback = $option['@value']; |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } else { |
|
| 343 | - $englishFallback = $option; |
|
| 344 | - } |
|
| 345 | - } |
|
| 335 | + if ($attributeLang === $similarLang) { |
|
| 336 | + $similarLangFallback = $option['@value']; |
|
| 337 | + } elseif (str_starts_with($attributeLang, $similarLang . '_')) { |
|
| 338 | + if ($similarLangFallback === false) { |
|
| 339 | + $similarLangFallback = $option['@value']; |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } else { |
|
| 343 | + $englishFallback = $option; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - if ($similarLangFallback !== false) { |
|
| 348 | - return $similarLangFallback; |
|
| 349 | - } elseif ($englishFallback !== false) { |
|
| 350 | - return $englishFallback; |
|
| 351 | - } |
|
| 352 | - return (string)$fallback; |
|
| 353 | - } |
|
| 347 | + if ($similarLangFallback !== false) { |
|
| 348 | + return $similarLangFallback; |
|
| 349 | + } elseif ($englishFallback !== false) { |
|
| 350 | + return $englishFallback; |
|
| 351 | + } |
|
| 352 | + return (string)$fallback; |
|
| 353 | + } |
|
| 354 | 354 | } |
@@ -24,329 +24,329 @@ |
||
| 24 | 24 | use Psr\Log\LoggerInterface; |
| 25 | 25 | |
| 26 | 26 | class Manager implements IManager { |
| 27 | - private ?IL10N $l = null; |
|
| 28 | - |
|
| 29 | - /** @var array<self::SETTINGS_*, list<class-string<IIconSection>>> */ |
|
| 30 | - protected array $sectionClasses = []; |
|
| 31 | - |
|
| 32 | - /** @var array<self::SETTINGS_*, array<string, IIconSection>> */ |
|
| 33 | - protected array $sections = []; |
|
| 34 | - |
|
| 35 | - /** @var array<class-string<ISettings>, self::SETTINGS_*> */ |
|
| 36 | - protected array $settingClasses = []; |
|
| 37 | - |
|
| 38 | - /** @var array<self::SETTINGS_*, array<string, list<ISettings>>> */ |
|
| 39 | - protected array $settings = []; |
|
| 40 | - |
|
| 41 | - public function __construct( |
|
| 42 | - private LoggerInterface $log, |
|
| 43 | - private IFactory $l10nFactory, |
|
| 44 | - private IURLGenerator $url, |
|
| 45 | - private IServerContainer $container, |
|
| 46 | - private AuthorizedGroupMapper $mapper, |
|
| 47 | - private IGroupManager $groupManager, |
|
| 48 | - private ISubAdmin $subAdmin, |
|
| 49 | - ) { |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @inheritdoc |
|
| 54 | - */ |
|
| 55 | - public function registerSection(string $type, string $section) { |
|
| 56 | - if (!isset($this->sectionClasses[$type])) { |
|
| 57 | - $this->sectionClasses[$type] = []; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $this->sectionClasses[$type][] = $section; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @psalm-param self::SETTINGS_* $type |
|
| 65 | - * |
|
| 66 | - * @return IIconSection[] |
|
| 67 | - */ |
|
| 68 | - protected function getSections(string $type): array { |
|
| 69 | - if (!isset($this->sections[$type])) { |
|
| 70 | - $this->sections[$type] = []; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - if (!isset($this->sectionClasses[$type])) { |
|
| 74 | - return $this->sections[$type]; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - foreach (array_unique($this->sectionClasses[$type]) as $index => $class) { |
|
| 78 | - try { |
|
| 79 | - /** @var IIconSection $section */ |
|
| 80 | - $section = $this->container->get($class); |
|
| 81 | - } catch (QueryException $e) { |
|
| 82 | - $this->log->info($e->getMessage(), ['exception' => $e]); |
|
| 83 | - continue; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $sectionID = $section->getID(); |
|
| 87 | - |
|
| 88 | - if (!$this->isKnownDuplicateSectionId($sectionID) && isset($this->sections[$type][$sectionID])) { |
|
| 89 | - $e = new \InvalidArgumentException('Section with the same ID already registered: ' . $sectionID . ', class: ' . $class); |
|
| 90 | - $this->log->info($e->getMessage(), ['exception' => $e]); |
|
| 91 | - continue; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $this->sections[$type][$sectionID] = $section; |
|
| 95 | - |
|
| 96 | - unset($this->sectionClasses[$type][$index]); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return $this->sections[$type]; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @inheritdoc |
|
| 104 | - */ |
|
| 105 | - public function getSection(string $type, string $sectionId): ?IIconSection { |
|
| 106 | - if (isset($this->sections[$type]) && isset($this->sections[$type][$sectionId])) { |
|
| 107 | - return $this->sections[$type][$sectionId]; |
|
| 108 | - } |
|
| 109 | - return null; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - protected function isKnownDuplicateSectionId(string $sectionID): bool { |
|
| 113 | - return in_array($sectionID, [ |
|
| 114 | - 'connected-accounts', |
|
| 115 | - 'notifications', |
|
| 116 | - ], true); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @inheritdoc |
|
| 121 | - */ |
|
| 122 | - public function registerSetting(string $type, string $setting) { |
|
| 123 | - $this->settingClasses[$setting] = $type; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @psalm-param self::SETTINGS_* $type The type of the setting. |
|
| 128 | - * @param string $section |
|
| 129 | - * @param ?Closure $filter optional filter to apply on all loaded ISettings |
|
| 130 | - * |
|
| 131 | - * @return ISettings[] |
|
| 132 | - */ |
|
| 133 | - protected function getSettings(string $type, string $section, ?Closure $filter = null): array { |
|
| 134 | - if (!isset($this->settings[$type])) { |
|
| 135 | - $this->settings[$type] = []; |
|
| 136 | - } |
|
| 137 | - if (!isset($this->settings[$type][$section])) { |
|
| 138 | - $this->settings[$type][$section] = []; |
|
| 139 | - |
|
| 140 | - foreach ($this->settingClasses as $class => $settingsType) { |
|
| 141 | - if ($type !== $settingsType) { |
|
| 142 | - continue; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - try { |
|
| 146 | - /** @var ISettings $setting */ |
|
| 147 | - $setting = $this->container->get($class); |
|
| 148 | - } catch (QueryException $e) { |
|
| 149 | - $this->log->info($e->getMessage(), ['exception' => $e]); |
|
| 150 | - continue; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - if (!$setting instanceof ISettings) { |
|
| 154 | - $e = new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'); |
|
| 155 | - $this->log->info($e->getMessage(), ['exception' => $e]); |
|
| 156 | - continue; |
|
| 157 | - } |
|
| 158 | - $settingSection = $setting->getSection(); |
|
| 159 | - if ($settingSection === null) { |
|
| 160 | - continue; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (!isset($this->settings[$settingsType][$settingSection])) { |
|
| 164 | - $this->settings[$settingsType][$settingSection] = []; |
|
| 165 | - } |
|
| 166 | - $this->settings[$settingsType][$settingSection][] = $setting; |
|
| 167 | - |
|
| 168 | - unset($this->settingClasses[$class]); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($filter !== null) { |
|
| 173 | - return array_values(array_filter($this->settings[$type][$section], $filter)); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return $this->settings[$type][$section]; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @inheritdoc |
|
| 181 | - */ |
|
| 182 | - public function getAdminSections(): array { |
|
| 183 | - // built-in sections |
|
| 184 | - $sections = []; |
|
| 185 | - |
|
| 186 | - $appSections = $this->getSections('admin'); |
|
| 187 | - |
|
| 188 | - foreach ($appSections as $section) { |
|
| 189 | - /** @var IIconSection $section */ |
|
| 190 | - if (!isset($sections[$section->getPriority()])) { |
|
| 191 | - $sections[$section->getPriority()] = []; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $sections[$section->getPriority()][] = $section; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - ksort($sections); |
|
| 198 | - |
|
| 199 | - return $sections; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @inheritdoc |
|
| 204 | - */ |
|
| 205 | - public function getAdminSettings(string $section, bool $subAdminOnly = false): array { |
|
| 206 | - if ($subAdminOnly) { |
|
| 207 | - $subAdminSettingsFilter = function (ISettings $settings) { |
|
| 208 | - return $settings instanceof ISubAdminSettings; |
|
| 209 | - }; |
|
| 210 | - $appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter); |
|
| 211 | - } else { |
|
| 212 | - $appSettings = $this->getSettings('admin', $section); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $settings = []; |
|
| 216 | - foreach ($appSettings as $setting) { |
|
| 217 | - if (!isset($settings[$setting->getPriority()])) { |
|
| 218 | - $settings[$setting->getPriority()] = []; |
|
| 219 | - } |
|
| 220 | - $settings[$setting->getPriority()][] = $setting; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - ksort($settings); |
|
| 224 | - return $settings; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @inheritdoc |
|
| 229 | - */ |
|
| 230 | - public function getPersonalSections(): array { |
|
| 231 | - if ($this->l === null) { |
|
| 232 | - $this->l = $this->l10nFactory->get('lib'); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $sections = []; |
|
| 236 | - |
|
| 237 | - if (count($this->getPersonalSettings('additional')) > 1) { |
|
| 238 | - $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $appSections = $this->getSections('personal'); |
|
| 242 | - |
|
| 243 | - foreach ($appSections as $section) { |
|
| 244 | - /** @var IIconSection $section */ |
|
| 245 | - if (!isset($sections[$section->getPriority()])) { |
|
| 246 | - $sections[$section->getPriority()] = []; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $sections[$section->getPriority()][] = $section; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - ksort($sections); |
|
| 253 | - |
|
| 254 | - return $sections; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @inheritdoc |
|
| 259 | - */ |
|
| 260 | - public function getPersonalSettings(string $section): array { |
|
| 261 | - $settings = []; |
|
| 262 | - $appSettings = $this->getSettings('personal', $section); |
|
| 263 | - |
|
| 264 | - foreach ($appSettings as $setting) { |
|
| 265 | - if (!isset($settings[$setting->getPriority()])) { |
|
| 266 | - $settings[$setting->getPriority()] = []; |
|
| 267 | - } |
|
| 268 | - $settings[$setting->getPriority()][] = $setting; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - ksort($settings); |
|
| 272 | - return $settings; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @inheritdoc |
|
| 277 | - */ |
|
| 278 | - public function getAllowedAdminSettings(string $section, IUser $user): array { |
|
| 279 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 280 | - if ($isAdmin) { |
|
| 281 | - $appSettings = $this->getSettings('admin', $section); |
|
| 282 | - } else { |
|
| 283 | - $authorizedSettingsClasses = $this->mapper->findAllClassesForUser($user); |
|
| 284 | - if ($this->subAdmin->isSubAdmin($user)) { |
|
| 285 | - $authorizedGroupFilter = function (ISettings $settings) use ($authorizedSettingsClasses) { |
|
| 286 | - return $settings instanceof ISubAdminSettings |
|
| 287 | - || in_array(get_class($settings), $authorizedSettingsClasses) === true; |
|
| 288 | - }; |
|
| 289 | - } else { |
|
| 290 | - $authorizedGroupFilter = function (ISettings $settings) use ($authorizedSettingsClasses) { |
|
| 291 | - return in_array(get_class($settings), $authorizedSettingsClasses) === true; |
|
| 292 | - }; |
|
| 293 | - } |
|
| 294 | - $appSettings = $this->getSettings('admin', $section, $authorizedGroupFilter); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - $settings = []; |
|
| 298 | - foreach ($appSettings as $setting) { |
|
| 299 | - if (!isset($settings[$setting->getPriority()])) { |
|
| 300 | - $settings[$setting->getPriority()] = []; |
|
| 301 | - } |
|
| 302 | - $settings[$setting->getPriority()][] = $setting; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - ksort($settings); |
|
| 306 | - return $settings; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * @inheritdoc |
|
| 311 | - */ |
|
| 312 | - public function getAllAllowedAdminSettings(IUser $user): array { |
|
| 313 | - $this->getSettings('admin', ''); // Make sure all the settings are loaded |
|
| 314 | - $settings = []; |
|
| 315 | - $authorizedSettingsClasses = $this->mapper->findAllClassesForUser($user); |
|
| 316 | - foreach ($this->settings['admin'] as $section) { |
|
| 317 | - foreach ($section as $setting) { |
|
| 318 | - if (in_array(get_class($setting), $authorizedSettingsClasses) === true) { |
|
| 319 | - $settings[] = $setting; |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - return $settings; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @return array<string, array{section:IIconSection,settings:list<IDelegatedSettings>}> |
|
| 328 | - */ |
|
| 329 | - public function getAdminDelegatedSettings(): array { |
|
| 330 | - $sections = $this->getAdminSections(); |
|
| 331 | - $settings = []; |
|
| 332 | - foreach ($sections as $sectionPriority) { |
|
| 333 | - foreach ($sectionPriority as $section) { |
|
| 334 | - /** @var IDelegatedSettings[] */ |
|
| 335 | - $sectionSettings = array_merge( |
|
| 336 | - $this->getSettings(self::SETTINGS_ADMIN, $section->getID(), fn (ISettings $settings): bool => $settings instanceof IDelegatedSettings), |
|
| 337 | - $this->getSettings(self::SETTINGS_DELEGATION, $section->getID(), fn (ISettings $settings): bool => $settings instanceof IDelegatedSettings), |
|
| 338 | - ); |
|
| 339 | - usort( |
|
| 340 | - $sectionSettings, |
|
| 341 | - fn (ISettings $s1, ISettings $s2) => $s1->getPriority() <=> $s2->getPriority() |
|
| 342 | - ); |
|
| 343 | - $settings[$section->getID()] = [ |
|
| 344 | - 'section' => $section, |
|
| 345 | - 'settings' => $sectionSettings, |
|
| 346 | - ]; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - uasort($settings, fn (array $a, array $b) => $a['section']->getPriority() <=> $b['section']->getPriority()); |
|
| 350 | - return $settings; |
|
| 351 | - } |
|
| 27 | + private ?IL10N $l = null; |
|
| 28 | + |
|
| 29 | + /** @var array<self::SETTINGS_*, list<class-string<IIconSection>>> */ |
|
| 30 | + protected array $sectionClasses = []; |
|
| 31 | + |
|
| 32 | + /** @var array<self::SETTINGS_*, array<string, IIconSection>> */ |
|
| 33 | + protected array $sections = []; |
|
| 34 | + |
|
| 35 | + /** @var array<class-string<ISettings>, self::SETTINGS_*> */ |
|
| 36 | + protected array $settingClasses = []; |
|
| 37 | + |
|
| 38 | + /** @var array<self::SETTINGS_*, array<string, list<ISettings>>> */ |
|
| 39 | + protected array $settings = []; |
|
| 40 | + |
|
| 41 | + public function __construct( |
|
| 42 | + private LoggerInterface $log, |
|
| 43 | + private IFactory $l10nFactory, |
|
| 44 | + private IURLGenerator $url, |
|
| 45 | + private IServerContainer $container, |
|
| 46 | + private AuthorizedGroupMapper $mapper, |
|
| 47 | + private IGroupManager $groupManager, |
|
| 48 | + private ISubAdmin $subAdmin, |
|
| 49 | + ) { |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @inheritdoc |
|
| 54 | + */ |
|
| 55 | + public function registerSection(string $type, string $section) { |
|
| 56 | + if (!isset($this->sectionClasses[$type])) { |
|
| 57 | + $this->sectionClasses[$type] = []; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $this->sectionClasses[$type][] = $section; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @psalm-param self::SETTINGS_* $type |
|
| 65 | + * |
|
| 66 | + * @return IIconSection[] |
|
| 67 | + */ |
|
| 68 | + protected function getSections(string $type): array { |
|
| 69 | + if (!isset($this->sections[$type])) { |
|
| 70 | + $this->sections[$type] = []; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + if (!isset($this->sectionClasses[$type])) { |
|
| 74 | + return $this->sections[$type]; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + foreach (array_unique($this->sectionClasses[$type]) as $index => $class) { |
|
| 78 | + try { |
|
| 79 | + /** @var IIconSection $section */ |
|
| 80 | + $section = $this->container->get($class); |
|
| 81 | + } catch (QueryException $e) { |
|
| 82 | + $this->log->info($e->getMessage(), ['exception' => $e]); |
|
| 83 | + continue; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $sectionID = $section->getID(); |
|
| 87 | + |
|
| 88 | + if (!$this->isKnownDuplicateSectionId($sectionID) && isset($this->sections[$type][$sectionID])) { |
|
| 89 | + $e = new \InvalidArgumentException('Section with the same ID already registered: ' . $sectionID . ', class: ' . $class); |
|
| 90 | + $this->log->info($e->getMessage(), ['exception' => $e]); |
|
| 91 | + continue; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $this->sections[$type][$sectionID] = $section; |
|
| 95 | + |
|
| 96 | + unset($this->sectionClasses[$type][$index]); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return $this->sections[$type]; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @inheritdoc |
|
| 104 | + */ |
|
| 105 | + public function getSection(string $type, string $sectionId): ?IIconSection { |
|
| 106 | + if (isset($this->sections[$type]) && isset($this->sections[$type][$sectionId])) { |
|
| 107 | + return $this->sections[$type][$sectionId]; |
|
| 108 | + } |
|
| 109 | + return null; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + protected function isKnownDuplicateSectionId(string $sectionID): bool { |
|
| 113 | + return in_array($sectionID, [ |
|
| 114 | + 'connected-accounts', |
|
| 115 | + 'notifications', |
|
| 116 | + ], true); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @inheritdoc |
|
| 121 | + */ |
|
| 122 | + public function registerSetting(string $type, string $setting) { |
|
| 123 | + $this->settingClasses[$setting] = $type; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @psalm-param self::SETTINGS_* $type The type of the setting. |
|
| 128 | + * @param string $section |
|
| 129 | + * @param ?Closure $filter optional filter to apply on all loaded ISettings |
|
| 130 | + * |
|
| 131 | + * @return ISettings[] |
|
| 132 | + */ |
|
| 133 | + protected function getSettings(string $type, string $section, ?Closure $filter = null): array { |
|
| 134 | + if (!isset($this->settings[$type])) { |
|
| 135 | + $this->settings[$type] = []; |
|
| 136 | + } |
|
| 137 | + if (!isset($this->settings[$type][$section])) { |
|
| 138 | + $this->settings[$type][$section] = []; |
|
| 139 | + |
|
| 140 | + foreach ($this->settingClasses as $class => $settingsType) { |
|
| 141 | + if ($type !== $settingsType) { |
|
| 142 | + continue; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + try { |
|
| 146 | + /** @var ISettings $setting */ |
|
| 147 | + $setting = $this->container->get($class); |
|
| 148 | + } catch (QueryException $e) { |
|
| 149 | + $this->log->info($e->getMessage(), ['exception' => $e]); |
|
| 150 | + continue; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if (!$setting instanceof ISettings) { |
|
| 154 | + $e = new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'); |
|
| 155 | + $this->log->info($e->getMessage(), ['exception' => $e]); |
|
| 156 | + continue; |
|
| 157 | + } |
|
| 158 | + $settingSection = $setting->getSection(); |
|
| 159 | + if ($settingSection === null) { |
|
| 160 | + continue; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if (!isset($this->settings[$settingsType][$settingSection])) { |
|
| 164 | + $this->settings[$settingsType][$settingSection] = []; |
|
| 165 | + } |
|
| 166 | + $this->settings[$settingsType][$settingSection][] = $setting; |
|
| 167 | + |
|
| 168 | + unset($this->settingClasses[$class]); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($filter !== null) { |
|
| 173 | + return array_values(array_filter($this->settings[$type][$section], $filter)); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return $this->settings[$type][$section]; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @inheritdoc |
|
| 181 | + */ |
|
| 182 | + public function getAdminSections(): array { |
|
| 183 | + // built-in sections |
|
| 184 | + $sections = []; |
|
| 185 | + |
|
| 186 | + $appSections = $this->getSections('admin'); |
|
| 187 | + |
|
| 188 | + foreach ($appSections as $section) { |
|
| 189 | + /** @var IIconSection $section */ |
|
| 190 | + if (!isset($sections[$section->getPriority()])) { |
|
| 191 | + $sections[$section->getPriority()] = []; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $sections[$section->getPriority()][] = $section; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + ksort($sections); |
|
| 198 | + |
|
| 199 | + return $sections; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @inheritdoc |
|
| 204 | + */ |
|
| 205 | + public function getAdminSettings(string $section, bool $subAdminOnly = false): array { |
|
| 206 | + if ($subAdminOnly) { |
|
| 207 | + $subAdminSettingsFilter = function (ISettings $settings) { |
|
| 208 | + return $settings instanceof ISubAdminSettings; |
|
| 209 | + }; |
|
| 210 | + $appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter); |
|
| 211 | + } else { |
|
| 212 | + $appSettings = $this->getSettings('admin', $section); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $settings = []; |
|
| 216 | + foreach ($appSettings as $setting) { |
|
| 217 | + if (!isset($settings[$setting->getPriority()])) { |
|
| 218 | + $settings[$setting->getPriority()] = []; |
|
| 219 | + } |
|
| 220 | + $settings[$setting->getPriority()][] = $setting; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + ksort($settings); |
|
| 224 | + return $settings; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @inheritdoc |
|
| 229 | + */ |
|
| 230 | + public function getPersonalSections(): array { |
|
| 231 | + if ($this->l === null) { |
|
| 232 | + $this->l = $this->l10nFactory->get('lib'); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $sections = []; |
|
| 236 | + |
|
| 237 | + if (count($this->getPersonalSettings('additional')) > 1) { |
|
| 238 | + $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $appSections = $this->getSections('personal'); |
|
| 242 | + |
|
| 243 | + foreach ($appSections as $section) { |
|
| 244 | + /** @var IIconSection $section */ |
|
| 245 | + if (!isset($sections[$section->getPriority()])) { |
|
| 246 | + $sections[$section->getPriority()] = []; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $sections[$section->getPriority()][] = $section; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + ksort($sections); |
|
| 253 | + |
|
| 254 | + return $sections; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @inheritdoc |
|
| 259 | + */ |
|
| 260 | + public function getPersonalSettings(string $section): array { |
|
| 261 | + $settings = []; |
|
| 262 | + $appSettings = $this->getSettings('personal', $section); |
|
| 263 | + |
|
| 264 | + foreach ($appSettings as $setting) { |
|
| 265 | + if (!isset($settings[$setting->getPriority()])) { |
|
| 266 | + $settings[$setting->getPriority()] = []; |
|
| 267 | + } |
|
| 268 | + $settings[$setting->getPriority()][] = $setting; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + ksort($settings); |
|
| 272 | + return $settings; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @inheritdoc |
|
| 277 | + */ |
|
| 278 | + public function getAllowedAdminSettings(string $section, IUser $user): array { |
|
| 279 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 280 | + if ($isAdmin) { |
|
| 281 | + $appSettings = $this->getSettings('admin', $section); |
|
| 282 | + } else { |
|
| 283 | + $authorizedSettingsClasses = $this->mapper->findAllClassesForUser($user); |
|
| 284 | + if ($this->subAdmin->isSubAdmin($user)) { |
|
| 285 | + $authorizedGroupFilter = function (ISettings $settings) use ($authorizedSettingsClasses) { |
|
| 286 | + return $settings instanceof ISubAdminSettings |
|
| 287 | + || in_array(get_class($settings), $authorizedSettingsClasses) === true; |
|
| 288 | + }; |
|
| 289 | + } else { |
|
| 290 | + $authorizedGroupFilter = function (ISettings $settings) use ($authorizedSettingsClasses) { |
|
| 291 | + return in_array(get_class($settings), $authorizedSettingsClasses) === true; |
|
| 292 | + }; |
|
| 293 | + } |
|
| 294 | + $appSettings = $this->getSettings('admin', $section, $authorizedGroupFilter); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + $settings = []; |
|
| 298 | + foreach ($appSettings as $setting) { |
|
| 299 | + if (!isset($settings[$setting->getPriority()])) { |
|
| 300 | + $settings[$setting->getPriority()] = []; |
|
| 301 | + } |
|
| 302 | + $settings[$setting->getPriority()][] = $setting; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + ksort($settings); |
|
| 306 | + return $settings; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * @inheritdoc |
|
| 311 | + */ |
|
| 312 | + public function getAllAllowedAdminSettings(IUser $user): array { |
|
| 313 | + $this->getSettings('admin', ''); // Make sure all the settings are loaded |
|
| 314 | + $settings = []; |
|
| 315 | + $authorizedSettingsClasses = $this->mapper->findAllClassesForUser($user); |
|
| 316 | + foreach ($this->settings['admin'] as $section) { |
|
| 317 | + foreach ($section as $setting) { |
|
| 318 | + if (in_array(get_class($setting), $authorizedSettingsClasses) === true) { |
|
| 319 | + $settings[] = $setting; |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + return $settings; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @return array<string, array{section:IIconSection,settings:list<IDelegatedSettings>}> |
|
| 328 | + */ |
|
| 329 | + public function getAdminDelegatedSettings(): array { |
|
| 330 | + $sections = $this->getAdminSections(); |
|
| 331 | + $settings = []; |
|
| 332 | + foreach ($sections as $sectionPriority) { |
|
| 333 | + foreach ($sectionPriority as $section) { |
|
| 334 | + /** @var IDelegatedSettings[] */ |
|
| 335 | + $sectionSettings = array_merge( |
|
| 336 | + $this->getSettings(self::SETTINGS_ADMIN, $section->getID(), fn (ISettings $settings): bool => $settings instanceof IDelegatedSettings), |
|
| 337 | + $this->getSettings(self::SETTINGS_DELEGATION, $section->getID(), fn (ISettings $settings): bool => $settings instanceof IDelegatedSettings), |
|
| 338 | + ); |
|
| 339 | + usort( |
|
| 340 | + $sectionSettings, |
|
| 341 | + fn (ISettings $s1, ISettings $s2) => $s1->getPriority() <=> $s2->getPriority() |
|
| 342 | + ); |
|
| 343 | + $settings[$section->getID()] = [ |
|
| 344 | + 'section' => $section, |
|
| 345 | + 'settings' => $sectionSettings, |
|
| 346 | + ]; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + uasort($settings, fn (array $a, array $b) => $a['section']->getPriority() <=> $b['section']->getPriority()); |
|
| 350 | + return $settings; |
|
| 351 | + } |
|
| 352 | 352 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $sectionID = $section->getID(); |
| 87 | 87 | |
| 88 | 88 | if (!$this->isKnownDuplicateSectionId($sectionID) && isset($this->sections[$type][$sectionID])) { |
| 89 | - $e = new \InvalidArgumentException('Section with the same ID already registered: ' . $sectionID . ', class: ' . $class); |
|
| 89 | + $e = new \InvalidArgumentException('Section with the same ID already registered: '.$sectionID.', class: '.$class); |
|
| 90 | 90 | $this->log->info($e->getMessage(), ['exception' => $e]); |
| 91 | 91 | continue; |
| 92 | 92 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (!$setting instanceof ISettings) { |
| 154 | - $e = new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'); |
|
| 154 | + $e = new \InvalidArgumentException('Invalid settings setting registered ('.$class.')'); |
|
| 155 | 155 | $this->log->info($e->getMessage(), ['exception' => $e]); |
| 156 | 156 | continue; |
| 157 | 157 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function getAdminSettings(string $section, bool $subAdminOnly = false): array { |
| 206 | 206 | if ($subAdminOnly) { |
| 207 | - $subAdminSettingsFilter = function (ISettings $settings) { |
|
| 207 | + $subAdminSettingsFilter = function(ISettings $settings) { |
|
| 208 | 208 | return $settings instanceof ISubAdminSettings; |
| 209 | 209 | }; |
| 210 | 210 | $appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter); |
@@ -282,12 +282,12 @@ discard block |
||
| 282 | 282 | } else { |
| 283 | 283 | $authorizedSettingsClasses = $this->mapper->findAllClassesForUser($user); |
| 284 | 284 | if ($this->subAdmin->isSubAdmin($user)) { |
| 285 | - $authorizedGroupFilter = function (ISettings $settings) use ($authorizedSettingsClasses) { |
|
| 285 | + $authorizedGroupFilter = function(ISettings $settings) use ($authorizedSettingsClasses) { |
|
| 286 | 286 | return $settings instanceof ISubAdminSettings |
| 287 | 287 | || in_array(get_class($settings), $authorizedSettingsClasses) === true; |
| 288 | 288 | }; |
| 289 | 289 | } else { |
| 290 | - $authorizedGroupFilter = function (ISettings $settings) use ($authorizedSettingsClasses) { |
|
| 290 | + $authorizedGroupFilter = function(ISettings $settings) use ($authorizedSettingsClasses) { |
|
| 291 | 291 | return in_array(get_class($settings), $authorizedSettingsClasses) === true; |
| 292 | 292 | }; |
| 293 | 293 | } |
@@ -13,122 +13,122 @@ |
||
| 13 | 13 | * @since 9.1 |
| 14 | 14 | */ |
| 15 | 15 | interface IManager { |
| 16 | - /** |
|
| 17 | - * @since 9.1.0 |
|
| 18 | - * @deprecated 29.0.0 Use {@see self::SETTINGS_ADMIN} instead |
|
| 19 | - */ |
|
| 20 | - public const KEY_ADMIN_SETTINGS = 'admin'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @since 9.1.0 |
|
| 24 | - * @deprecated 29.0.0 Use {@see self::SETTINGS_ADMIN} instead |
|
| 25 | - */ |
|
| 26 | - public const KEY_ADMIN_SECTION = 'admin-section'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @since 13.0.0 |
|
| 30 | - * @deprecated 29.0.0 Use {@see self::SETTINGS_PERSONAL} instead |
|
| 31 | - */ |
|
| 32 | - public const KEY_PERSONAL_SETTINGS = 'personal'; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @since 13.0.0 |
|
| 36 | - * @deprecated 29.0.0 Use {@see self::SETTINGS_PERSONAL} instead |
|
| 37 | - */ |
|
| 38 | - public const KEY_PERSONAL_SECTION = 'personal-section'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @since 29.0.0 |
|
| 42 | - */ |
|
| 43 | - public const SETTINGS_ADMIN = 'admin'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @since 29.0.0 |
|
| 47 | - */ |
|
| 48 | - public const SETTINGS_PERSONAL = 'personal'; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @since 33.0.0 |
|
| 52 | - * For settings only used for delegation but not appearing in settings menu |
|
| 53 | - */ |
|
| 54 | - public const SETTINGS_DELEGATION = 'delegation'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @psalm-param self::SETTINGS_* $type |
|
| 58 | - * @param class-string<IIconSection> $section |
|
| 59 | - * @since 14.0.0 |
|
| 60 | - */ |
|
| 61 | - public function registerSection(string $type, string $section); |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @psalm-param self::SETTINGS_* $type |
|
| 65 | - * @param class-string<ISettings> $setting |
|
| 66 | - * @since 14.0.0 |
|
| 67 | - */ |
|
| 68 | - public function registerSetting(string $type, string $setting); |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * returns a list of the admin sections |
|
| 72 | - * |
|
| 73 | - * @return array<int, list<IIconSection>> list of sections with priority as key |
|
| 74 | - * @since 9.1.0 |
|
| 75 | - */ |
|
| 76 | - public function getAdminSections(): array; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * returns a list of the personal sections |
|
| 80 | - * |
|
| 81 | - * @return array<int, list<IIconSection>> list of sections with priority as key |
|
| 82 | - * @since 13.0.0 |
|
| 83 | - */ |
|
| 84 | - public function getPersonalSections(): array; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * returns a list of the admin settings |
|
| 88 | - * |
|
| 89 | - * @param string $section the section id for which to load the settings |
|
| 90 | - * @param bool $subAdminOnly only return settings sub admins are supposed to see (since 17.0.0) |
|
| 91 | - * @return array<int, list<ISettings>> list of settings with priority as key |
|
| 92 | - * @since 9.1.0 |
|
| 93 | - */ |
|
| 94 | - public function getAdminSettings(string $section, bool $subAdminOnly = false): array; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Returns a list of admin settings that the given user can use for the give section |
|
| 98 | - * |
|
| 99 | - * @return array<int, list<ISettings>> List of admin-settings the user has access to, with priority as key. |
|
| 100 | - * @since 23.0.0 |
|
| 101 | - */ |
|
| 102 | - public function getAllowedAdminSettings(string $section, IUser $user): array; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Returns a list of admin settings that the given user can use. |
|
| 106 | - * |
|
| 107 | - * @return list<ISettings> The array of admin settings there admin delegation is allowed. |
|
| 108 | - * @since 23.0.0 |
|
| 109 | - */ |
|
| 110 | - public function getAllAllowedAdminSettings(IUser $user): array; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * returns a list of the personal settings |
|
| 114 | - * |
|
| 115 | - * @param string $section the section id for which to load the settings |
|
| 116 | - * @return array<int, list<ISettings>> list of settings with priority as key |
|
| 117 | - * @since 13.0.0 |
|
| 118 | - */ |
|
| 119 | - public function getPersonalSettings(string $section): array; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Get a specific section by type and id |
|
| 123 | - * @psalm-param self::SETTINGS_* $type |
|
| 124 | - * @since 25.0.0 |
|
| 125 | - */ |
|
| 126 | - public function getSection(string $type, string $sectionId): ?IIconSection; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Return admin delegated settings, sorted by priority and grouped by section |
|
| 130 | - * @return array<string, array{section:IIconSection,settings:list<IDelegatedSettings>}> |
|
| 131 | - * @since 33.0.0 |
|
| 132 | - */ |
|
| 133 | - public function getAdminDelegatedSettings(): array; |
|
| 16 | + /** |
|
| 17 | + * @since 9.1.0 |
|
| 18 | + * @deprecated 29.0.0 Use {@see self::SETTINGS_ADMIN} instead |
|
| 19 | + */ |
|
| 20 | + public const KEY_ADMIN_SETTINGS = 'admin'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @since 9.1.0 |
|
| 24 | + * @deprecated 29.0.0 Use {@see self::SETTINGS_ADMIN} instead |
|
| 25 | + */ |
|
| 26 | + public const KEY_ADMIN_SECTION = 'admin-section'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @since 13.0.0 |
|
| 30 | + * @deprecated 29.0.0 Use {@see self::SETTINGS_PERSONAL} instead |
|
| 31 | + */ |
|
| 32 | + public const KEY_PERSONAL_SETTINGS = 'personal'; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @since 13.0.0 |
|
| 36 | + * @deprecated 29.0.0 Use {@see self::SETTINGS_PERSONAL} instead |
|
| 37 | + */ |
|
| 38 | + public const KEY_PERSONAL_SECTION = 'personal-section'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @since 29.0.0 |
|
| 42 | + */ |
|
| 43 | + public const SETTINGS_ADMIN = 'admin'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @since 29.0.0 |
|
| 47 | + */ |
|
| 48 | + public const SETTINGS_PERSONAL = 'personal'; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @since 33.0.0 |
|
| 52 | + * For settings only used for delegation but not appearing in settings menu |
|
| 53 | + */ |
|
| 54 | + public const SETTINGS_DELEGATION = 'delegation'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @psalm-param self::SETTINGS_* $type |
|
| 58 | + * @param class-string<IIconSection> $section |
|
| 59 | + * @since 14.0.0 |
|
| 60 | + */ |
|
| 61 | + public function registerSection(string $type, string $section); |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @psalm-param self::SETTINGS_* $type |
|
| 65 | + * @param class-string<ISettings> $setting |
|
| 66 | + * @since 14.0.0 |
|
| 67 | + */ |
|
| 68 | + public function registerSetting(string $type, string $setting); |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * returns a list of the admin sections |
|
| 72 | + * |
|
| 73 | + * @return array<int, list<IIconSection>> list of sections with priority as key |
|
| 74 | + * @since 9.1.0 |
|
| 75 | + */ |
|
| 76 | + public function getAdminSections(): array; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * returns a list of the personal sections |
|
| 80 | + * |
|
| 81 | + * @return array<int, list<IIconSection>> list of sections with priority as key |
|
| 82 | + * @since 13.0.0 |
|
| 83 | + */ |
|
| 84 | + public function getPersonalSections(): array; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * returns a list of the admin settings |
|
| 88 | + * |
|
| 89 | + * @param string $section the section id for which to load the settings |
|
| 90 | + * @param bool $subAdminOnly only return settings sub admins are supposed to see (since 17.0.0) |
|
| 91 | + * @return array<int, list<ISettings>> list of settings with priority as key |
|
| 92 | + * @since 9.1.0 |
|
| 93 | + */ |
|
| 94 | + public function getAdminSettings(string $section, bool $subAdminOnly = false): array; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Returns a list of admin settings that the given user can use for the give section |
|
| 98 | + * |
|
| 99 | + * @return array<int, list<ISettings>> List of admin-settings the user has access to, with priority as key. |
|
| 100 | + * @since 23.0.0 |
|
| 101 | + */ |
|
| 102 | + public function getAllowedAdminSettings(string $section, IUser $user): array; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Returns a list of admin settings that the given user can use. |
|
| 106 | + * |
|
| 107 | + * @return list<ISettings> The array of admin settings there admin delegation is allowed. |
|
| 108 | + * @since 23.0.0 |
|
| 109 | + */ |
|
| 110 | + public function getAllAllowedAdminSettings(IUser $user): array; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * returns a list of the personal settings |
|
| 114 | + * |
|
| 115 | + * @param string $section the section id for which to load the settings |
|
| 116 | + * @return array<int, list<ISettings>> list of settings with priority as key |
|
| 117 | + * @since 13.0.0 |
|
| 118 | + */ |
|
| 119 | + public function getPersonalSettings(string $section): array; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Get a specific section by type and id |
|
| 123 | + * @psalm-param self::SETTINGS_* $type |
|
| 124 | + * @since 25.0.0 |
|
| 125 | + */ |
|
| 126 | + public function getSection(string $type, string $sectionId): ?IIconSection; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Return admin delegated settings, sorted by priority and grouped by section |
|
| 130 | + * @return array<string, array{section:IIconSection,settings:list<IDelegatedSettings>}> |
|
| 131 | + * @since 33.0.0 |
|
| 132 | + */ |
|
| 133 | + public function getAdminDelegatedSettings(): array; |
|
| 134 | 134 | } |