Completed
Push — master ( e35451...cc9073 )
by Morris
53:33 queued 20:44
created
lib/private/Files/Config/MountProviderCollection.php 1 patch
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -35,165 +35,165 @@
 block discarded – undo
35 35
 use OCP\IUser;
36 36
 
37 37
 class MountProviderCollection implements IMountProviderCollection, Emitter {
38
-	use EmitterTrait;
39
-
40
-	/**
41
-	 * @var \OCP\Files\Config\IHomeMountProvider[]
42
-	 */
43
-	private $homeProviders = [];
44
-
45
-	/**
46
-	 * @var \OCP\Files\Config\IMountProvider[]
47
-	 */
48
-	private $providers = array();
49
-
50
-	/**
51
-	 * @var \OCP\Files\Storage\IStorageFactory
52
-	 */
53
-	private $loader;
54
-
55
-	/**
56
-	 * @var \OCP\Files\Config\IUserMountCache
57
-	 */
58
-	private $mountCache;
59
-
60
-	/** @var callable[] */
61
-	private $mountFilters = [];
62
-
63
-	/**
64
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
65
-	 * @param IUserMountCache $mountCache
66
-	 */
67
-	public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) {
68
-		$this->loader = $loader;
69
-		$this->mountCache = $mountCache;
70
-	}
71
-
72
-	/**
73
-	 * Get all configured mount points for the user
74
-	 *
75
-	 * @param \OCP\IUser $user
76
-	 * @return \OCP\Files\Mount\IMountPoint[]
77
-	 */
78
-	public function getMountsForUser(IUser $user) {
79
-		$loader = $this->loader;
80
-		$mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
81
-			return $provider->getMountsForUser($user, $loader);
82
-		}, $this->providers);
83
-		$mounts = array_filter($mounts, function ($result) {
84
-			return is_array($result);
85
-		});
86
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
87
-			return array_merge($mounts, $providerMounts);
88
-		}, array());
89
-		return $this->filterMounts($user, $mounts);
90
-	}
91
-
92
-	public function addMountForUser(IUser $user, IMountManager $mountManager) {
93
-		// shared mount provider gets to go last since it needs to know existing files
94
-		// to check for name collisions
95
-		$firstMounts = [];
96
-		$firstProviders = array_filter($this->providers, function (IMountProvider $provider) {
97
-			return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
98
-		});
99
-		$lastProviders = array_filter($this->providers, function (IMountProvider $provider) {
100
-			return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
101
-		});
102
-		foreach ($firstProviders as $provider) {
103
-			$mounts = $provider->getMountsForUser($user, $this->loader);
104
-			if (is_array($mounts)) {
105
-				$firstMounts = array_merge($firstMounts, $mounts);
106
-			}
107
-		}
108
-		$firstMounts = $this->filterMounts($user, $firstMounts);
109
-		array_walk($firstMounts, [$mountManager, 'addMount']);
110
-
111
-		$lateMounts = [];
112
-		foreach ($lastProviders as $provider) {
113
-			$mounts = $provider->getMountsForUser($user, $this->loader);
114
-			if (is_array($mounts)) {
115
-				$lateMounts = array_merge($lateMounts, $mounts);
116
-			}
117
-		}
118
-
119
-		$lateMounts = $this->filterMounts($user, $lateMounts);
120
-		array_walk($lateMounts, [$mountManager, 'addMount']);
121
-
122
-		return array_merge($lateMounts, $firstMounts);
123
-	}
124
-
125
-	/**
126
-	 * Get the configured home mount for this user
127
-	 *
128
-	 * @param \OCP\IUser $user
129
-	 * @return \OCP\Files\Mount\IMountPoint
130
-	 * @since 9.1.0
131
-	 */
132
-	public function getHomeMountForUser(IUser $user) {
133
-		/** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
134
-		$providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
135
-		foreach ($providers as $homeProvider) {
136
-			if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
137
-				$mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
138
-				return $mount;
139
-			}
140
-		}
141
-		throw new \Exception('No home storage configured for user ' . $user);
142
-	}
143
-
144
-	/**
145
-	 * Add a provider for mount points
146
-	 *
147
-	 * @param \OCP\Files\Config\IMountProvider $provider
148
-	 */
149
-	public function registerProvider(IMountProvider $provider) {
150
-		$this->providers[] = $provider;
151
-
152
-		$this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
153
-	}
154
-
155
-	public function registerMountFilter(callable $filter) {
156
-		$this->mountFilters[] = $filter;
157
-	}
158
-
159
-	private function filterMounts(IUser $user, array $mountPoints) {
160
-		return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
161
-			foreach ($this->mountFilters as $filter) {
162
-				if ($filter($mountPoint, $user) === false) {
163
-					return false;
164
-				}
165
-			}
166
-			return true;
167
-		});
168
-	}
169
-
170
-	/**
171
-	 * Add a provider for home mount points
172
-	 *
173
-	 * @param \OCP\Files\Config\IHomeMountProvider $provider
174
-	 * @since 9.1.0
175
-	 */
176
-	public function registerHomeProvider(IHomeMountProvider $provider) {
177
-		$this->homeProviders[] = $provider;
178
-		$this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]);
179
-	}
180
-
181
-	/**
182
-	 * Cache mounts for user
183
-	 *
184
-	 * @param IUser $user
185
-	 * @param IMountPoint[] $mountPoints
186
-	 */
187
-	public function registerMounts(IUser $user, array $mountPoints) {
188
-		$this->mountCache->registerMounts($user, $mountPoints);
189
-	}
190
-
191
-	/**
192
-	 * Get the mount cache which can be used to search for mounts without setting up the filesystem
193
-	 *
194
-	 * @return IUserMountCache
195
-	 */
196
-	public function getMountCache() {
197
-		return $this->mountCache;
198
-	}
38
+    use EmitterTrait;
39
+
40
+    /**
41
+     * @var \OCP\Files\Config\IHomeMountProvider[]
42
+     */
43
+    private $homeProviders = [];
44
+
45
+    /**
46
+     * @var \OCP\Files\Config\IMountProvider[]
47
+     */
48
+    private $providers = array();
49
+
50
+    /**
51
+     * @var \OCP\Files\Storage\IStorageFactory
52
+     */
53
+    private $loader;
54
+
55
+    /**
56
+     * @var \OCP\Files\Config\IUserMountCache
57
+     */
58
+    private $mountCache;
59
+
60
+    /** @var callable[] */
61
+    private $mountFilters = [];
62
+
63
+    /**
64
+     * @param \OCP\Files\Storage\IStorageFactory $loader
65
+     * @param IUserMountCache $mountCache
66
+     */
67
+    public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) {
68
+        $this->loader = $loader;
69
+        $this->mountCache = $mountCache;
70
+    }
71
+
72
+    /**
73
+     * Get all configured mount points for the user
74
+     *
75
+     * @param \OCP\IUser $user
76
+     * @return \OCP\Files\Mount\IMountPoint[]
77
+     */
78
+    public function getMountsForUser(IUser $user) {
79
+        $loader = $this->loader;
80
+        $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
81
+            return $provider->getMountsForUser($user, $loader);
82
+        }, $this->providers);
83
+        $mounts = array_filter($mounts, function ($result) {
84
+            return is_array($result);
85
+        });
86
+        $mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
87
+            return array_merge($mounts, $providerMounts);
88
+        }, array());
89
+        return $this->filterMounts($user, $mounts);
90
+    }
91
+
92
+    public function addMountForUser(IUser $user, IMountManager $mountManager) {
93
+        // shared mount provider gets to go last since it needs to know existing files
94
+        // to check for name collisions
95
+        $firstMounts = [];
96
+        $firstProviders = array_filter($this->providers, function (IMountProvider $provider) {
97
+            return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
98
+        });
99
+        $lastProviders = array_filter($this->providers, function (IMountProvider $provider) {
100
+            return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
101
+        });
102
+        foreach ($firstProviders as $provider) {
103
+            $mounts = $provider->getMountsForUser($user, $this->loader);
104
+            if (is_array($mounts)) {
105
+                $firstMounts = array_merge($firstMounts, $mounts);
106
+            }
107
+        }
108
+        $firstMounts = $this->filterMounts($user, $firstMounts);
109
+        array_walk($firstMounts, [$mountManager, 'addMount']);
110
+
111
+        $lateMounts = [];
112
+        foreach ($lastProviders as $provider) {
113
+            $mounts = $provider->getMountsForUser($user, $this->loader);
114
+            if (is_array($mounts)) {
115
+                $lateMounts = array_merge($lateMounts, $mounts);
116
+            }
117
+        }
118
+
119
+        $lateMounts = $this->filterMounts($user, $lateMounts);
120
+        array_walk($lateMounts, [$mountManager, 'addMount']);
121
+
122
+        return array_merge($lateMounts, $firstMounts);
123
+    }
124
+
125
+    /**
126
+     * Get the configured home mount for this user
127
+     *
128
+     * @param \OCP\IUser $user
129
+     * @return \OCP\Files\Mount\IMountPoint
130
+     * @since 9.1.0
131
+     */
132
+    public function getHomeMountForUser(IUser $user) {
133
+        /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
134
+        $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
135
+        foreach ($providers as $homeProvider) {
136
+            if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
137
+                $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
138
+                return $mount;
139
+            }
140
+        }
141
+        throw new \Exception('No home storage configured for user ' . $user);
142
+    }
143
+
144
+    /**
145
+     * Add a provider for mount points
146
+     *
147
+     * @param \OCP\Files\Config\IMountProvider $provider
148
+     */
149
+    public function registerProvider(IMountProvider $provider) {
150
+        $this->providers[] = $provider;
151
+
152
+        $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
153
+    }
154
+
155
+    public function registerMountFilter(callable $filter) {
156
+        $this->mountFilters[] = $filter;
157
+    }
158
+
159
+    private function filterMounts(IUser $user, array $mountPoints) {
160
+        return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
161
+            foreach ($this->mountFilters as $filter) {
162
+                if ($filter($mountPoint, $user) === false) {
163
+                    return false;
164
+                }
165
+            }
166
+            return true;
167
+        });
168
+    }
169
+
170
+    /**
171
+     * Add a provider for home mount points
172
+     *
173
+     * @param \OCP\Files\Config\IHomeMountProvider $provider
174
+     * @since 9.1.0
175
+     */
176
+    public function registerHomeProvider(IHomeMountProvider $provider) {
177
+        $this->homeProviders[] = $provider;
178
+        $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]);
179
+    }
180
+
181
+    /**
182
+     * Cache mounts for user
183
+     *
184
+     * @param IUser $user
185
+     * @param IMountPoint[] $mountPoints
186
+     */
187
+    public function registerMounts(IUser $user, array $mountPoints) {
188
+        $this->mountCache->registerMounts($user, $mountPoints);
189
+    }
190
+
191
+    /**
192
+     * Get the mount cache which can be used to search for mounts without setting up the filesystem
193
+     *
194
+     * @return IUserMountCache
195
+     */
196
+    public function getMountCache() {
197
+        return $this->mountCache;
198
+    }
199 199
 }
