99
1010use OC \Hooks \Emitter ;
1111use OC \Hooks \EmitterTrait ;
12+ use OCA \Files_Sharing \MountProvider ;
1213use OCP \Diagnostics \IEventLogger ;
1314use OCP \Files \Cache \ICacheEntry ;
1415use OCP \Files \Config \ICachedMountInfo ;
2223use OCP \Files \Mount \IMountPoint ;
2324use OCP \Files \Storage \IStorageFactory ;
2425use OCP \IUser ;
26+ use function get_class ;
27+ use function in_array ;
2528
2629class MountProviderCollection implements IMountProviderCollection, Emitter {
2730 use EmitterTrait;
@@ -32,7 +35,7 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
3235 private array $ homeProviders = [];
3336
3437 /**
35- * @var list< IMountProvider>
38+ * @var array<class-string<IMountProvider>, IMountProvider>
3639 */
3740 private array $ providers = [];
3841
@@ -78,7 +81,7 @@ private function getUserMountsForProviders(IUser $user, array $providers): array
7881 * @return list<IMountPoint>
7982 */
8083 public function getMountsForUser (IUser $ user ): array {
81- return $ this ->getUserMountsForProviders ($ user , $ this ->providers );
84+ return $ this ->getUserMountsForProviders ($ user , array_values ( $ this ->providers ) );
8285 }
8386
8487 /**
@@ -120,8 +123,12 @@ public function getUserMountsFromProviderByPath(
120123 * @return list<IMountPoint>
121124 */
122125 public function getUserMountsForProviderClasses (IUser $ user , array $ mountProviderClasses ): array {
123- $ providers = $ this ->getProvidersByClass ($ this ->providers , $ mountProviderClasses );
124- return $ this ->getUserMountsForProviders ($ user , array_values ($ providers ));
126+ $ providers = array_filter (
127+ $ this ->providers ,
128+ fn (string $ providerClass ) => in_array ($ providerClass , $ mountProviderClasses ),
129+ ARRAY_FILTER_USE_KEY
130+ );
131+ return $ this ->getUserMountsForProviders ($ user , $ providers );
125132 }
126133
127134 /**
@@ -132,16 +139,21 @@ public function addMountForUser(IUser $user, IMountManager $mountManager, ?calla
132139 // to check for name collisions
133140 $ firstMounts = [];
134141 if ($ providerFilter ) {
135- $ providers = array_filter ($ this ->providers , $ providerFilter );
142+ $ providers = array_filter ($ this ->providers , $ providerFilter, ARRAY_FILTER_USE_KEY );
136143 } else {
137144 $ providers = $ this ->providers ;
138145 }
139- $ firstProviders = array_filter ($ providers , function (IMountProvider $ provider ) {
140- return (get_class ($ provider ) !== 'OCA\Files_Sharing\MountProvider ' );
141- });
142- $ lastProviders = array_filter ($ providers , function (IMountProvider $ provider ) {
143- return (get_class ($ provider ) === 'OCA\Files_Sharing\MountProvider ' );
144- });
146+ $ firstProviders
147+ = array_filter (
148+ $ providers ,
149+ fn (string $ providerClass ) => ($ providerClass !== MountProvider::class),
150+ ARRAY_FILTER_USE_KEY
151+ );
152+ $ lastProviders = array_filter (
153+ $ providers ,
154+ fn (string $ providerClass ) => $ providerClass === MountProvider::class,
155+ ARRAY_FILTER_USE_KEY
156+ );
145157 foreach ($ firstProviders as $ provider ) {
146158 $ mounts = $ this ->getMountsFromProvider ($ provider , $ user , $ this ->loader );
147159 $ firstMounts = array_merge ($ firstMounts , $ mounts );
@@ -183,7 +195,7 @@ public function getHomeMountForUser(IUser $user): IMountPoint {
183195 * Add a provider for mount points
184196 */
185197 public function registerProvider (IMountProvider $ provider ): void {
186- $ this ->providers [] = $ provider ;
198+ $ this ->providers [get_class ( $ provider ) ] = $ provider ;
187199
188200 $ this ->emit ('\OC\Files\Config ' , 'registerMountProvider ' , [$ provider ]);
189201 }
@@ -261,7 +273,7 @@ public function clearProviders(): void {
261273 * @return list<IMountProvider>
262274 */
263275 public function getProviders (): array {
264- return $ this ->providers ;
276+ return array_values ( $ this ->providers ) ;
265277 }
266278
267279 /**
0 commit comments