@@ -29,16 +29,16 @@ |
||
29 | 29 | use OCP\Accounts\IAccountManager; |
30 | 30 | |
31 | 31 | trait TAccountsHelper { |
32 | - /** |
|
33 | - * returns whether the property is a collection |
|
34 | - */ |
|
35 | - protected function isCollection(string $propertyName): bool { |
|
36 | - return in_array( |
|
37 | - $propertyName, |
|
38 | - [ |
|
39 | - IAccountManager::COLLECTION_EMAIL, |
|
40 | - ], |
|
41 | - true |
|
42 | - ); |
|
43 | - } |
|
32 | + /** |
|
33 | + * returns whether the property is a collection |
|
34 | + */ |
|
35 | + protected function isCollection(string $propertyName): bool { |
|
36 | + return in_array( |
|
37 | + $propertyName, |
|
38 | + [ |
|
39 | + IAccountManager::COLLECTION_EMAIL, |
|
40 | + ], |
|
41 | + true |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | } |
@@ -151,14 +151,14 @@ discard block |
||
151 | 151 | foreach ($releases as $release) { |
152 | 152 | $versions[] = $release['version']; |
153 | 153 | } |
154 | - usort($versions, function ($version1, $version2) { |
|
154 | + usort($versions, function($version1, $version2) { |
|
155 | 155 | return version_compare($version1, $version2); |
156 | 156 | }); |
157 | 157 | $versions = array_reverse($versions); |
158 | 158 | if (isset($versions[0])) { |
159 | 159 | $highestVersion = $versions[0]; |
160 | 160 | foreach ($releases as $release) { |
161 | - if ((string)$release['version'] === (string)$highestVersion) { |
|
161 | + if ((string) $release['version'] === (string) $highestVersion) { |
|
162 | 162 | $response['data'][$dataKey]['releases'] = [$release]; |
163 | 163 | break; |
164 | 164 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | // If the admin specified a allow list, filter apps from the appstore |
190 | 190 | if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { |
191 | - return array_filter($apps, function ($app) use ($allowList) { |
|
191 | + return array_filter($apps, function($app) use ($allowList) { |
|
192 | 192 | return in_array($app['id'], $allowList); |
193 | 193 | }); |
194 | 194 | } |
@@ -16,157 +16,157 @@ |
||
16 | 16 | use Psr\Log\LoggerInterface; |
17 | 17 | |
18 | 18 | class AppFetcher extends Fetcher { |
19 | - /** @var bool */ |
|
20 | - private $ignoreMaxVersion; |
|
21 | - |
|
22 | - public function __construct( |
|
23 | - Factory $appDataFactory, |
|
24 | - IClientService $clientService, |
|
25 | - ITimeFactory $timeFactory, |
|
26 | - IConfig $config, |
|
27 | - private CompareVersion $compareVersion, |
|
28 | - LoggerInterface $logger, |
|
29 | - protected IRegistry $registry, |
|
30 | - ) { |
|
31 | - parent::__construct( |
|
32 | - $appDataFactory, |
|
33 | - $clientService, |
|
34 | - $timeFactory, |
|
35 | - $config, |
|
36 | - $logger, |
|
37 | - $registry |
|
38 | - ); |
|
39 | - |
|
40 | - $this->fileName = 'apps.json'; |
|
41 | - $this->endpointName = 'apps.json'; |
|
42 | - $this->ignoreMaxVersion = true; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Only returns the latest compatible app release in the releases array |
|
47 | - * |
|
48 | - * @param string $ETag |
|
49 | - * @param string $content |
|
50 | - * @param bool [$allowUnstable] Allow unstable releases |
|
51 | - * |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - protected function fetch($ETag, $content, $allowUnstable = false) { |
|
55 | - /** @var mixed[] $response */ |
|
56 | - $response = parent::fetch($ETag, $content); |
|
57 | - |
|
58 | - if (!isset($response['data']) || $response['data'] === null) { |
|
59 | - $this->logger->warning('Response from appstore is invalid, apps could not be retrieved. Try again later.', ['app' => 'appstoreFetcher']); |
|
60 | - return []; |
|
61 | - } |
|
62 | - |
|
63 | - $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
64 | - $allowNightly = $allowUnstable || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
65 | - |
|
66 | - foreach ($response['data'] as $dataKey => $app) { |
|
67 | - $releases = []; |
|
68 | - |
|
69 | - // Filter all compatible releases |
|
70 | - foreach ($app['releases'] as $release) { |
|
71 | - // Exclude all nightly and pre-releases if required |
|
72 | - if (($allowNightly || $release['isNightly'] === false) |
|
73 | - && ($allowPreReleases || !str_contains($release['version'], '-'))) { |
|
74 | - // Exclude all versions not compatible with the current version |
|
75 | - try { |
|
76 | - $versionParser = new VersionParser(); |
|
77 | - $serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
78 | - $ncVersion = $this->getVersion(); |
|
79 | - $minServerVersion = $serverVersion->getMinimumVersion(); |
|
80 | - $maxServerVersion = $serverVersion->getMaximumVersion(); |
|
81 | - $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>='); |
|
82 | - $maxFulfilled = $maxServerVersion !== '' |
|
83 | - && $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<='); |
|
84 | - $isPhpCompatible = true; |
|
85 | - if (($release['rawPhpVersionSpec'] ?? '*') !== '*') { |
|
86 | - $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']); |
|
87 | - $minPhpVersion = $phpVersion->getMinimumVersion(); |
|
88 | - $maxPhpVersion = $phpVersion->getMaximumVersion(); |
|
89 | - $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible( |
|
90 | - PHP_VERSION, |
|
91 | - $minPhpVersion, |
|
92 | - '>=' |
|
93 | - ); |
|
94 | - $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible( |
|
95 | - PHP_VERSION, |
|
96 | - $maxPhpVersion, |
|
97 | - '<=' |
|
98 | - ); |
|
99 | - |
|
100 | - $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled; |
|
101 | - } |
|
102 | - if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) { |
|
103 | - $releases[] = $release; |
|
104 | - } |
|
105 | - } catch (\InvalidArgumentException $e) { |
|
106 | - $this->logger->warning($e->getMessage(), [ |
|
107 | - 'exception' => $e, |
|
108 | - ]); |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - if (empty($releases)) { |
|
114 | - // Remove apps that don't have a matching release |
|
115 | - $response['data'][$dataKey] = []; |
|
116 | - continue; |
|
117 | - } |
|
118 | - |
|
119 | - // Get the highest version |
|
120 | - $versions = []; |
|
121 | - foreach ($releases as $release) { |
|
122 | - $versions[] = $release['version']; |
|
123 | - } |
|
124 | - usort($versions, function ($version1, $version2) { |
|
125 | - return version_compare($version1, $version2); |
|
126 | - }); |
|
127 | - $versions = array_reverse($versions); |
|
128 | - if (isset($versions[0])) { |
|
129 | - $highestVersion = $versions[0]; |
|
130 | - foreach ($releases as $release) { |
|
131 | - if ((string)$release['version'] === (string)$highestVersion) { |
|
132 | - $response['data'][$dataKey]['releases'] = [$release]; |
|
133 | - break; |
|
134 | - } |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - $response['data'] = array_values(array_filter($response['data'])); |
|
140 | - return $response; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param string $version |
|
145 | - * @param string $fileName |
|
146 | - * @param bool $ignoreMaxVersion |
|
147 | - */ |
|
148 | - public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) { |
|
149 | - parent::setVersion($version); |
|
150 | - $this->fileName = $fileName; |
|
151 | - $this->ignoreMaxVersion = $ignoreMaxVersion; |
|
152 | - } |
|
153 | - |
|
154 | - public function get($allowUnstable = false): array { |
|
155 | - $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
156 | - |
|
157 | - $apps = parent::get($allowPreReleases); |
|
158 | - if (empty($apps)) { |
|
159 | - return []; |
|
160 | - } |
|
161 | - $allowList = $this->config->getSystemValue('appsallowlist'); |
|
162 | - |
|
163 | - // If the admin specified a allow list, filter apps from the appstore |
|
164 | - if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { |
|
165 | - return array_filter($apps, function ($app) use ($allowList) { |
|
166 | - return in_array($app['id'], $allowList); |
|
167 | - }); |
|
168 | - } |
|
169 | - |
|
170 | - return $apps; |
|
171 | - } |
|
19 | + /** @var bool */ |
|
20 | + private $ignoreMaxVersion; |
|
21 | + |
|
22 | + public function __construct( |
|
23 | + Factory $appDataFactory, |
|
24 | + IClientService $clientService, |
|
25 | + ITimeFactory $timeFactory, |
|
26 | + IConfig $config, |
|
27 | + private CompareVersion $compareVersion, |
|
28 | + LoggerInterface $logger, |
|
29 | + protected IRegistry $registry, |
|
30 | + ) { |
|
31 | + parent::__construct( |
|
32 | + $appDataFactory, |
|
33 | + $clientService, |
|
34 | + $timeFactory, |
|
35 | + $config, |
|
36 | + $logger, |
|
37 | + $registry |
|
38 | + ); |
|
39 | + |
|
40 | + $this->fileName = 'apps.json'; |
|
41 | + $this->endpointName = 'apps.json'; |
|
42 | + $this->ignoreMaxVersion = true; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Only returns the latest compatible app release in the releases array |
|
47 | + * |
|
48 | + * @param string $ETag |
|
49 | + * @param string $content |
|
50 | + * @param bool [$allowUnstable] Allow unstable releases |
|
51 | + * |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + protected function fetch($ETag, $content, $allowUnstable = false) { |
|
55 | + /** @var mixed[] $response */ |
|
56 | + $response = parent::fetch($ETag, $content); |
|
57 | + |
|
58 | + if (!isset($response['data']) || $response['data'] === null) { |
|
59 | + $this->logger->warning('Response from appstore is invalid, apps could not be retrieved. Try again later.', ['app' => 'appstoreFetcher']); |
|
60 | + return []; |
|
61 | + } |
|
62 | + |
|
63 | + $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
64 | + $allowNightly = $allowUnstable || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
65 | + |
|
66 | + foreach ($response['data'] as $dataKey => $app) { |
|
67 | + $releases = []; |
|
68 | + |
|
69 | + // Filter all compatible releases |
|
70 | + foreach ($app['releases'] as $release) { |
|
71 | + // Exclude all nightly and pre-releases if required |
|
72 | + if (($allowNightly || $release['isNightly'] === false) |
|
73 | + && ($allowPreReleases || !str_contains($release['version'], '-'))) { |
|
74 | + // Exclude all versions not compatible with the current version |
|
75 | + try { |
|
76 | + $versionParser = new VersionParser(); |
|
77 | + $serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
78 | + $ncVersion = $this->getVersion(); |
|
79 | + $minServerVersion = $serverVersion->getMinimumVersion(); |
|
80 | + $maxServerVersion = $serverVersion->getMaximumVersion(); |
|
81 | + $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>='); |
|
82 | + $maxFulfilled = $maxServerVersion !== '' |
|
83 | + && $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<='); |
|
84 | + $isPhpCompatible = true; |
|
85 | + if (($release['rawPhpVersionSpec'] ?? '*') !== '*') { |
|
86 | + $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']); |
|
87 | + $minPhpVersion = $phpVersion->getMinimumVersion(); |
|
88 | + $maxPhpVersion = $phpVersion->getMaximumVersion(); |
|
89 | + $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible( |
|
90 | + PHP_VERSION, |
|
91 | + $minPhpVersion, |
|
92 | + '>=' |
|
93 | + ); |
|
94 | + $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible( |
|
95 | + PHP_VERSION, |
|
96 | + $maxPhpVersion, |
|
97 | + '<=' |
|
98 | + ); |
|
99 | + |
|
100 | + $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled; |
|
101 | + } |
|
102 | + if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) { |
|
103 | + $releases[] = $release; |
|
104 | + } |
|
105 | + } catch (\InvalidArgumentException $e) { |
|
106 | + $this->logger->warning($e->getMessage(), [ |
|
107 | + 'exception' => $e, |
|
108 | + ]); |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + if (empty($releases)) { |
|
114 | + // Remove apps that don't have a matching release |
|
115 | + $response['data'][$dataKey] = []; |
|
116 | + continue; |
|
117 | + } |
|
118 | + |
|
119 | + // Get the highest version |
|
120 | + $versions = []; |
|
121 | + foreach ($releases as $release) { |
|
122 | + $versions[] = $release['version']; |
|
123 | + } |
|
124 | + usort($versions, function ($version1, $version2) { |
|
125 | + return version_compare($version1, $version2); |
|
126 | + }); |
|
127 | + $versions = array_reverse($versions); |
|
128 | + if (isset($versions[0])) { |
|
129 | + $highestVersion = $versions[0]; |
|
130 | + foreach ($releases as $release) { |
|
131 | + if ((string)$release['version'] === (string)$highestVersion) { |
|
132 | + $response['data'][$dataKey]['releases'] = [$release]; |
|
133 | + break; |
|
134 | + } |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + $response['data'] = array_values(array_filter($response['data'])); |
|
140 | + return $response; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param string $version |
|
145 | + * @param string $fileName |
|
146 | + * @param bool $ignoreMaxVersion |
|
147 | + */ |
|
148 | + public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) { |
|
149 | + parent::setVersion($version); |
|
150 | + $this->fileName = $fileName; |
|
151 | + $this->ignoreMaxVersion = $ignoreMaxVersion; |
|
152 | + } |
|
153 | + |
|
154 | + public function get($allowUnstable = false): array { |
|
155 | + $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
156 | + |
|
157 | + $apps = parent::get($allowPreReleases); |
|
158 | + if (empty($apps)) { |
|
159 | + return []; |
|
160 | + } |
|
161 | + $allowList = $this->config->getSystemValue('appsallowlist'); |
|
162 | + |
|
163 | + // If the admin specified a allow list, filter apps from the appstore |
|
164 | + if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { |
|
165 | + return array_filter($apps, function ($app) use ($allowList) { |
|
166 | + return in_array($app['id'], $allowList); |
|
167 | + }); |
|
168 | + } |
|
169 | + |
|
170 | + return $apps; |
|
171 | + } |
|
172 | 172 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | } |
55 | 55 | |
56 | 56 | if ($this->cache !== null) { |
57 | - $fileCacheKey = $file . filemtime($file); |
|
57 | + $fileCacheKey = $file.filemtime($file); |
|
58 | 58 | if ($cachedValue = $this->cache->get($fileCacheKey)) { |
59 | 59 | return json_decode($cachedValue, true); |
60 | 60 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function xmlToArray($xml) { |
236 | 236 | if (!$xml->children()) { |
237 | - return (string)$xml; |
|
237 | + return (string) $xml; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | $array = []; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | '@attributes' => [], |
252 | 252 | ]; |
253 | 253 | if (!count($node->children())) { |
254 | - $value = (string)$node; |
|
254 | + $value = (string) $node; |
|
255 | 255 | if (!empty($value)) { |
256 | 256 | $data['@value'] = $value; |
257 | 257 | } |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $data = array_merge($data, $this->xmlToArray($node)); |
260 | 260 | } |
261 | 261 | foreach ($attributes as $attr => $value) { |
262 | - $data['@attributes'][$attr] = (string)$value; |
|
262 | + $data['@attributes'][$attr] = (string) $value; |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | if ($totalElement > 1) { |
@@ -10,265 +10,265 @@ |
||
10 | 10 | use function simplexml_load_string; |
11 | 11 | |
12 | 12 | class InfoParser { |
13 | - /** |
|
14 | - * @param ICache|null $cache |
|
15 | - */ |
|
16 | - public function __construct( |
|
17 | - private ?ICache $cache = null, |
|
18 | - ) { |
|
19 | - } |
|
13 | + /** |
|
14 | + * @param ICache|null $cache |
|
15 | + */ |
|
16 | + public function __construct( |
|
17 | + private ?ICache $cache = null, |
|
18 | + ) { |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $file the xml file to be loaded |
|
23 | - * @return null|array where null is an indicator for an error |
|
24 | - */ |
|
25 | - public function parse($file) { |
|
26 | - if (!file_exists($file)) { |
|
27 | - return null; |
|
28 | - } |
|
21 | + /** |
|
22 | + * @param string $file the xml file to be loaded |
|
23 | + * @return null|array where null is an indicator for an error |
|
24 | + */ |
|
25 | + public function parse($file) { |
|
26 | + if (!file_exists($file)) { |
|
27 | + return null; |
|
28 | + } |
|
29 | 29 | |
30 | - if ($this->cache !== null) { |
|
31 | - $fileCacheKey = $file . filemtime($file); |
|
32 | - if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
33 | - return json_decode($cachedValue, true); |
|
34 | - } |
|
35 | - } |
|
30 | + if ($this->cache !== null) { |
|
31 | + $fileCacheKey = $file . filemtime($file); |
|
32 | + if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
33 | + return json_decode($cachedValue, true); |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | - libxml_use_internal_errors(true); |
|
38 | - $xml = simplexml_load_string(file_get_contents($file)); |
|
37 | + libxml_use_internal_errors(true); |
|
38 | + $xml = simplexml_load_string(file_get_contents($file)); |
|
39 | 39 | |
40 | - if ($xml === false) { |
|
41 | - libxml_clear_errors(); |
|
42 | - return null; |
|
43 | - } |
|
44 | - $array = $this->xmlToArray($xml); |
|
40 | + if ($xml === false) { |
|
41 | + libxml_clear_errors(); |
|
42 | + return null; |
|
43 | + } |
|
44 | + $array = $this->xmlToArray($xml); |
|
45 | 45 | |
46 | - if (is_null($array)) { |
|
47 | - return null; |
|
48 | - } |
|
46 | + if (is_null($array)) { |
|
47 | + return null; |
|
48 | + } |
|
49 | 49 | |
50 | - if (!array_key_exists('info', $array)) { |
|
51 | - $array['info'] = []; |
|
52 | - } |
|
53 | - if (!array_key_exists('remote', $array)) { |
|
54 | - $array['remote'] = []; |
|
55 | - } |
|
56 | - if (!array_key_exists('public', $array)) { |
|
57 | - $array['public'] = []; |
|
58 | - } |
|
59 | - if (!array_key_exists('types', $array)) { |
|
60 | - $array['types'] = []; |
|
61 | - } |
|
62 | - if (!array_key_exists('repair-steps', $array)) { |
|
63 | - $array['repair-steps'] = []; |
|
64 | - } |
|
65 | - if (!array_key_exists('install', $array['repair-steps'])) { |
|
66 | - $array['repair-steps']['install'] = []; |
|
67 | - } |
|
68 | - if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
69 | - $array['repair-steps']['pre-migration'] = []; |
|
70 | - } |
|
71 | - if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
72 | - $array['repair-steps']['post-migration'] = []; |
|
73 | - } |
|
74 | - if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
75 | - $array['repair-steps']['live-migration'] = []; |
|
76 | - } |
|
77 | - if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
78 | - $array['repair-steps']['uninstall'] = []; |
|
79 | - } |
|
80 | - if (!array_key_exists('background-jobs', $array)) { |
|
81 | - $array['background-jobs'] = []; |
|
82 | - } |
|
83 | - if (!array_key_exists('two-factor-providers', $array)) { |
|
84 | - $array['two-factor-providers'] = []; |
|
85 | - } |
|
86 | - if (!array_key_exists('commands', $array)) { |
|
87 | - $array['commands'] = []; |
|
88 | - } |
|
89 | - if (!array_key_exists('activity', $array)) { |
|
90 | - $array['activity'] = []; |
|
91 | - } |
|
92 | - if (!array_key_exists('filters', $array['activity'])) { |
|
93 | - $array['activity']['filters'] = []; |
|
94 | - } |
|
95 | - if (!array_key_exists('settings', $array['activity'])) { |
|
96 | - $array['activity']['settings'] = []; |
|
97 | - } |
|
98 | - if (!array_key_exists('providers', $array['activity'])) { |
|
99 | - $array['activity']['providers'] = []; |
|
100 | - } |
|
101 | - if (!array_key_exists('settings', $array)) { |
|
102 | - $array['settings'] = []; |
|
103 | - } |
|
104 | - if (!array_key_exists('admin', $array['settings'])) { |
|
105 | - $array['settings']['admin'] = []; |
|
106 | - } |
|
107 | - if (!array_key_exists('admin-section', $array['settings'])) { |
|
108 | - $array['settings']['admin-section'] = []; |
|
109 | - } |
|
110 | - if (!array_key_exists('personal', $array['settings'])) { |
|
111 | - $array['settings']['personal'] = []; |
|
112 | - } |
|
113 | - if (!array_key_exists('personal-section', $array['settings'])) { |
|
114 | - $array['settings']['personal-section'] = []; |
|
115 | - } |
|
116 | - if (!array_key_exists('dependencies', $array)) { |
|
117 | - $array['dependencies'] = []; |
|
118 | - } |
|
119 | - if (!array_key_exists('backend', $array['dependencies'])) { |
|
120 | - $array['dependencies']['backend'] = []; |
|
121 | - } |
|
50 | + if (!array_key_exists('info', $array)) { |
|
51 | + $array['info'] = []; |
|
52 | + } |
|
53 | + if (!array_key_exists('remote', $array)) { |
|
54 | + $array['remote'] = []; |
|
55 | + } |
|
56 | + if (!array_key_exists('public', $array)) { |
|
57 | + $array['public'] = []; |
|
58 | + } |
|
59 | + if (!array_key_exists('types', $array)) { |
|
60 | + $array['types'] = []; |
|
61 | + } |
|
62 | + if (!array_key_exists('repair-steps', $array)) { |
|
63 | + $array['repair-steps'] = []; |
|
64 | + } |
|
65 | + if (!array_key_exists('install', $array['repair-steps'])) { |
|
66 | + $array['repair-steps']['install'] = []; |
|
67 | + } |
|
68 | + if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
69 | + $array['repair-steps']['pre-migration'] = []; |
|
70 | + } |
|
71 | + if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
72 | + $array['repair-steps']['post-migration'] = []; |
|
73 | + } |
|
74 | + if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
75 | + $array['repair-steps']['live-migration'] = []; |
|
76 | + } |
|
77 | + if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
78 | + $array['repair-steps']['uninstall'] = []; |
|
79 | + } |
|
80 | + if (!array_key_exists('background-jobs', $array)) { |
|
81 | + $array['background-jobs'] = []; |
|
82 | + } |
|
83 | + if (!array_key_exists('two-factor-providers', $array)) { |
|
84 | + $array['two-factor-providers'] = []; |
|
85 | + } |
|
86 | + if (!array_key_exists('commands', $array)) { |
|
87 | + $array['commands'] = []; |
|
88 | + } |
|
89 | + if (!array_key_exists('activity', $array)) { |
|
90 | + $array['activity'] = []; |
|
91 | + } |
|
92 | + if (!array_key_exists('filters', $array['activity'])) { |
|
93 | + $array['activity']['filters'] = []; |
|
94 | + } |
|
95 | + if (!array_key_exists('settings', $array['activity'])) { |
|
96 | + $array['activity']['settings'] = []; |
|
97 | + } |
|
98 | + if (!array_key_exists('providers', $array['activity'])) { |
|
99 | + $array['activity']['providers'] = []; |
|
100 | + } |
|
101 | + if (!array_key_exists('settings', $array)) { |
|
102 | + $array['settings'] = []; |
|
103 | + } |
|
104 | + if (!array_key_exists('admin', $array['settings'])) { |
|
105 | + $array['settings']['admin'] = []; |
|
106 | + } |
|
107 | + if (!array_key_exists('admin-section', $array['settings'])) { |
|
108 | + $array['settings']['admin-section'] = []; |
|
109 | + } |
|
110 | + if (!array_key_exists('personal', $array['settings'])) { |
|
111 | + $array['settings']['personal'] = []; |
|
112 | + } |
|
113 | + if (!array_key_exists('personal-section', $array['settings'])) { |
|
114 | + $array['settings']['personal-section'] = []; |
|
115 | + } |
|
116 | + if (!array_key_exists('dependencies', $array)) { |
|
117 | + $array['dependencies'] = []; |
|
118 | + } |
|
119 | + if (!array_key_exists('backend', $array['dependencies'])) { |
|
120 | + $array['dependencies']['backend'] = []; |
|
121 | + } |
|
122 | 122 | |
123 | - if (array_key_exists('types', $array)) { |
|
124 | - if (is_array($array['types'])) { |
|
125 | - foreach ($array['types'] as $type => $v) { |
|
126 | - unset($array['types'][$type]); |
|
127 | - if (is_string($type)) { |
|
128 | - $array['types'][] = $type; |
|
129 | - } |
|
130 | - } |
|
131 | - } else { |
|
132 | - $array['types'] = []; |
|
133 | - } |
|
134 | - } |
|
135 | - if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
136 | - $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
137 | - } |
|
138 | - if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
139 | - $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
140 | - } |
|
141 | - if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
142 | - $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
143 | - } |
|
144 | - if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
145 | - $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
146 | - } |
|
147 | - if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
148 | - $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
149 | - } |
|
150 | - if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
151 | - $array['background-jobs'] = $array['background-jobs']['job']; |
|
152 | - } |
|
153 | - if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
154 | - $array['commands'] = $array['commands']['command']; |
|
155 | - } |
|
156 | - if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) { |
|
157 | - $array['two-factor-providers'] = $array['two-factor-providers']['provider']; |
|
158 | - } |
|
159 | - if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
160 | - $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
161 | - } |
|
162 | - if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
163 | - $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
164 | - } |
|
165 | - if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
166 | - $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
167 | - } |
|
168 | - if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
169 | - && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
170 | - && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
171 | - ) { |
|
172 | - $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
173 | - } |
|
174 | - if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) { |
|
175 | - $array['settings']['admin'] = [$array['settings']['admin']]; |
|
176 | - } |
|
177 | - if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) { |
|
178 | - $array['settings']['admin-section'] = [$array['settings']['admin-section']]; |
|
179 | - } |
|
180 | - if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) { |
|
181 | - $array['settings']['personal'] = [$array['settings']['personal']]; |
|
182 | - } |
|
183 | - if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) { |
|
184 | - $array['settings']['personal-section'] = [$array['settings']['personal-section']]; |
|
185 | - } |
|
186 | - if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { |
|
187 | - $array['navigations']['navigation'] = [$array['navigations']['navigation']]; |
|
188 | - } |
|
189 | - if (isset($array['dependencies']['backend']) && !is_array($array['dependencies']['backend'])) { |
|
190 | - $array['dependencies']['backend'] = [$array['dependencies']['backend']]; |
|
191 | - } |
|
123 | + if (array_key_exists('types', $array)) { |
|
124 | + if (is_array($array['types'])) { |
|
125 | + foreach ($array['types'] as $type => $v) { |
|
126 | + unset($array['types'][$type]); |
|
127 | + if (is_string($type)) { |
|
128 | + $array['types'][] = $type; |
|
129 | + } |
|
130 | + } |
|
131 | + } else { |
|
132 | + $array['types'] = []; |
|
133 | + } |
|
134 | + } |
|
135 | + if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
136 | + $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
137 | + } |
|
138 | + if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
139 | + $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
140 | + } |
|
141 | + if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
142 | + $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
143 | + } |
|
144 | + if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
145 | + $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
146 | + } |
|
147 | + if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
148 | + $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
149 | + } |
|
150 | + if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
151 | + $array['background-jobs'] = $array['background-jobs']['job']; |
|
152 | + } |
|
153 | + if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
154 | + $array['commands'] = $array['commands']['command']; |
|
155 | + } |
|
156 | + if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) { |
|
157 | + $array['two-factor-providers'] = $array['two-factor-providers']['provider']; |
|
158 | + } |
|
159 | + if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
160 | + $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
161 | + } |
|
162 | + if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
163 | + $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
164 | + } |
|
165 | + if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
166 | + $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
167 | + } |
|
168 | + if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
169 | + && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
170 | + && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
171 | + ) { |
|
172 | + $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
173 | + } |
|
174 | + if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) { |
|
175 | + $array['settings']['admin'] = [$array['settings']['admin']]; |
|
176 | + } |
|
177 | + if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) { |
|
178 | + $array['settings']['admin-section'] = [$array['settings']['admin-section']]; |
|
179 | + } |
|
180 | + if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) { |
|
181 | + $array['settings']['personal'] = [$array['settings']['personal']]; |
|
182 | + } |
|
183 | + if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) { |
|
184 | + $array['settings']['personal-section'] = [$array['settings']['personal-section']]; |
|
185 | + } |
|
186 | + if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { |
|
187 | + $array['navigations']['navigation'] = [$array['navigations']['navigation']]; |
|
188 | + } |
|
189 | + if (isset($array['dependencies']['backend']) && !is_array($array['dependencies']['backend'])) { |
|
190 | + $array['dependencies']['backend'] = [$array['dependencies']['backend']]; |
|
191 | + } |
|
192 | 192 | |
193 | - // Ensure some fields are always arrays |
|
194 | - if (isset($array['screenshot']) && !is_array($array['screenshot'])) { |
|
195 | - $array['screenshot'] = [$array['screenshot']]; |
|
196 | - } |
|
197 | - if (isset($array['author']) && !is_array($array['author'])) { |
|
198 | - $array['author'] = [$array['author']]; |
|
199 | - } |
|
200 | - if (isset($array['category']) && !is_array($array['category'])) { |
|
201 | - $array['category'] = [$array['category']]; |
|
202 | - } |
|
193 | + // Ensure some fields are always arrays |
|
194 | + if (isset($array['screenshot']) && !is_array($array['screenshot'])) { |
|
195 | + $array['screenshot'] = [$array['screenshot']]; |
|
196 | + } |
|
197 | + if (isset($array['author']) && !is_array($array['author'])) { |
|
198 | + $array['author'] = [$array['author']]; |
|
199 | + } |
|
200 | + if (isset($array['category']) && !is_array($array['category'])) { |
|
201 | + $array['category'] = [$array['category']]; |
|
202 | + } |
|
203 | 203 | |
204 | - if ($this->cache !== null) { |
|
205 | - $this->cache->set($fileCacheKey, json_encode($array)); |
|
206 | - } |
|
207 | - return $array; |
|
208 | - } |
|
204 | + if ($this->cache !== null) { |
|
205 | + $this->cache->set($fileCacheKey, json_encode($array)); |
|
206 | + } |
|
207 | + return $array; |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * @param $data |
|
212 | - * @return bool |
|
213 | - */ |
|
214 | - private function isNavigationItem($data): bool { |
|
215 | - // Allow settings navigation items with no route entry |
|
216 | - $type = $data['type'] ?? 'link'; |
|
217 | - if ($type === 'settings') { |
|
218 | - return isset($data['name']); |
|
219 | - } |
|
220 | - return isset($data['name'], $data['route']); |
|
221 | - } |
|
210 | + /** |
|
211 | + * @param $data |
|
212 | + * @return bool |
|
213 | + */ |
|
214 | + private function isNavigationItem($data): bool { |
|
215 | + // Allow settings navigation items with no route entry |
|
216 | + $type = $data['type'] ?? 'link'; |
|
217 | + if ($type === 'settings') { |
|
218 | + return isset($data['name']); |
|
219 | + } |
|
220 | + return isset($data['name'], $data['route']); |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * @param \SimpleXMLElement $xml |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - public function xmlToArray($xml) { |
|
228 | - if (!$xml->children()) { |
|
229 | - return (string)$xml; |
|
230 | - } |
|
223 | + /** |
|
224 | + * @param \SimpleXMLElement $xml |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + public function xmlToArray($xml) { |
|
228 | + if (!$xml->children()) { |
|
229 | + return (string)$xml; |
|
230 | + } |
|
231 | 231 | |
232 | - $array = []; |
|
233 | - foreach ($xml->children() as $element => $node) { |
|
234 | - $totalElement = count($xml->{$element}); |
|
232 | + $array = []; |
|
233 | + foreach ($xml->children() as $element => $node) { |
|
234 | + $totalElement = count($xml->{$element}); |
|
235 | 235 | |
236 | - if (!isset($array[$element])) { |
|
237 | - $array[$element] = $totalElement > 1 ? [] : ''; |
|
238 | - } |
|
239 | - /** @var \SimpleXMLElement $node */ |
|
240 | - // Has attributes |
|
241 | - if ($attributes = $node->attributes()) { |
|
242 | - $data = [ |
|
243 | - '@attributes' => [], |
|
244 | - ]; |
|
245 | - if (!count($node->children())) { |
|
246 | - $value = (string)$node; |
|
247 | - if (!empty($value)) { |
|
248 | - $data['@value'] = $value; |
|
249 | - } |
|
250 | - } else { |
|
251 | - $data = array_merge($data, $this->xmlToArray($node)); |
|
252 | - } |
|
253 | - foreach ($attributes as $attr => $value) { |
|
254 | - $data['@attributes'][$attr] = (string)$value; |
|
255 | - } |
|
236 | + if (!isset($array[$element])) { |
|
237 | + $array[$element] = $totalElement > 1 ? [] : ''; |
|
238 | + } |
|
239 | + /** @var \SimpleXMLElement $node */ |
|
240 | + // Has attributes |
|
241 | + if ($attributes = $node->attributes()) { |
|
242 | + $data = [ |
|
243 | + '@attributes' => [], |
|
244 | + ]; |
|
245 | + if (!count($node->children())) { |
|
246 | + $value = (string)$node; |
|
247 | + if (!empty($value)) { |
|
248 | + $data['@value'] = $value; |
|
249 | + } |
|
250 | + } else { |
|
251 | + $data = array_merge($data, $this->xmlToArray($node)); |
|
252 | + } |
|
253 | + foreach ($attributes as $attr => $value) { |
|
254 | + $data['@attributes'][$attr] = (string)$value; |
|
255 | + } |
|
256 | 256 | |
257 | - if ($totalElement > 1) { |
|
258 | - $array[$element][] = $data; |
|
259 | - } else { |
|
260 | - $array[$element] = $data; |
|
261 | - } |
|
262 | - // Just a value |
|
263 | - } else { |
|
264 | - if ($totalElement > 1) { |
|
265 | - $array[$element][] = $this->xmlToArray($node); |
|
266 | - } else { |
|
267 | - $array[$element] = $this->xmlToArray($node); |
|
268 | - } |
|
269 | - } |
|
270 | - } |
|
257 | + if ($totalElement > 1) { |
|
258 | + $array[$element][] = $data; |
|
259 | + } else { |
|
260 | + $array[$element] = $data; |
|
261 | + } |
|
262 | + // Just a value |
|
263 | + } else { |
|
264 | + if ($totalElement > 1) { |
|
265 | + $array[$element][] = $this->xmlToArray($node); |
|
266 | + } else { |
|
267 | + $array[$element] = $this->xmlToArray($node); |
|
268 | + } |
|
269 | + } |
|
270 | + } |
|
271 | 271 | |
272 | - return $array; |
|
273 | - } |
|
272 | + return $array; |
|
273 | + } |
|
274 | 274 | } |
@@ -89,6 +89,6 @@ |
||
89 | 89 | if (empty($this->value)) { |
90 | 90 | return null; |
91 | 91 | } |
92 | - return 'tel:' . $this->value; |
|
92 | + return 'tel:'.$this->value; |
|
93 | 93 | } |
94 | 94 | } |
@@ -16,48 +16,48 @@ |
||
16 | 16 | use OCP\Profile\ILinkAction; |
17 | 17 | |
18 | 18 | class PhoneAction implements ILinkAction { |
19 | - private string $value = ''; |
|
20 | - |
|
21 | - public function __construct( |
|
22 | - private IAccountManager $accountManager, |
|
23 | - private IFactory $l10nFactory, |
|
24 | - private IURLGenerator $urlGenerator, |
|
25 | - ) { |
|
26 | - } |
|
27 | - |
|
28 | - public function preload(IUser $targetUser): void { |
|
29 | - $account = $this->accountManager->getAccount($targetUser); |
|
30 | - $this->value = $account->getProperty(IAccountManager::PROPERTY_PHONE)->getValue(); |
|
31 | - } |
|
32 | - |
|
33 | - public function getAppId(): string { |
|
34 | - return 'core'; |
|
35 | - } |
|
36 | - |
|
37 | - public function getId(): string { |
|
38 | - return IAccountManager::PROPERTY_PHONE; |
|
39 | - } |
|
40 | - |
|
41 | - public function getDisplayId(): string { |
|
42 | - return $this->l10nFactory->get('lib')->t('Phone'); |
|
43 | - } |
|
44 | - |
|
45 | - public function getTitle(): string { |
|
46 | - return $this->l10nFactory->get('lib')->t('Call %s', [$this->value]); |
|
47 | - } |
|
48 | - |
|
49 | - public function getPriority(): int { |
|
50 | - return 30; |
|
51 | - } |
|
52 | - |
|
53 | - public function getIcon(): string { |
|
54 | - return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/phone.svg')); |
|
55 | - } |
|
56 | - |
|
57 | - public function getTarget(): ?string { |
|
58 | - if (empty($this->value)) { |
|
59 | - return null; |
|
60 | - } |
|
61 | - return 'tel:' . $this->value; |
|
62 | - } |
|
19 | + private string $value = ''; |
|
20 | + |
|
21 | + public function __construct( |
|
22 | + private IAccountManager $accountManager, |
|
23 | + private IFactory $l10nFactory, |
|
24 | + private IURLGenerator $urlGenerator, |
|
25 | + ) { |
|
26 | + } |
|
27 | + |
|
28 | + public function preload(IUser $targetUser): void { |
|
29 | + $account = $this->accountManager->getAccount($targetUser); |
|
30 | + $this->value = $account->getProperty(IAccountManager::PROPERTY_PHONE)->getValue(); |
|
31 | + } |
|
32 | + |
|
33 | + public function getAppId(): string { |
|
34 | + return 'core'; |
|
35 | + } |
|
36 | + |
|
37 | + public function getId(): string { |
|
38 | + return IAccountManager::PROPERTY_PHONE; |
|
39 | + } |
|
40 | + |
|
41 | + public function getDisplayId(): string { |
|
42 | + return $this->l10nFactory->get('lib')->t('Phone'); |
|
43 | + } |
|
44 | + |
|
45 | + public function getTitle(): string { |
|
46 | + return $this->l10nFactory->get('lib')->t('Call %s', [$this->value]); |
|
47 | + } |
|
48 | + |
|
49 | + public function getPriority(): int { |
|
50 | + return 30; |
|
51 | + } |
|
52 | + |
|
53 | + public function getIcon(): string { |
|
54 | + return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/phone.svg')); |
|
55 | + } |
|
56 | + |
|
57 | + public function getTarget(): ?string { |
|
58 | + if (empty($this->value)) { |
|
59 | + return null; |
|
60 | + } |
|
61 | + return 'tel:' . $this->value; |
|
62 | + } |
|
63 | 63 | } |
@@ -89,6 +89,6 @@ |
||
89 | 89 | if (empty($this->value)) { |
90 | 90 | return null; |
91 | 91 | } |
92 | - return 'mailto:' . $this->value; |
|
92 | + return 'mailto:'.$this->value; |
|
93 | 93 | } |
94 | 94 | } |
@@ -16,48 +16,48 @@ |
||
16 | 16 | use OCP\Profile\ILinkAction; |
17 | 17 | |
18 | 18 | class EmailAction implements ILinkAction { |
19 | - private string $value = ''; |
|
20 | - |
|
21 | - public function __construct( |
|
22 | - private IAccountManager $accountManager, |
|
23 | - private IFactory $l10nFactory, |
|
24 | - private IURLGenerator $urlGenerator, |
|
25 | - ) { |
|
26 | - } |
|
27 | - |
|
28 | - public function preload(IUser $targetUser): void { |
|
29 | - $account = $this->accountManager->getAccount($targetUser); |
|
30 | - $this->value = $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(); |
|
31 | - } |
|
32 | - |
|
33 | - public function getAppId(): string { |
|
34 | - return 'core'; |
|
35 | - } |
|
36 | - |
|
37 | - public function getId(): string { |
|
38 | - return IAccountManager::PROPERTY_EMAIL; |
|
39 | - } |
|
40 | - |
|
41 | - public function getDisplayId(): string { |
|
42 | - return $this->l10nFactory->get('lib')->t('Email'); |
|
43 | - } |
|
44 | - |
|
45 | - public function getTitle(): string { |
|
46 | - return $this->l10nFactory->get('lib')->t('Mail %s', [$this->value]); |
|
47 | - } |
|
48 | - |
|
49 | - public function getPriority(): int { |
|
50 | - return 20; |
|
51 | - } |
|
52 | - |
|
53 | - public function getIcon(): string { |
|
54 | - return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); |
|
55 | - } |
|
56 | - |
|
57 | - public function getTarget(): ?string { |
|
58 | - if (empty($this->value)) { |
|
59 | - return null; |
|
60 | - } |
|
61 | - return 'mailto:' . $this->value; |
|
62 | - } |
|
19 | + private string $value = ''; |
|
20 | + |
|
21 | + public function __construct( |
|
22 | + private IAccountManager $accountManager, |
|
23 | + private IFactory $l10nFactory, |
|
24 | + private IURLGenerator $urlGenerator, |
|
25 | + ) { |
|
26 | + } |
|
27 | + |
|
28 | + public function preload(IUser $targetUser): void { |
|
29 | + $account = $this->accountManager->getAccount($targetUser); |
|
30 | + $this->value = $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(); |
|
31 | + } |
|
32 | + |
|
33 | + public function getAppId(): string { |
|
34 | + return 'core'; |
|
35 | + } |
|
36 | + |
|
37 | + public function getId(): string { |
|
38 | + return IAccountManager::PROPERTY_EMAIL; |
|
39 | + } |
|
40 | + |
|
41 | + public function getDisplayId(): string { |
|
42 | + return $this->l10nFactory->get('lib')->t('Email'); |
|
43 | + } |
|
44 | + |
|
45 | + public function getTitle(): string { |
|
46 | + return $this->l10nFactory->get('lib')->t('Mail %s', [$this->value]); |
|
47 | + } |
|
48 | + |
|
49 | + public function getPriority(): int { |
|
50 | + return 20; |
|
51 | + } |
|
52 | + |
|
53 | + public function getIcon(): string { |
|
54 | + return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); |
|
55 | + } |
|
56 | + |
|
57 | + public function getTarget(): ?string { |
|
58 | + if (empty($this->value)) { |
|
59 | + return null; |
|
60 | + } |
|
61 | + return 'mailto:' . $this->value; |
|
62 | + } |
|
63 | 63 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | public function getTitle(): string { |
78 | - $displayUsername = $this->value[0] === '@' ? $this->value : '@' . $this->value; |
|
78 | + $displayUsername = $this->value[0] === '@' ? $this->value : '@'.$this->value; |
|
79 | 79 | return $this->l10nFactory->get('lib')->t('View %s on Twitter', [$displayUsername]); |
80 | 80 | } |
81 | 81 | |
@@ -92,6 +92,6 @@ discard block |
||
92 | 92 | return null; |
93 | 93 | } |
94 | 94 | $username = $this->value[0] === '@' ? substr($this->value, 1) : $this->value; |
95 | - return 'https://twitter.com/' . $username; |
|
95 | + return 'https://twitter.com/'.$username; |
|
96 | 96 | } |
97 | 97 | } |
@@ -17,50 +17,50 @@ |
||
17 | 17 | use function substr; |
18 | 18 | |
19 | 19 | class TwitterAction implements ILinkAction { |
20 | - private string $value = ''; |
|
20 | + private string $value = ''; |
|
21 | 21 | |
22 | - public function __construct( |
|
23 | - private IAccountManager $accountManager, |
|
24 | - private IFactory $l10nFactory, |
|
25 | - private IURLGenerator $urlGenerator, |
|
26 | - ) { |
|
27 | - } |
|
22 | + public function __construct( |
|
23 | + private IAccountManager $accountManager, |
|
24 | + private IFactory $l10nFactory, |
|
25 | + private IURLGenerator $urlGenerator, |
|
26 | + ) { |
|
27 | + } |
|
28 | 28 | |
29 | - public function preload(IUser $targetUser): void { |
|
30 | - $account = $this->accountManager->getAccount($targetUser); |
|
31 | - $this->value = $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getValue(); |
|
32 | - } |
|
29 | + public function preload(IUser $targetUser): void { |
|
30 | + $account = $this->accountManager->getAccount($targetUser); |
|
31 | + $this->value = $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getValue(); |
|
32 | + } |
|
33 | 33 | |
34 | - public function getAppId(): string { |
|
35 | - return 'core'; |
|
36 | - } |
|
34 | + public function getAppId(): string { |
|
35 | + return 'core'; |
|
36 | + } |
|
37 | 37 | |
38 | - public function getId(): string { |
|
39 | - return IAccountManager::PROPERTY_TWITTER; |
|
40 | - } |
|
38 | + public function getId(): string { |
|
39 | + return IAccountManager::PROPERTY_TWITTER; |
|
40 | + } |
|
41 | 41 | |
42 | - public function getDisplayId(): string { |
|
43 | - return $this->l10nFactory->get('lib')->t('Twitter'); |
|
44 | - } |
|
42 | + public function getDisplayId(): string { |
|
43 | + return $this->l10nFactory->get('lib')->t('Twitter'); |
|
44 | + } |
|
45 | 45 | |
46 | - public function getTitle(): string { |
|
47 | - $displayUsername = $this->value[0] === '@' ? $this->value : '@' . $this->value; |
|
48 | - return $this->l10nFactory->get('lib')->t('View %s on Twitter', [$displayUsername]); |
|
49 | - } |
|
46 | + public function getTitle(): string { |
|
47 | + $displayUsername = $this->value[0] === '@' ? $this->value : '@' . $this->value; |
|
48 | + return $this->l10nFactory->get('lib')->t('View %s on Twitter', [$displayUsername]); |
|
49 | + } |
|
50 | 50 | |
51 | - public function getPriority(): int { |
|
52 | - return 50; |
|
53 | - } |
|
51 | + public function getPriority(): int { |
|
52 | + return 50; |
|
53 | + } |
|
54 | 54 | |
55 | - public function getIcon(): string { |
|
56 | - return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/twitter.svg')); |
|
57 | - } |
|
55 | + public function getIcon(): string { |
|
56 | + return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/twitter.svg')); |
|
57 | + } |
|
58 | 58 | |
59 | - public function getTarget(): ?string { |
|
60 | - if (empty($this->value)) { |
|
61 | - return null; |
|
62 | - } |
|
63 | - $username = $this->value[0] === '@' ? substr($this->value, 1) : $this->value; |
|
64 | - return 'https://twitter.com/' . $username; |
|
65 | - } |
|
59 | + public function getTarget(): ?string { |
|
60 | + if (empty($this->value)) { |
|
61 | + return null; |
|
62 | + } |
|
63 | + $username = $this->value[0] === '@' ? substr($this->value, 1) : $this->value; |
|
64 | + return 'https://twitter.com/' . $username; |
|
65 | + } |
|
66 | 66 | } |
@@ -96,7 +96,7 @@ |
||
96 | 96 | try { |
97 | 97 | $provider = $this->container->get($this->providerClass); |
98 | 98 | } catch (ContainerExceptionInterface $e) { |
99 | - $this->logger->error('Could not load user-status "' . $this->providerClass . '" provider dynamically: ' . $e->getMessage(), [ |
|
99 | + $this->logger->error('Could not load user-status "'.$this->providerClass.'" provider dynamically: '.$e->getMessage(), [ |
|
100 | 100 | 'exception' => $e, |
101 | 101 | ]); |
102 | 102 | return; |
@@ -15,100 +15,100 @@ |
||
15 | 15 | use Psr\Log\LoggerInterface; |
16 | 16 | |
17 | 17 | class Manager implements IManager { |
18 | - /** @var IServerContainer */ |
|
19 | - private $container; |
|
20 | - |
|
21 | - /** @var LoggerInterface */ |
|
22 | - private $logger; |
|
23 | - |
|
24 | - /** @var class-string */ |
|
25 | - private $providerClass; |
|
26 | - |
|
27 | - /** @var IProvider */ |
|
28 | - private $provider; |
|
29 | - |
|
30 | - /** |
|
31 | - * Manager constructor. |
|
32 | - * |
|
33 | - * @param IServerContainer $container |
|
34 | - * @param LoggerInterface $logger |
|
35 | - */ |
|
36 | - public function __construct(IServerContainer $container, |
|
37 | - LoggerInterface $logger) { |
|
38 | - $this->container = $container; |
|
39 | - $this->logger = $logger; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @inheritDoc |
|
44 | - */ |
|
45 | - public function getUserStatuses(array $userIds): array { |
|
46 | - $this->setupProvider(); |
|
47 | - if (!$this->provider) { |
|
48 | - return []; |
|
49 | - } |
|
50 | - |
|
51 | - return $this->provider->getUserStatuses($userIds); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $class |
|
56 | - * @since 20.0.0 |
|
57 | - * @internal |
|
58 | - */ |
|
59 | - public function registerProvider(string $class): void { |
|
60 | - $this->providerClass = $class; |
|
61 | - $this->provider = null; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Lazily set up provider |
|
66 | - */ |
|
67 | - private function setupProvider(): void { |
|
68 | - if ($this->provider !== null) { |
|
69 | - return; |
|
70 | - } |
|
71 | - if ($this->providerClass === null) { |
|
72 | - return; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @psalm-suppress InvalidCatch |
|
77 | - */ |
|
78 | - try { |
|
79 | - $provider = $this->container->get($this->providerClass); |
|
80 | - } catch (ContainerExceptionInterface $e) { |
|
81 | - $this->logger->error('Could not load user-status "' . $this->providerClass . '" provider dynamically: ' . $e->getMessage(), [ |
|
82 | - 'exception' => $e, |
|
83 | - ]); |
|
84 | - return; |
|
85 | - } |
|
86 | - |
|
87 | - $this->provider = $provider; |
|
88 | - } |
|
89 | - |
|
90 | - public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, ?string $customMessage = null): void { |
|
91 | - $this->setupProvider(); |
|
92 | - if (!$this->provider || !($this->provider instanceof ISettableProvider)) { |
|
93 | - return; |
|
94 | - } |
|
95 | - |
|
96 | - $this->provider->setUserStatus($userId, $messageId, $status, $createBackup, $customMessage); |
|
97 | - } |
|
98 | - |
|
99 | - public function revertUserStatus(string $userId, string $messageId, string $status): void { |
|
100 | - $this->setupProvider(); |
|
101 | - if (!$this->provider || !($this->provider instanceof ISettableProvider)) { |
|
102 | - return; |
|
103 | - } |
|
104 | - $this->provider->revertUserStatus($userId, $messageId, $status); |
|
105 | - } |
|
106 | - |
|
107 | - public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void { |
|
108 | - $this->setupProvider(); |
|
109 | - if (!$this->provider || !($this->provider instanceof ISettableProvider)) { |
|
110 | - return; |
|
111 | - } |
|
112 | - $this->provider->revertMultipleUserStatus($userIds, $messageId, $status); |
|
113 | - } |
|
18 | + /** @var IServerContainer */ |
|
19 | + private $container; |
|
20 | + |
|
21 | + /** @var LoggerInterface */ |
|
22 | + private $logger; |
|
23 | + |
|
24 | + /** @var class-string */ |
|
25 | + private $providerClass; |
|
26 | + |
|
27 | + /** @var IProvider */ |
|
28 | + private $provider; |
|
29 | + |
|
30 | + /** |
|
31 | + * Manager constructor. |
|
32 | + * |
|
33 | + * @param IServerContainer $container |
|
34 | + * @param LoggerInterface $logger |
|
35 | + */ |
|
36 | + public function __construct(IServerContainer $container, |
|
37 | + LoggerInterface $logger) { |
|
38 | + $this->container = $container; |
|
39 | + $this->logger = $logger; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @inheritDoc |
|
44 | + */ |
|
45 | + public function getUserStatuses(array $userIds): array { |
|
46 | + $this->setupProvider(); |
|
47 | + if (!$this->provider) { |
|
48 | + return []; |
|
49 | + } |
|
50 | + |
|
51 | + return $this->provider->getUserStatuses($userIds); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $class |
|
56 | + * @since 20.0.0 |
|
57 | + * @internal |
|
58 | + */ |
|
59 | + public function registerProvider(string $class): void { |
|
60 | + $this->providerClass = $class; |
|
61 | + $this->provider = null; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Lazily set up provider |
|
66 | + */ |
|
67 | + private function setupProvider(): void { |
|
68 | + if ($this->provider !== null) { |
|
69 | + return; |
|
70 | + } |
|
71 | + if ($this->providerClass === null) { |
|
72 | + return; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @psalm-suppress InvalidCatch |
|
77 | + */ |
|
78 | + try { |
|
79 | + $provider = $this->container->get($this->providerClass); |
|
80 | + } catch (ContainerExceptionInterface $e) { |
|
81 | + $this->logger->error('Could not load user-status "' . $this->providerClass . '" provider dynamically: ' . $e->getMessage(), [ |
|
82 | + 'exception' => $e, |
|
83 | + ]); |
|
84 | + return; |
|
85 | + } |
|
86 | + |
|
87 | + $this->provider = $provider; |
|
88 | + } |
|
89 | + |
|
90 | + public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, ?string $customMessage = null): void { |
|
91 | + $this->setupProvider(); |
|
92 | + if (!$this->provider || !($this->provider instanceof ISettableProvider)) { |
|
93 | + return; |
|
94 | + } |
|
95 | + |
|
96 | + $this->provider->setUserStatus($userId, $messageId, $status, $createBackup, $customMessage); |
|
97 | + } |
|
98 | + |
|
99 | + public function revertUserStatus(string $userId, string $messageId, string $status): void { |
|
100 | + $this->setupProvider(); |
|
101 | + if (!$this->provider || !($this->provider instanceof ISettableProvider)) { |
|
102 | + return; |
|
103 | + } |
|
104 | + $this->provider->revertUserStatus($userId, $messageId, $status); |
|
105 | + } |
|
106 | + |
|
107 | + public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void { |
|
108 | + $this->setupProvider(); |
|
109 | + if (!$this->provider || !($this->provider instanceof ISettableProvider)) { |
|
110 | + return; |
|
111 | + } |
|
112 | + $this->provider->revertMultipleUserStatus($userIds, $messageId, $status); |
|
113 | + } |
|
114 | 114 | } |
@@ -33,37 +33,37 @@ |
||
33 | 33 | * Map a user to a bucket. |
34 | 34 | */ |
35 | 35 | class Mapper { |
36 | - /** @var IUser */ |
|
37 | - private $user; |
|
36 | + /** @var IUser */ |
|
37 | + private $user; |
|
38 | 38 | |
39 | - /** @var IConfig */ |
|
40 | - private $config; |
|
39 | + /** @var IConfig */ |
|
40 | + private $config; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Mapper constructor. |
|
44 | - * |
|
45 | - * @param IUser $user |
|
46 | - * @param IConfig $config |
|
47 | - */ |
|
48 | - public function __construct(IUser $user, IConfig $config) { |
|
49 | - $this->user = $user; |
|
50 | - $this->config = $config; |
|
51 | - } |
|
42 | + /** |
|
43 | + * Mapper constructor. |
|
44 | + * |
|
45 | + * @param IUser $user |
|
46 | + * @param IConfig $config |
|
47 | + */ |
|
48 | + public function __construct(IUser $user, IConfig $config) { |
|
49 | + $this->user = $user; |
|
50 | + $this->config = $config; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param int $numBuckets |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function getBucket($numBuckets = 64) { |
|
58 | - // Get the bucket config and shift if provided. |
|
59 | - // Allow us to prevent writing in old filled buckets |
|
60 | - $config = $this->config->getSystemValue('objectstore_multibucket'); |
|
61 | - $minBucket = is_array($config) && isset($config['arguments']['min_bucket']) |
|
62 | - ? (int)$config['arguments']['min_bucket'] |
|
63 | - : 0; |
|
53 | + /** |
|
54 | + * @param int $numBuckets |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function getBucket($numBuckets = 64) { |
|
58 | + // Get the bucket config and shift if provided. |
|
59 | + // Allow us to prevent writing in old filled buckets |
|
60 | + $config = $this->config->getSystemValue('objectstore_multibucket'); |
|
61 | + $minBucket = is_array($config) && isset($config['arguments']['min_bucket']) |
|
62 | + ? (int)$config['arguments']['min_bucket'] |
|
63 | + : 0; |
|
64 | 64 | |
65 | - $hash = md5($this->user->getUID()); |
|
66 | - $num = hexdec(substr($hash, 0, 4)); |
|
67 | - return (string)(($num % ($numBuckets - $minBucket)) + $minBucket); |
|
68 | - } |
|
65 | + $hash = md5($this->user->getUID()); |
|
66 | + $num = hexdec(substr($hash, 0, 4)); |
|
67 | + return (string)(($num % ($numBuckets - $minBucket)) + $minBucket); |
|
68 | + } |
|
69 | 69 | } |
@@ -59,11 +59,11 @@ |
||
59 | 59 | // Allow us to prevent writing in old filled buckets |
60 | 60 | $config = $this->config->getSystemValue('objectstore_multibucket'); |
61 | 61 | $minBucket = is_array($config) && isset($config['arguments']['min_bucket']) |
62 | - ? (int)$config['arguments']['min_bucket'] |
|
62 | + ? (int) $config['arguments']['min_bucket'] |
|
63 | 63 | : 0; |
64 | 64 | |
65 | 65 | $hash = md5($this->user->getUID()); |
66 | 66 | $num = hexdec(substr($hash, 0, 4)); |
67 | - return (string)(($num % ($numBuckets - $minBucket)) + $minBucket); |
|
67 | + return (string) (($num % ($numBuckets - $minBucket)) + $minBucket); |
|
68 | 68 | } |
69 | 69 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | throw new \RuntimeException('no instance id!'); |
77 | 77 | } |
78 | 78 | |
79 | - return 'appdata_' . $instanceId; |
|
79 | + return 'appdata_'.$instanceId; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | protected function getAppDataRootFolder(): Folder { |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $name = $this->getAppDataFolderName(); |
105 | 105 | |
106 | 106 | try { |
107 | - $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
107 | + $this->folder = $this->rootFolder->get($name.'/'.$this->appId); |
|
108 | 108 | } catch (NotFoundException $e) { |
109 | 109 | $appDataRootFolder = $this->getAppDataRootFolder(); |
110 | 110 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | try { |
115 | 115 | $this->folder = $appDataRootFolder->newFolder($this->appId); |
116 | 116 | } catch (NotPermittedException $e) { |
117 | - throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
117 | + throw new \RuntimeException('Could not get appdata folder for '.$this->appId); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | public function getFolder(string $name): ISimpleFolder { |
127 | - $key = $this->appId . '/' . $name; |
|
127 | + $key = $this->appId.'/'.$name; |
|
128 | 128 | if ($cachedFolder = $this->folders->get($key)) { |
129 | 129 | if ($cachedFolder instanceof \Exception) { |
130 | 130 | throw $cachedFolder; |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | if ($name === '/') { |
138 | 138 | $node = $this->getAppDataFolder(); |
139 | 139 | } else { |
140 | - $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
140 | + $path = $this->getAppDataFolderName().'/'.$this->appId.'/'.$name; |
|
141 | 141 | $node = $this->rootFolder->get($path); |
142 | 142 | } |
143 | 143 | } catch (NotFoundException $e) { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | public function newFolder(string $name): ISimpleFolder { |
155 | - $key = $this->appId . '/' . $name; |
|
155 | + $key = $this->appId.'/'.$name; |
|
156 | 156 | $folder = $this->getAppDataFolder()->newFolder($name); |
157 | 157 | |
158 | 158 | $simpleFolder = new SimpleFolder($folder); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | public function getDirectoryListing(): array { |
164 | 164 | $listing = $this->getAppDataFolder()->getDirectoryListing(); |
165 | 165 | |
166 | - $fileListing = array_map(function (Node $folder) { |
|
166 | + $fileListing = array_map(function(Node $folder) { |
|
167 | 167 | if ($folder instanceof Folder) { |
168 | 168 | return new SimpleFolder($folder); |
169 | 169 | } |
@@ -20,135 +20,135 @@ |
||
20 | 20 | use OCP\Files\SimpleFS\ISimpleFolder; |
21 | 21 | |
22 | 22 | class AppData implements IAppData { |
23 | - private IRootFolder $rootFolder; |
|
24 | - private SystemConfig $config; |
|
25 | - private string $appId; |
|
26 | - private ?Folder $folder = null; |
|
27 | - /** @var CappedMemoryCache<ISimpleFolder|NotFoundException> */ |
|
28 | - private CappedMemoryCache $folders; |
|
29 | - |
|
30 | - /** |
|
31 | - * AppData constructor. |
|
32 | - * |
|
33 | - * @param IRootFolder $rootFolder |
|
34 | - * @param SystemConfig $systemConfig |
|
35 | - * @param string $appId |
|
36 | - */ |
|
37 | - public function __construct(IRootFolder $rootFolder, |
|
38 | - SystemConfig $systemConfig, |
|
39 | - string $appId) { |
|
40 | - $this->rootFolder = $rootFolder; |
|
41 | - $this->config = $systemConfig; |
|
42 | - $this->appId = $appId; |
|
43 | - $this->folders = new CappedMemoryCache(); |
|
44 | - } |
|
45 | - |
|
46 | - private function getAppDataFolderName() { |
|
47 | - $instanceId = $this->config->getValue('instanceid', null); |
|
48 | - if ($instanceId === null) { |
|
49 | - throw new \RuntimeException('no instance id!'); |
|
50 | - } |
|
51 | - |
|
52 | - return 'appdata_' . $instanceId; |
|
53 | - } |
|
54 | - |
|
55 | - protected function getAppDataRootFolder(): Folder { |
|
56 | - $name = $this->getAppDataFolderName(); |
|
57 | - |
|
58 | - try { |
|
59 | - /** @var Folder $node */ |
|
60 | - $node = $this->rootFolder->get($name); |
|
61 | - return $node; |
|
62 | - } catch (NotFoundException $e) { |
|
63 | - try { |
|
64 | - return $this->rootFolder->newFolder($name); |
|
65 | - } catch (NotPermittedException $e) { |
|
66 | - throw new \RuntimeException('Could not get appdata folder'); |
|
67 | - } |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return Folder |
|
73 | - * @throws \RuntimeException |
|
74 | - */ |
|
75 | - private function getAppDataFolder(): Folder { |
|
76 | - if ($this->folder === null) { |
|
77 | - $name = $this->getAppDataFolderName(); |
|
78 | - |
|
79 | - try { |
|
80 | - $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
81 | - } catch (NotFoundException $e) { |
|
82 | - $appDataRootFolder = $this->getAppDataRootFolder(); |
|
83 | - |
|
84 | - try { |
|
85 | - $this->folder = $appDataRootFolder->get($this->appId); |
|
86 | - } catch (NotFoundException $e) { |
|
87 | - try { |
|
88 | - $this->folder = $appDataRootFolder->newFolder($this->appId); |
|
89 | - } catch (NotPermittedException $e) { |
|
90 | - throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - return $this->folder; |
|
97 | - } |
|
98 | - |
|
99 | - public function getFolder(string $name): ISimpleFolder { |
|
100 | - $key = $this->appId . '/' . $name; |
|
101 | - if ($cachedFolder = $this->folders->get($key)) { |
|
102 | - if ($cachedFolder instanceof \Exception) { |
|
103 | - throw $cachedFolder; |
|
104 | - } else { |
|
105 | - return $cachedFolder; |
|
106 | - } |
|
107 | - } |
|
108 | - try { |
|
109 | - // Hardening if somebody wants to retrieve '/' |
|
110 | - if ($name === '/') { |
|
111 | - $node = $this->getAppDataFolder(); |
|
112 | - } else { |
|
113 | - $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
114 | - $node = $this->rootFolder->get($path); |
|
115 | - } |
|
116 | - } catch (NotFoundException $e) { |
|
117 | - $this->folders->set($key, $e); |
|
118 | - throw $e; |
|
119 | - } |
|
120 | - |
|
121 | - /** @var Folder $node */ |
|
122 | - $folder = new SimpleFolder($node); |
|
123 | - $this->folders->set($key, $folder); |
|
124 | - return $folder; |
|
125 | - } |
|
126 | - |
|
127 | - public function newFolder(string $name): ISimpleFolder { |
|
128 | - $key = $this->appId . '/' . $name; |
|
129 | - $folder = $this->getAppDataFolder()->newFolder($name); |
|
130 | - |
|
131 | - $simpleFolder = new SimpleFolder($folder); |
|
132 | - $this->folders->set($key, $simpleFolder); |
|
133 | - return $simpleFolder; |
|
134 | - } |
|
135 | - |
|
136 | - public function getDirectoryListing(): array { |
|
137 | - $listing = $this->getAppDataFolder()->getDirectoryListing(); |
|
138 | - |
|
139 | - $fileListing = array_map(function (Node $folder) { |
|
140 | - if ($folder instanceof Folder) { |
|
141 | - return new SimpleFolder($folder); |
|
142 | - } |
|
143 | - return null; |
|
144 | - }, $listing); |
|
145 | - |
|
146 | - $fileListing = array_filter($fileListing); |
|
147 | - |
|
148 | - return array_values($fileListing); |
|
149 | - } |
|
150 | - |
|
151 | - public function getId(): int { |
|
152 | - return $this->getAppDataFolder()->getId(); |
|
153 | - } |
|
23 | + private IRootFolder $rootFolder; |
|
24 | + private SystemConfig $config; |
|
25 | + private string $appId; |
|
26 | + private ?Folder $folder = null; |
|
27 | + /** @var CappedMemoryCache<ISimpleFolder|NotFoundException> */ |
|
28 | + private CappedMemoryCache $folders; |
|
29 | + |
|
30 | + /** |
|
31 | + * AppData constructor. |
|
32 | + * |
|
33 | + * @param IRootFolder $rootFolder |
|
34 | + * @param SystemConfig $systemConfig |
|
35 | + * @param string $appId |
|
36 | + */ |
|
37 | + public function __construct(IRootFolder $rootFolder, |
|
38 | + SystemConfig $systemConfig, |
|
39 | + string $appId) { |
|
40 | + $this->rootFolder = $rootFolder; |
|
41 | + $this->config = $systemConfig; |
|
42 | + $this->appId = $appId; |
|
43 | + $this->folders = new CappedMemoryCache(); |
|
44 | + } |
|
45 | + |
|
46 | + private function getAppDataFolderName() { |
|
47 | + $instanceId = $this->config->getValue('instanceid', null); |
|
48 | + if ($instanceId === null) { |
|
49 | + throw new \RuntimeException('no instance id!'); |
|
50 | + } |
|
51 | + |
|
52 | + return 'appdata_' . $instanceId; |
|
53 | + } |
|
54 | + |
|
55 | + protected function getAppDataRootFolder(): Folder { |
|
56 | + $name = $this->getAppDataFolderName(); |
|
57 | + |
|
58 | + try { |
|
59 | + /** @var Folder $node */ |
|
60 | + $node = $this->rootFolder->get($name); |
|
61 | + return $node; |
|
62 | + } catch (NotFoundException $e) { |
|
63 | + try { |
|
64 | + return $this->rootFolder->newFolder($name); |
|
65 | + } catch (NotPermittedException $e) { |
|
66 | + throw new \RuntimeException('Could not get appdata folder'); |
|
67 | + } |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return Folder |
|
73 | + * @throws \RuntimeException |
|
74 | + */ |
|
75 | + private function getAppDataFolder(): Folder { |
|
76 | + if ($this->folder === null) { |
|
77 | + $name = $this->getAppDataFolderName(); |
|
78 | + |
|
79 | + try { |
|
80 | + $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
81 | + } catch (NotFoundException $e) { |
|
82 | + $appDataRootFolder = $this->getAppDataRootFolder(); |
|
83 | + |
|
84 | + try { |
|
85 | + $this->folder = $appDataRootFolder->get($this->appId); |
|
86 | + } catch (NotFoundException $e) { |
|
87 | + try { |
|
88 | + $this->folder = $appDataRootFolder->newFolder($this->appId); |
|
89 | + } catch (NotPermittedException $e) { |
|
90 | + throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + return $this->folder; |
|
97 | + } |
|
98 | + |
|
99 | + public function getFolder(string $name): ISimpleFolder { |
|
100 | + $key = $this->appId . '/' . $name; |
|
101 | + if ($cachedFolder = $this->folders->get($key)) { |
|
102 | + if ($cachedFolder instanceof \Exception) { |
|
103 | + throw $cachedFolder; |
|
104 | + } else { |
|
105 | + return $cachedFolder; |
|
106 | + } |
|
107 | + } |
|
108 | + try { |
|
109 | + // Hardening if somebody wants to retrieve '/' |
|
110 | + if ($name === '/') { |
|
111 | + $node = $this->getAppDataFolder(); |
|
112 | + } else { |
|
113 | + $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
114 | + $node = $this->rootFolder->get($path); |
|
115 | + } |
|
116 | + } catch (NotFoundException $e) { |
|
117 | + $this->folders->set($key, $e); |
|
118 | + throw $e; |
|
119 | + } |
|
120 | + |
|
121 | + /** @var Folder $node */ |
|
122 | + $folder = new SimpleFolder($node); |
|
123 | + $this->folders->set($key, $folder); |
|
124 | + return $folder; |
|
125 | + } |
|
126 | + |
|
127 | + public function newFolder(string $name): ISimpleFolder { |
|
128 | + $key = $this->appId . '/' . $name; |
|
129 | + $folder = $this->getAppDataFolder()->newFolder($name); |
|
130 | + |
|
131 | + $simpleFolder = new SimpleFolder($folder); |
|
132 | + $this->folders->set($key, $simpleFolder); |
|
133 | + return $simpleFolder; |
|
134 | + } |
|
135 | + |
|
136 | + public function getDirectoryListing(): array { |
|
137 | + $listing = $this->getAppDataFolder()->getDirectoryListing(); |
|
138 | + |
|
139 | + $fileListing = array_map(function (Node $folder) { |
|
140 | + if ($folder instanceof Folder) { |
|
141 | + return new SimpleFolder($folder); |
|
142 | + } |
|
143 | + return null; |
|
144 | + }, $listing); |
|
145 | + |
|
146 | + $fileListing = array_filter($fileListing); |
|
147 | + |
|
148 | + return array_values($fileListing); |
|
149 | + } |
|
150 | + |
|
151 | + public function getId(): int { |
|
152 | + return $this->getAppDataFolder()->getId(); |
|
153 | + } |
|
154 | 154 | } |