Please login to merge, or discard this patch.
lib/public/Files/Config/IMountProviderCollection.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -30,53 +30,53 @@
 block discarded – undo
30 30
  * @since 8.0.0
31 31
  */
32 32
 interface IMountProviderCollection {
33
-	/**
34
-	 * Get all configured mount points for the user
35
-	 *
36
-	 * @param \OCP\IUser $user
37
-	 * @return \OCP\Files\Mount\IMountPoint[]
38
-	 * @since 8.0.0
39
-	 */
40
-	public function getMountsForUser(IUser $user);
33
+    /**
34
+     * Get all configured mount points for the user
35
+     *
36
+     * @param \OCP\IUser $user
37
+     * @return \OCP\Files\Mount\IMountPoint[]
38
+     * @since 8.0.0
39
+     */
40
+    public function getMountsForUser(IUser $user);
41 41
 
42
-	/**
43
-	 * Get the configured home mount for this user
44
-	 *
45
-	 * @param \OCP\IUser $user
46
-	 * @return \OCP\Files\Mount\IMountPoint
47
-	 * @since 9.1.0
48
-	 */
49
-	public function getHomeMountForUser(IUser $user);
42
+    /**
43
+     * Get the configured home mount for this user
44
+     *
45
+     * @param \OCP\IUser $user
46
+     * @return \OCP\Files\Mount\IMountPoint
47
+     * @since 9.1.0
48
+     */
49
+    public function getHomeMountForUser(IUser $user);
50 50
 
51
-	/**
52
-	 * Add a provider for mount points
53
-	 *
54
-	 * @param \OCP\Files\Config\IMountProvider $provider
55
-	 * @since 8.0.0
56
-	 */
57
-	public function registerProvider(IMountProvider $provider);
51
+    /**
52
+     * Add a provider for mount points
53
+     *
54
+     * @param \OCP\Files\Config\IMountProvider $provider
55
+     * @since 8.0.0
56
+     */
57
+    public function registerProvider(IMountProvider $provider);
58 58
 
59
-	/**
60
-	 * Add a filter for mounts
61
-	 *
62
-	 * @param callable $filter (IMountPoint $mountPoint, IUser $user) => boolean
63
-	 * @since 14.0.0
64
-	 */
65
-	public function registerMountFilter(callable $filter);
59
+    /**
60
+     * Add a filter for mounts
61
+     *
62
+     * @param callable $filter (IMountPoint $mountPoint, IUser $user) => boolean
63
+     * @since 14.0.0
64
+     */
65
+    public function registerMountFilter(callable $filter);
66 66
 
67
-	/**
68
-	 * Add a provider for home mount points
69
-	 *
70
-	 * @param \OCP\Files\Config\IHomeMountProvider $provider
71
-	 * @since 9.1.0
72
-	 */
73
-	public function registerHomeProvider(IHomeMountProvider $provider);
67
+    /**
68
+     * Add a provider for home mount points
69
+     *
70
+     * @param \OCP\Files\Config\IHomeMountProvider $provider
71
+     * @since 9.1.0
72
+     */
73
+    public function registerHomeProvider(IHomeMountProvider $provider);
74 74
 
75
-	/**
76
-	 * Get the mount cache which can be used to search for mounts without setting up the filesystem
77
-	 *
78
-	 * @return IUserMountCache
79
-	 * @since 9.0.0
80
-	 */
81
-	public function getMountCache();
75
+    /**
76
+     * Get the mount cache which can be used to search for mounts without setting up the filesystem
77
+     *
78
+     * @return IUserMountCache
79
+     * @since 9.0.0
80
+     */
81
+    public function getMountCache();
82 82
 }
Please login to merge, or discard this patch.