Passed
Push — master ( 873501...d2df81 )
by Maxence
14:59 queued 12s
created
apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -32,21 +32,21 @@
 block discarded – undo
32 32
  * OAuth2 authentication
33 33
  */
34 34
 class OAuth2 extends AuthMechanism {
35
-	public function __construct(IL10N $l) {
36
-		$this
37
-			->setIdentifier('oauth2::oauth2')
38
-			->setScheme(self::SCHEME_OAUTH2)
39
-			->setText($l->t('OAuth2'))
40
-			->addParameters([
41
-				(new DefinitionParameter('configured', 'configured'))
42
-					->setType(DefinitionParameter::VALUE_HIDDEN),
43
-				new DefinitionParameter('client_id', $l->t('Client ID')),
44
-				(new DefinitionParameter('client_secret', $l->t('Client secret')))
45
-					->setType(DefinitionParameter::VALUE_PASSWORD),
46
-				(new DefinitionParameter('token', 'token'))
47
-					->setType(DefinitionParameter::VALUE_HIDDEN),
48
-			])
49
-			->addCustomJs('oauth2')
50
-		;
51
-	}
35
+    public function __construct(IL10N $l) {
36
+        $this
37
+            ->setIdentifier('oauth2::oauth2')
38
+            ->setScheme(self::SCHEME_OAUTH2)
39
+            ->setText($l->t('OAuth2'))
40
+            ->addParameters([
41
+                (new DefinitionParameter('configured', 'configured'))
42
+                    ->setType(DefinitionParameter::VALUE_HIDDEN),
43
+                new DefinitionParameter('client_id', $l->t('Client ID')),
44
+                (new DefinitionParameter('client_secret', $l->t('Client secret')))
45
+                    ->setType(DefinitionParameter::VALUE_PASSWORD),
46
+                (new DefinitionParameter('token', 'token'))
47
+                    ->setType(DefinitionParameter::VALUE_HIDDEN),
48
+            ])
49
+            ->addCustomJs('oauth2')
50
+        ;
51
+    }
52 52
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Backend/SFTP_Key.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -30,19 +30,19 @@
 block discarded – undo
30 30
 use OCP\IL10N;
31 31
 
32 32
 class SFTP_Key extends Backend {
33
-	public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) {
34
-		$this
35
-			->setIdentifier('\OC\Files\Storage\SFTP_Key')
36
-			->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP')
37
-			->setText($l->t('SFTP with secret key login'))
38
-			->addParameters([
39
-				new DefinitionParameter('host', $l->t('Host')),
40
-				(new DefinitionParameter('root', $l->t('Remote subfolder')))
41
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
42
-			])
43
-			->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY)
44
-			->setLegacyAuthMechanism($legacyAuth)
45
-			->deprecateTo($sftpBackend)
46
-		;
47
-	}
33
+    public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) {
34
+        $this
35
+            ->setIdentifier('\OC\Files\Storage\SFTP_Key')
36
+            ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP')
37
+            ->setText($l->t('SFTP with secret key login'))
38
+            ->addParameters([
39
+                new DefinitionParameter('host', $l->t('Host')),
40
+                (new DefinitionParameter('root', $l->t('Remote subfolder')))
41
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
42
+            ])
43
+            ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY)
44
+            ->setLegacyAuthMechanism($legacyAuth)
45
+            ->deprecateTo($sftpBackend)
46
+        ;
47
+    }
48 48
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Backend/Local.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -31,19 +31,19 @@
 block discarded – undo
31 31
 use OCP\IL10N;
32 32
 
33 33
 class Local extends Backend {
34
-	public function __construct(IL10N $l, NullMechanism $legacyAuth) {
35
-		$this
36
-			->setIdentifier('local')
37
-			->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat
38
-			->setStorageClass('\OC\Files\Storage\Local')
39
-			->setText($l->t('Local'))
40
-			->addParameters([
41
-				new DefinitionParameter('datadir', $l->t('Location')),
42
-			])
43
-			->setAllowedVisibility(BackendService::VISIBILITY_ADMIN)
44
-			->setPriority(BackendService::PRIORITY_DEFAULT + 50)
45
-			->addAuthScheme(AuthMechanism::SCHEME_NULL)
46
-			->setLegacyAuthMechanism($legacyAuth)
47
-		;
48
-	}
34
+    public function __construct(IL10N $l, NullMechanism $legacyAuth) {
35
+        $this
36
+            ->setIdentifier('local')
37
+            ->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat
38
+            ->setStorageClass('\OC\Files\Storage\Local')
39
+            ->setText($l->t('Local'))
40
+            ->addParameters([
41
+                new DefinitionParameter('datadir', $l->t('Location')),
42
+            ])
43
+            ->setAllowedVisibility(BackendService::VISIBILITY_ADMIN)
44
+            ->setPriority(BackendService::PRIORITY_DEFAULT + 50)
45
+            ->addAuthScheme(AuthMechanism::SCHEME_NULL)
46
+            ->setLegacyAuthMechanism($legacyAuth)
47
+        ;
48
+    }
49 49
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Backend/SFTP.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -30,20 +30,20 @@
 block discarded – undo
30 30
 use OCP\IL10N;
31 31
 
32 32
 class SFTP extends Backend {
33
-	public function __construct(IL10N $l, Password $legacyAuth) {
34
-		$this
35
-			->setIdentifier('sftp')
36
-			->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat
37
-			->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP')
38
-			->setText($l->t('SFTP'))
39
-			->addParameters([
40
-				new DefinitionParameter('host', $l->t('Host')),
41
-				(new DefinitionParameter('root', $l->t('Root')))
42
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
43
-			])
44
-			->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
45
-			->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY)
46
-			->setLegacyAuthMechanism($legacyAuth)
47
-		;
48
-	}
33
+    public function __construct(IL10N $l, Password $legacyAuth) {
34
+        $this
35
+            ->setIdentifier('sftp')
36
+            ->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat
37
+            ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP')
38
+            ->setText($l->t('SFTP'))
39
+            ->addParameters([
40
+                new DefinitionParameter('host', $l->t('Host')),
41
+                (new DefinitionParameter('root', $l->t('Root')))
42
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
43
+            ])
44
+            ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
45
+            ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY)
46
+            ->setLegacyAuthMechanism($legacyAuth)
47
+        ;
48
+    }
49 49
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Storage/OwnCloud.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,13 +65,13 @@
 block discarded – undo
65 65
 		}
66 66
 
67 67
 		if (isset($params['root'])) {
68
-			$root = '/' . ltrim($params['root'], '/');
68
+			$root = '/'.ltrim($params['root'], '/');
69 69
 		} else {
70 70
 			$root = '/';
71 71
 		}
72 72
 
73 73
 		$params['host'] = $host;
74
-		$params['root'] = $contextPath . self::OC_URL_SUFFIX . $root;
74
+		$params['root'] = $contextPath.self::OC_URL_SUFFIX.$root;
75 75
 		$params['authType'] = Client::AUTH_BASIC;
76 76
 
77 77
 		parent::__construct($params);
Please login to merge, or discard this patch.
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -39,45 +39,45 @@
 block discarded – undo
39 39
  *
40 40
  */
41 41
 class OwnCloud extends \OC\Files\Storage\DAV implements IDisableEncryptionStorage {
42
-	public const OC_URL_SUFFIX = 'remote.php/webdav';
42
+    public const OC_URL_SUFFIX = 'remote.php/webdav';
43 43
 
44
-	public function __construct($params) {
45
-		// extract context path from host if specified
46
-		// (owncloud install path on host)
47
-		$host = $params['host'];
48
-		// strip protocol
49
-		if (substr($host, 0, 8) === "https://") {
50
-			$host = substr($host, 8);
51
-			$params['secure'] = true;
52
-		} elseif (substr($host, 0, 7) === "http://") {
53
-			$host = substr($host, 7);
54
-			$params['secure'] = false;
55
-		}
56
-		$contextPath = '';
57
-		$hostSlashPos = strpos($host, '/');
58
-		if ($hostSlashPos !== false) {
59
-			$contextPath = substr($host, $hostSlashPos);
60
-			$host = substr($host, 0, $hostSlashPos);
61
-		}
44
+    public function __construct($params) {
45
+        // extract context path from host if specified
46
+        // (owncloud install path on host)
47
+        $host = $params['host'];
48
+        // strip protocol
49
+        if (substr($host, 0, 8) === "https://") {
50
+            $host = substr($host, 8);
51
+            $params['secure'] = true;
52
+        } elseif (substr($host, 0, 7) === "http://") {
53
+            $host = substr($host, 7);
54
+            $params['secure'] = false;
55
+        }
56
+        $contextPath = '';
57
+        $hostSlashPos = strpos($host, '/');
58
+        if ($hostSlashPos !== false) {
59
+            $contextPath = substr($host, $hostSlashPos);
60
+            $host = substr($host, 0, $hostSlashPos);
61
+        }
62 62
 
63
-		if (substr($contextPath, -1) !== '/') {
64
-			$contextPath .= '/';
65
-		}
63
+        if (substr($contextPath, -1) !== '/') {
64
+            $contextPath .= '/';
65
+        }
66 66
 
67
-		if (isset($params['root'])) {
68
-			$root = '/' . ltrim($params['root'], '/');
69
-		} else {
70
-			$root = '/';
71
-		}
67
+        if (isset($params['root'])) {
68
+            $root = '/' . ltrim($params['root'], '/');
69
+        } else {
70
+            $root = '/';
71
+        }
72 72
 
73
-		$params['host'] = $host;
74
-		$params['root'] = $contextPath . self::OC_URL_SUFFIX . $root;
75
-		$params['authType'] = Client::AUTH_BASIC;
73
+        $params['host'] = $host;
74
+        $params['root'] = $contextPath . self::OC_URL_SUFFIX . $root;
75
+        $params['authType'] = Client::AUTH_BASIC;
76 76
 
77
-		parent::__construct($params);
78
-	}
77
+        parent::__construct($params);
78
+    }
79 79
 
80
-	public function needsPartFile() {
81
-		return false;
82
-	}
80
+    public function needsPartFile() {
81
+        return false;
82
+    }
83 83
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Config/UserPlaceholderHandler.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -25,19 +25,19 @@
 block discarded – undo
25 25
 namespace OCA\Files_External\Config;
26 26
 
27 27
 class UserPlaceholderHandler extends UserContext implements IConfigHandler {
28
-	use SimpleSubstitutionTrait;
28
+    use SimpleSubstitutionTrait;
29 29
 
30
-	/**
31
-	 * @param mixed $optionValue
32
-	 * @return mixed the same type as $optionValue
33
-	 * @since 16.0.0
34
-	 */
35
-	public function handle($optionValue) {
36
-		$this->placeholder = 'user';
37
-		$uid = $this->getUserId();
38
-		if ($uid === null) {
39
-			return $optionValue;
40
-		}
41
-		return $this->processInput($optionValue, $uid);
42
-	}
30
+    /**
31
+     * @param mixed $optionValue
32
+     * @return mixed the same type as $optionValue
33
+     * @since 16.0.0
34
+     */
35
+    public function handle($optionValue) {
36
+        $this->placeholder = 'user';
37
+        $uid = $this->getUserId();
38
+        if ($uid === null) {
39
+            return $optionValue;
40
+        }
41
+        return $this->processInput($optionValue, $uid);
42
+    }
43 43
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Config/SimpleSubstitutionTrait.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -31,57 +31,57 @@
 block discarded – undo
31 31
  * @since 16.0.0
32 32
  */
33 33
 trait SimpleSubstitutionTrait {
34
-	/**
35
-	 * @var string the placeholder without $ prefix
36
-	 * @since 16.0.0
37
-	 */
38
-	protected $placeholder;
34
+    /**
35
+     * @var string the placeholder without $ prefix
36
+     * @since 16.0.0
37
+     */
38
+    protected $placeholder;
39 39
 
40
-	/** @var string */
41
-	protected $sanitizedPlaceholder;
40
+    /** @var string */
41
+    protected $sanitizedPlaceholder;
42 42
 
43
-	/**
44
-	 * @param mixed $optionValue
45
-	 * @param string $replacement
46
-	 * @return mixed
47
-	 * @since 16.0.0
48
-	 */
49
-	private function processInput($optionValue, string $replacement) {
50
-		$this->checkPlaceholder();
51
-		if (is_array($optionValue)) {
52
-			foreach ($optionValue as &$value) {
53
-				$value = $this->substituteIfString($value, $replacement);
54
-			}
55
-		} else {
56
-			$optionValue = $this->substituteIfString($optionValue, $replacement);
57
-		}
58
-		return $optionValue;
59
-	}
43
+    /**
44
+     * @param mixed $optionValue
45
+     * @param string $replacement
46
+     * @return mixed
47
+     * @since 16.0.0
48
+     */
49
+    private function processInput($optionValue, string $replacement) {
50
+        $this->checkPlaceholder();
51
+        if (is_array($optionValue)) {
52
+            foreach ($optionValue as &$value) {
53
+                $value = $this->substituteIfString($value, $replacement);
54
+            }
55
+        } else {
56
+            $optionValue = $this->substituteIfString($optionValue, $replacement);
57
+        }
58
+        return $optionValue;
59
+    }
60 60
 
61
-	/**
62
-	 * @throws \RuntimeException
63
-	 */
64
-	protected function checkPlaceholder(): void {
65
-		$this->sanitizedPlaceholder = trim(strtolower($this->placeholder));
66
-		if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) {
67
-			throw new \RuntimeException(sprintf(
68
-				'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder
69
-			));
70
-		}
71
-		if ($this->sanitizedPlaceholder === '') {
72
-			throw new \RuntimeException('Invalid empty placeholder');
73
-		}
74
-	}
61
+    /**
62
+     * @throws \RuntimeException
63
+     */
64
+    protected function checkPlaceholder(): void {
65
+        $this->sanitizedPlaceholder = trim(strtolower($this->placeholder));
66
+        if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) {
67
+            throw new \RuntimeException(sprintf(
68
+                'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder
69
+            ));
70
+        }
71
+        if ($this->sanitizedPlaceholder === '') {
72
+            throw new \RuntimeException('Invalid empty placeholder');
73
+        }
74
+    }
75 75
 
76
-	/**
77
-	 * @param mixed $value
78
-	 * @param string $replacement
79
-	 * @return mixed
80
-	 */
81
-	protected function substituteIfString($value, string $replacement) {
82
-		if (is_string($value)) {
83
-			return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value);
84
-		}
85
-		return $value;
86
-	}
76
+    /**
77
+     * @param mixed $value
78
+     * @param string $replacement
79
+     * @return mixed
80
+     */
81
+    protected function substituteIfString($value, string $replacement) {
82
+        if (is_string($value)) {
83
+            return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value);
84
+        }
85
+        return $value;
86
+    }
87 87
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	protected function checkPlaceholder(): void {
65 65
 		$this->sanitizedPlaceholder = trim(strtolower($this->placeholder));
66
-		if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) {
66
+		if (!(bool) \preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) {
67 67
 			throw new \RuntimeException(sprintf(
68 68
 				'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder
69 69
 			));
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	protected function substituteIfString($value, string $replacement) {
82 82
 		if (is_string($value)) {
83
-			return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value);
83
+			return str_ireplace('$'.$this->sanitizedPlaceholder, $replacement, $value);
84 84
 		}
85 85
 		return $value;
86 86
 	}
Please login to merge, or discard this patch.
apps/files_external/lib/Config/UserContext.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -33,58 +33,58 @@
 block discarded – undo
33 33
 
34 34
 class UserContext {
35 35
 
36
-	/** @var IUserSession */
37
-	private $session;
36
+    /** @var IUserSession */
37
+    private $session;
38 38
 
39
-	/** @var ShareManager */
40
-	private $shareManager;
39
+    /** @var ShareManager */
40
+    private $shareManager;
41 41
 
42
-	/** @var IRequest */
43
-	private $request;
42
+    /** @var IRequest */
43
+    private $request;
44 44
 
45
-	/** @var string */
46
-	private $userId;
45
+    /** @var string */
46
+    private $userId;
47 47
 
48
-	/** @var IUserManager */
49
-	private $userManager;
48
+    /** @var IUserManager */
49
+    private $userManager;
50 50
 
51
-	public function __construct(IUserSession $session, ShareManager $manager, IRequest $request, IUserManager $userManager) {
52
-		$this->session = $session;
53
-		$this->shareManager = $manager;
54
-		$this->request = $request;
55
-		$this->userManager = $userManager;
56
-	}
51
+    public function __construct(IUserSession $session, ShareManager $manager, IRequest $request, IUserManager $userManager) {
52
+        $this->session = $session;
53
+        $this->shareManager = $manager;
54
+        $this->request = $request;
55
+        $this->userManager = $userManager;
56
+    }
57 57
 
58
-	public function getSession(): IUserSession {
59
-		return $this->session;
60
-	}
58
+    public function getSession(): IUserSession {
59
+        return $this->session;
60
+    }
61 61
 
62
-	public function setUserId(string $userId): void {
63
-		$this->userId = $userId;
64
-	}
62
+    public function setUserId(string $userId): void {
63
+        $this->userId = $userId;
64
+    }
65 65
 
66
-	protected function getUserId(): ?string {
67
-		if ($this->userId !== null) {
68
-			return $this->userId;
69
-		}
70
-		if ($this->session && $this->session->getUser() !== null) {
71
-			return $this->session->getUser()->getUID();
72
-		}
73
-		try {
74
-			$shareToken = $this->request->getParam('token');
75
-			$share = $this->shareManager->getShareByToken($shareToken);
76
-			return $share->getShareOwner();
77
-		} catch (ShareNotFound $e) {
78
-		}
66
+    protected function getUserId(): ?string {
67
+        if ($this->userId !== null) {
68
+            return $this->userId;
69
+        }
70
+        if ($this->session && $this->session->getUser() !== null) {
71
+            return $this->session->getUser()->getUID();
72
+        }
73
+        try {
74
+            $shareToken = $this->request->getParam('token');
75
+            $share = $this->shareManager->getShareByToken($shareToken);
76
+            return $share->getShareOwner();
77
+        } catch (ShareNotFound $e) {
78
+        }
79 79
 
80
-		return null;
81
-	}
80
+        return null;
81
+    }
82 82
 
83
-	protected function getUser(): ?IUser {
84
-		$userId = $this->getUserId();
85
-		if ($userId !== null) {
86
-			return $this->userManager->get($userId);
87
-		}
88
-		return null;
89
-	}
83
+    protected function getUser(): ?IUser {
84
+        $userId = $this->getUserId();
85
+        if ($userId !== null) {
86
+            return $this->userManager->get($userId);
87
+        }
88
+        return null;
89
+    }
90 90
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/BackendService.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 * @return Backend[]
217 217
 	 */
218 218
 	public function getAvailableBackends() {
219
-		return array_filter($this->getBackends(), function ($backend) {
219
+		return array_filter($this->getBackends(), function($backend) {
220 220
 			return !$backend->checkDependencies();
221 221
 		});
222 222
 	}
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * @return AuthMechanism[]
256 256
 	 */
257 257
 	public function getAuthMechanismsByScheme(array $schemes) {
258
-		return array_filter($this->getAuthMechanisms(), function ($authMech) use ($schemes) {
258
+		return array_filter($this->getAuthMechanisms(), function($authMech) use ($schemes) {
259 259
 			return in_array($authMech->getScheme(), $schemes, true);
260 260
 		});
261 261
 	}
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 */
323 323
 	public function registerConfigHandler(string $placeholder, callable $configHandlerLoader) {
324 324
 		$placeholder = trim(strtolower($placeholder));
325
-		if (!(bool)\preg_match('/^[a-z0-9]*$/', $placeholder)) {
325
+		if (!(bool) \preg_match('/^[a-z0-9]*$/', $placeholder)) {
326 326
 			throw new \RuntimeException(sprintf(
327 327
 				'Invalid placeholder %s, only [a-z0-9] are allowed', $placeholder
328 328
 			));
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		if ($newLoaded) {
354 354
 			// ensure those with longest placeholders come first,
355 355
 			// to avoid substring matches
356
-			uksort($this->configHandlers, function ($phA, $phB) {
356
+			uksort($this->configHandlers, function($phA, $phB) {
357 357
 				return strlen($phB) <=> strlen($phA);
358 358
 			});
359 359
 		}
Please login to merge, or discard this patch.
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -40,330 +40,330 @@
 block discarded – undo
40 40
  */
41 41
 class BackendService {
42 42
 
43
-	/** Visibility constants for VisibilityTrait */
44
-	public const VISIBILITY_NONE = 0;
45
-	public const VISIBILITY_PERSONAL = 1;
46
-	public const VISIBILITY_ADMIN = 2;
47
-	//const VISIBILITY_ALIENS = 4;
48
-
49
-	public const VISIBILITY_DEFAULT = 3; // PERSONAL | ADMIN
50
-
51
-	/** Priority constants for PriorityTrait */
52
-	public const PRIORITY_DEFAULT = 100;
53
-
54
-	/** @var IConfig */
55
-	protected $config;
56
-
57
-	/** @var bool */
58
-	private $userMountingAllowed = true;
59
-
60
-	/** @var string[] */
61
-	private $userMountingBackends = [];
62
-
63
-	/** @var Backend[] */
64
-	private $backends = [];
65
-
66
-	/** @var IBackendProvider[] */
67
-	private $backendProviders = [];
68
-
69
-	/** @var AuthMechanism[] */
70
-	private $authMechanisms = [];
71
-
72
-	/** @var IAuthMechanismProvider[] */
73
-	private $authMechanismProviders = [];
74
-
75
-	/** @var callable[] */
76
-	private $configHandlerLoaders = [];
77
-
78
-	private $configHandlers = [];
79
-
80
-	/**
81
-	 * @param IConfig $config
82
-	 */
83
-	public function __construct(
84
-		IConfig $config
85
-	) {
86
-		$this->config = $config;
87
-
88
-		// Load config values
89
-		if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') {
90
-			$this->userMountingAllowed = false;
91
-		}
92
-		$this->userMountingBackends = explode(',',
93
-			$this->config->getAppValue('files_external', 'user_mounting_backends', '')
94
-		);
95
-
96
-		// if no backend is in the list an empty string is in the array and user mounting is disabled
97
-		if ($this->userMountingBackends === ['']) {
98
-			$this->userMountingAllowed = false;
99
-		}
100
-	}
101
-
102
-	/**
103
-	 * Register a backend provider
104
-	 *
105
-	 * @since 9.1.0
106
-	 * @param IBackendProvider $provider
107
-	 */
108
-	public function registerBackendProvider(IBackendProvider $provider) {
109
-		$this->backendProviders[] = $provider;
110
-	}
111
-
112
-	private function callForRegistrations() {
113
-		static $eventSent = false;
114
-		if (!$eventSent) {
115
-			\OC::$server->getEventDispatcher()->dispatch(
116
-				'OCA\\Files_External::loadAdditionalBackends',
117
-				new GenericEvent()
118
-			);
119
-			$eventSent = true;
120
-		}
121
-	}
122
-
123
-	private function loadBackendProviders() {
124
-		$this->callForRegistrations();
125
-		foreach ($this->backendProviders as $provider) {
126
-			$this->registerBackends($provider->getBackends());
127
-		}
128
-		$this->backendProviders = [];
129
-	}
130
-
131
-	/**
132
-	 * Register an auth mechanism provider
133
-	 *
134
-	 * @since 9.1.0
135
-	 * @param IAuthMechanismProvider $provider
136
-	 */
137
-	public function registerAuthMechanismProvider(IAuthMechanismProvider $provider) {
138
-		$this->authMechanismProviders[] = $provider;
139
-	}
140
-
141
-	private function loadAuthMechanismProviders() {
142
-		$this->callForRegistrations();
143
-		foreach ($this->authMechanismProviders as $provider) {
144
-			$this->registerAuthMechanisms($provider->getAuthMechanisms());
145
-		}
146
-		$this->authMechanismProviders = [];
147
-	}
148
-
149
-	/**
150
-	 * Register a backend
151
-	 *
152
-	 * @deprecated 9.1.0 use registerBackendProvider()
153
-	 * @param Backend $backend
154
-	 */
155
-	public function registerBackend(Backend $backend) {
156
-		if (!$this->isAllowedUserBackend($backend)) {
157
-			$backend->removeVisibility(BackendService::VISIBILITY_PERSONAL);
158
-		}
159
-		foreach ($backend->getIdentifierAliases() as $alias) {
160
-			$this->backends[$alias] = $backend;
161
-		}
162
-	}
163
-
164
-	/**
165
-	 * @deprecated 9.1.0 use registerBackendProvider()
166
-	 * @param Backend[] $backends
167
-	 */
168
-	public function registerBackends(array $backends) {
169
-		foreach ($backends as $backend) {
170
-			$this->registerBackend($backend);
171
-		}
172
-	}
173
-	/**
174
-	 * Register an authentication mechanism
175
-	 *
176
-	 * @deprecated 9.1.0 use registerAuthMechanismProvider()
177
-	 * @param AuthMechanism $authMech
178
-	 */
179
-	public function registerAuthMechanism(AuthMechanism $authMech) {
180
-		if (!$this->isAllowedAuthMechanism($authMech)) {
181
-			$authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL);
182
-		}
183
-		foreach ($authMech->getIdentifierAliases() as $alias) {
184
-			$this->authMechanisms[$alias] = $authMech;
185
-		}
186
-	}
187
-
188
-	/**
189
-	 * @deprecated 9.1.0 use registerAuthMechanismProvider()
190
-	 * @param AuthMechanism[] $mechanisms
191
-	 */
192
-	public function registerAuthMechanisms(array $mechanisms) {
193
-		foreach ($mechanisms as $mechanism) {
194
-			$this->registerAuthMechanism($mechanism);
195
-		}
196
-	}
197
-
198
-	/**
199
-	 * Get all backends
200
-	 *
201
-	 * @return Backend[]
202
-	 */
203
-	public function getBackends() {
204
-		$this->loadBackendProviders();
205
-		// only return real identifiers, no aliases
206
-		$backends = [];
207
-		foreach ($this->backends as $backend) {
208
-			$backends[$backend->getIdentifier()] = $backend;
209
-		}
210
-		return $backends;
211
-	}
212
-
213
-	/**
214
-	 * Get all available backends
215
-	 *
216
-	 * @return Backend[]
217
-	 */
218
-	public function getAvailableBackends() {
219
-		return array_filter($this->getBackends(), function ($backend) {
220
-			return !$backend->checkDependencies();
221
-		});
222
-	}
223
-
224
-	/**
225
-	 * @param string $identifier
226
-	 * @return Backend|null
227
-	 */
228
-	public function getBackend($identifier) {
229
-		$this->loadBackendProviders();
230
-		if (isset($this->backends[$identifier])) {
231
-			return $this->backends[$identifier];
232
-		}
233
-		return null;
234
-	}
235
-
236
-	/**
237
-	 * Get all authentication mechanisms
238
-	 *
239
-	 * @return AuthMechanism[]
240
-	 */
241
-	public function getAuthMechanisms() {
242
-		$this->loadAuthMechanismProviders();
243
-		// only return real identifiers, no aliases
244
-		$mechanisms = [];
245
-		foreach ($this->authMechanisms as $mechanism) {
246
-			$mechanisms[$mechanism->getIdentifier()] = $mechanism;
247
-		}
248
-		return $mechanisms;
249
-	}
250
-
251
-	/**
252
-	 * Get all authentication mechanisms for schemes
253
-	 *
254
-	 * @param string[] $schemes
255
-	 * @return AuthMechanism[]
256
-	 */
257
-	public function getAuthMechanismsByScheme(array $schemes) {
258
-		return array_filter($this->getAuthMechanisms(), function ($authMech) use ($schemes) {
259
-			return in_array($authMech->getScheme(), $schemes, true);
260
-		});
261
-	}
262
-
263
-	/**
264
-	 * @param string $identifier
265
-	 * @return AuthMechanism|null
266
-	 */
267
-	public function getAuthMechanism($identifier) {
268
-		$this->loadAuthMechanismProviders();
269
-		if (isset($this->authMechanisms[$identifier])) {
270
-			return $this->authMechanisms[$identifier];
271
-		}
272
-		return null;
273
-	}
274
-
275
-	/**
276
-	 * @return bool
277
-	 */
278
-	public function isUserMountingAllowed() {
279
-		return $this->userMountingAllowed;
280
-	}
281
-
282
-	/**
283
-	 * Check a backend if a user is allowed to mount it
284
-	 *
285
-	 * @param Backend $backend
286
-	 * @return bool
287
-	 */
288
-	protected function isAllowedUserBackend(Backend $backend) {
289
-		if ($this->userMountingAllowed &&
290
-			array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
291
-		) {
292
-			return true;
293
-		}
294
-		return false;
295
-	}
296
-
297
-	/**
298
-	 * Check an authentication mechanism if a user is allowed to use it
299
-	 *
300
-	 * @param AuthMechanism $authMechanism
301
-	 * @return bool
302
-	 */
303
-	protected function isAllowedAuthMechanism(AuthMechanism $authMechanism) {
304
-		return true; // not implemented
305
-	}
306
-
307
-	/**
308
-	 * registers a configuration handler
309
-	 *
310
-	 * The function of the provided $placeholder is mostly to act a sorting
311
-	 * criteria, so longer placeholders are replaced first. This avoids
312
-	 * "$user" overwriting parts of "$userMail" and "$userLang", for example.
313
-	 * The provided value should not contain the $ prefix, only a-z0-9 are
314
-	 * allowed. Upper case letters are lower cased, the replacement is case-
315
-	 * insensitive.
316
-	 *
317
-	 * The configHandlerLoader should just instantiate the handler on demand.
318
-	 * For now all handlers are instantiated when a mount is loaded, independent
319
-	 * of whether the placeholder is present or not. This may change in future.
320
-	 *
321
-	 * @since 16.0.0
322
-	 */
323
-	public function registerConfigHandler(string $placeholder, callable $configHandlerLoader) {
324
-		$placeholder = trim(strtolower($placeholder));
325
-		if (!(bool)\preg_match('/^[a-z0-9]*$/', $placeholder)) {
326
-			throw new \RuntimeException(sprintf(
327
-				'Invalid placeholder %s, only [a-z0-9] are allowed', $placeholder
328
-			));
329
-		}
330
-		if ($placeholder === '') {
331
-			throw new \RuntimeException('Invalid empty placeholder');
332
-		}
333
-		if (isset($this->configHandlerLoaders[$placeholder]) || isset($this->configHandlers[$placeholder])) {
334
-			throw new \RuntimeException(sprintf('A handler is already registered for %s', $placeholder));
335
-		}
336
-		$this->configHandlerLoaders[$placeholder] = $configHandlerLoader;
337
-	}
338
-
339
-	protected function loadConfigHandlers():void {
340
-		$this->callForRegistrations();
341
-		$newLoaded = false;
342
-		foreach ($this->configHandlerLoaders as $placeholder => $loader) {
343
-			$handler = $loader();
344
-			if (!$handler instanceof IConfigHandler) {
345
-				throw new \RuntimeException(sprintf(
346
-					'Handler for %s is not an instance of IConfigHandler', $placeholder
347
-				));
348
-			}
349
-			$this->configHandlers[$placeholder] = $handler;
350
-			$newLoaded = true;
351
-		}
352
-		$this->configHandlerLoaders = [];
353
-		if ($newLoaded) {
354
-			// ensure those with longest placeholders come first,
355
-			// to avoid substring matches
356
-			uksort($this->configHandlers, function ($phA, $phB) {
357
-				return strlen($phB) <=> strlen($phA);
358
-			});
359
-		}
360
-	}
361
-
362
-	/**
363
-	 * @since 16.0.0
364
-	 */
365
-	public function getConfigHandlers() {
366
-		$this->loadConfigHandlers();
367
-		return $this->configHandlers;
368
-	}
43
+    /** Visibility constants for VisibilityTrait */
44
+    public const VISIBILITY_NONE = 0;
45
+    public const VISIBILITY_PERSONAL = 1;
46
+    public const VISIBILITY_ADMIN = 2;
47
+    //const VISIBILITY_ALIENS = 4;
48
+
49
+    public const VISIBILITY_DEFAULT = 3; // PERSONAL | ADMIN
50
+
51
+    /** Priority constants for PriorityTrait */
52
+    public const PRIORITY_DEFAULT = 100;
53
+
54
+    /** @var IConfig */
55
+    protected $config;
56
+
57
+    /** @var bool */
58
+    private $userMountingAllowed = true;
59
+
60
+    /** @var string[] */
61
+    private $userMountingBackends = [];
62
+
63
+    /** @var Backend[] */
64
+    private $backends = [];
65
+
66
+    /** @var IBackendProvider[] */
67
+    private $backendProviders = [];
68
+
69
+    /** @var AuthMechanism[] */
70
+    private $authMechanisms = [];
71
+
72
+    /** @var IAuthMechanismProvider[] */
73
+    private $authMechanismProviders = [];
74
+
75
+    /** @var callable[] */
76
+    private $configHandlerLoaders = [];
77
+
78
+    private $configHandlers = [];
79
+
80
+    /**
81
+     * @param IConfig $config
82
+     */
83
+    public function __construct(
84
+        IConfig $config
85
+    ) {
86
+        $this->config = $config;
87
+
88
+        // Load config values
89
+        if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') {
90
+            $this->userMountingAllowed = false;
91
+        }
92
+        $this->userMountingBackends = explode(',',
93
+            $this->config->getAppValue('files_external', 'user_mounting_backends', '')
94
+        );
95
+
96
+        // if no backend is in the list an empty string is in the array and user mounting is disabled
97
+        if ($this->userMountingBackends === ['']) {
98
+            $this->userMountingAllowed = false;
99
+        }
100
+    }
101
+
102
+    /**
103
+     * Register a backend provider
104
+     *
105
+     * @since 9.1.0
106
+     * @param IBackendProvider $provider
107
+     */
108
+    public function registerBackendProvider(IBackendProvider $provider) {
109
+        $this->backendProviders[] = $provider;
110
+    }
111
+
112
+    private function callForRegistrations() {
113
+        static $eventSent = false;
114
+        if (!$eventSent) {
115
+            \OC::$server->getEventDispatcher()->dispatch(
116
+                'OCA\\Files_External::loadAdditionalBackends',
117
+                new GenericEvent()
118
+            );
119
+            $eventSent = true;
120
+        }
121
+    }
122
+
123
+    private function loadBackendProviders() {
124
+        $this->callForRegistrations();
125
+        foreach ($this->backendProviders as $provider) {
126
+            $this->registerBackends($provider->getBackends());
127
+        }
128
+        $this->backendProviders = [];
129
+    }
130
+
131
+    /**
132
+     * Register an auth mechanism provider
133
+     *
134
+     * @since 9.1.0
135
+     * @param IAuthMechanismProvider $provider
136
+     */
137
+    public function registerAuthMechanismProvider(IAuthMechanismProvider $provider) {
138
+        $this->authMechanismProviders[] = $provider;
139
+    }
140
+
141
+    private function loadAuthMechanismProviders() {
142
+        $this->callForRegistrations();
143
+        foreach ($this->authMechanismProviders as $provider) {
144
+            $this->registerAuthMechanisms($provider->getAuthMechanisms());
145
+        }
146
+        $this->authMechanismProviders = [];
147
+    }
148
+
149
+    /**
150
+     * Register a backend
151
+     *
152
+     * @deprecated 9.1.0 use registerBackendProvider()
153
+     * @param Backend $backend
154
+     */
155
+    public function registerBackend(Backend $backend) {
156
+        if (!$this->isAllowedUserBackend($backend)) {
157
+            $backend->removeVisibility(BackendService::VISIBILITY_PERSONAL);
158
+        }
159
+        foreach ($backend->getIdentifierAliases() as $alias) {
160
+            $this->backends[$alias] = $backend;
161
+        }
162
+    }
163
+
164
+    /**
165
+     * @deprecated 9.1.0 use registerBackendProvider()
166
+     * @param Backend[] $backends
167
+     */
168
+    public function registerBackends(array $backends) {
169
+        foreach ($backends as $backend) {
170
+            $this->registerBackend($backend);
171
+        }
172
+    }
173
+    /**
174
+     * Register an authentication mechanism
175
+     *
176
+     * @deprecated 9.1.0 use registerAuthMechanismProvider()
177
+     * @param AuthMechanism $authMech
178
+     */
179
+    public function registerAuthMechanism(AuthMechanism $authMech) {
180
+        if (!$this->isAllowedAuthMechanism($authMech)) {
181
+            $authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL);
182
+        }
183
+        foreach ($authMech->getIdentifierAliases() as $alias) {
184
+            $this->authMechanisms[$alias] = $authMech;
185
+        }
186
+    }
187
+
188
+    /**
189
+     * @deprecated 9.1.0 use registerAuthMechanismProvider()
190
+     * @param AuthMechanism[] $mechanisms
191
+     */
192
+    public function registerAuthMechanisms(array $mechanisms) {
193
+        foreach ($mechanisms as $mechanism) {
194
+            $this->registerAuthMechanism($mechanism);
195
+        }
196
+    }
197
+
198
+    /**
199
+     * Get all backends
200
+     *
201
+     * @return Backend[]
202
+     */
203
+    public function getBackends() {
204
+        $this->loadBackendProviders();
205
+        // only return real identifiers, no aliases
206
+        $backends = [];
207
+        foreach ($this->backends as $backend) {
208
+            $backends[$backend->getIdentifier()] = $backend;
209
+        }
210
+        return $backends;
211
+    }
212
+
213
+    /**
214
+     * Get all available backends
215
+     *
216
+     * @return Backend[]
217
+     */
218
+    public function getAvailableBackends() {
219
+        return array_filter($this->getBackends(), function ($backend) {
220
+            return !$backend->checkDependencies();
221
+        });
222
+    }
223
+
224
+    /**
225
+     * @param string $identifier
226
+     * @return Backend|null
227
+     */
228
+    public function getBackend($identifier) {
229
+        $this->loadBackendProviders();
230
+        if (isset($this->backends[$identifier])) {
231
+            return $this->backends[$identifier];
232
+        }
233
+        return null;
234
+    }
235
+
236
+    /**
237
+     * Get all authentication mechanisms
238
+     *
239
+     * @return AuthMechanism[]
240
+     */
241
+    public function getAuthMechanisms() {
242
+        $this->loadAuthMechanismProviders();
243
+        // only return real identifiers, no aliases
244
+        $mechanisms = [];
245
+        foreach ($this->authMechanisms as $mechanism) {
246
+            $mechanisms[$mechanism->getIdentifier()] = $mechanism;
247
+        }
248
+        return $mechanisms;
249
+    }
250
+
251
+    /**
252
+     * Get all authentication mechanisms for schemes
253
+     *
254
+     * @param string[] $schemes
255
+     * @return AuthMechanism[]
256
+     */
257
+    public function getAuthMechanismsByScheme(array $schemes) {
258
+        return array_filter($this->getAuthMechanisms(), function ($authMech) use ($schemes) {
259
+            return in_array($authMech->getScheme(), $schemes, true);
260
+        });
261
+    }
262
+
263
+    /**
264
+     * @param string $identifier
265
+     * @return AuthMechanism|null
266
+     */
267
+    public function getAuthMechanism($identifier) {
268
+        $this->loadAuthMechanismProviders();
269
+        if (isset($this->authMechanisms[$identifier])) {
270
+            return $this->authMechanisms[$identifier];
271
+        }
272
+        return null;
273
+    }
274
+
275
+    /**
276
+     * @return bool
277
+     */
278
+    public function isUserMountingAllowed() {
279
+        return $this->userMountingAllowed;
280
+    }
281
+
282
+    /**
283
+     * Check a backend if a user is allowed to mount it
284
+     *
285
+     * @param Backend $backend
286
+     * @return bool
287
+     */
288
+    protected function isAllowedUserBackend(Backend $backend) {
289
+        if ($this->userMountingAllowed &&
290
+            array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
291
+        ) {
292
+            return true;
293
+        }
294
+        return false;
295
+    }
296
+
297
+    /**
298
+     * Check an authentication mechanism if a user is allowed to use it
299
+     *
300
+     * @param AuthMechanism $authMechanism
301
+     * @return bool
302
+     */
303
+    protected function isAllowedAuthMechanism(AuthMechanism $authMechanism) {
304
+        return true; // not implemented
305
+    }
306
+
307
+    /**
308
+     * registers a configuration handler
309
+     *
310
+     * The function of the provided $placeholder is mostly to act a sorting
311
+     * criteria, so longer placeholders are replaced first. This avoids
312
+     * "$user" overwriting parts of "$userMail" and "$userLang", for example.
313
+     * The provided value should not contain the $ prefix, only a-z0-9 are
314
+     * allowed. Upper case letters are lower cased, the replacement is case-
315
+     * insensitive.
316
+     *
317
+     * The configHandlerLoader should just instantiate the handler on demand.
318
+     * For now all handlers are instantiated when a mount is loaded, independent
319
+     * of whether the placeholder is present or not. This may change in future.
320
+     *
321
+     * @since 16.0.0
322
+     */
323
+    public function registerConfigHandler(string $placeholder, callable $configHandlerLoader) {
324
+        $placeholder = trim(strtolower($placeholder));
325
+        if (!(bool)\preg_match('/^[a-z0-9]*$/', $placeholder)) {
326
+            throw new \RuntimeException(sprintf(
327
+                'Invalid placeholder %s, only [a-z0-9] are allowed', $placeholder
328
+            ));
329
+        }
330
+        if ($placeholder === '') {
331
+            throw new \RuntimeException('Invalid empty placeholder');
332
+        }
333
+        if (isset($this->configHandlerLoaders[$placeholder]) || isset($this->configHandlers[$placeholder])) {
334
+            throw new \RuntimeException(sprintf('A handler is already registered for %s', $placeholder));
335
+        }
336
+        $this->configHandlerLoaders[$placeholder] = $configHandlerLoader;
337
+    }
338
+
339
+    protected function loadConfigHandlers():void {
340
+        $this->callForRegistrations();
341
+        $newLoaded = false;
342
+        foreach ($this->configHandlerLoaders as $placeholder => $loader) {
343
+            $handler = $loader();
344
+            if (!$handler instanceof IConfigHandler) {
345
+                throw new \RuntimeException(sprintf(
346
+                    'Handler for %s is not an instance of IConfigHandler', $placeholder
347
+                ));
348
+            }
349
+            $this->configHandlers[$placeholder] = $handler;
350
+            $newLoaded = true;
351
+        }
352
+        $this->configHandlerLoaders = [];
353
+        if ($newLoaded) {
354
+            // ensure those with longest placeholders come first,
355
+            // to avoid substring matches
356
+            uksort($this->configHandlers, function ($phA, $phB) {
357
+                return strlen($phB) <=> strlen($phA);
358
+            });
359
+        }
360
+    }
361
+
362
+    /**
363
+     * @since 16.0.0
364
+     */
365
+    public function getConfigHandlers() {
366
+        $this->loadConfigHandlers();
367
+        return $this->configHandlers;
368
+    }
369 369
 }
Please login to merge, or discard this patch.