Passed
Push — master ( 410e29...0c7bed )
by Morris
32:13 queued 21:01
created
lib/public/Files/StorageTimeoutException.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -27,15 +27,15 @@
 block discarded – undo
27 27
  */
28 28
 class StorageTimeoutException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * StorageTimeoutException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param \Exception|null $previous
35
-	 * @since 9.0.0
36
-	 */
37
-	public function __construct($message = '', \Exception $previous = null) {
38
-		$l = \OC::$server->getL10N('core');
39
-		parent::__construct($l->t('Storage connection timeout. %s', [$message]), self::STATUS_TIMEOUT, $previous);
40
-	}
30
+    /**
31
+     * StorageTimeoutException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param \Exception|null $previous
35
+     * @since 9.0.0
36
+     */
37
+    public function __construct($message = '', \Exception $previous = null) {
38
+        $l = \OC::$server->getL10N('core');
39
+        parent::__construct($l->t('Storage connection timeout. %s', [$message]), self::STATUS_TIMEOUT, $previous);
40
+    }
41 41
 }
Please login to merge, or discard this patch.
lib/public/Files/StorageConnectionException.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -27,15 +27,15 @@
 block discarded – undo
27 27
  */
28 28
 class StorageConnectionException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * StorageConnectionException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param \Exception|null $previous
35
-	 * @since 9.0.0
36
-	 */
37
-	public function __construct($message = '', \Exception $previous = null) {
38
-		$l = \OC::$server->getL10N('core');
39
-		parent::__construct($l->t('Storage connection error. %s', [$message]), self::STATUS_NETWORK_ERROR, $previous);
40
-	}
30
+    /**
31
+     * StorageConnectionException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param \Exception|null $previous
35
+     * @since 9.0.0
36
+     */
37
+    public function __construct($message = '', \Exception $previous = null) {
38
+        $l = \OC::$server->getL10N('core');
39
+        parent::__construct($l->t('Storage connection error. %s', [$message]), self::STATUS_NETWORK_ERROR, $previous);
40
+    }
41 41
 }
Please login to merge, or discard this patch.
core/Controller/ContactsMenuController.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -33,46 +33,46 @@
 block discarded – undo
33 33
 
34 34
 class ContactsMenuController extends Controller {
35 35
 
36
-	/** @var Manager */
37
-	private $manager;
36
+    /** @var Manager */
37
+    private $manager;
38 38
 
39
-	/** @var IUserSession */
40
-	private $userSession;
39
+    /** @var IUserSession */
40
+    private $userSession;
41 41
 
42
-	/**
43
-	 * @param IRequest $request
44
-	 * @param IUserSession $userSession
45
-	 * @param Manager $manager
46
-	 */
47
-	public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) {
48
-		parent::__construct('core', $request);
49
-		$this->userSession = $userSession;
50
-		$this->manager = $manager;
51
-	}
42
+    /**
43
+     * @param IRequest $request
44
+     * @param IUserSession $userSession
45
+     * @param Manager $manager
46
+     */
47
+    public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) {
48
+        parent::__construct('core', $request);
49
+        $this->userSession = $userSession;
50
+        $this->manager = $manager;
51
+    }
52 52
 
53
-	/**
54
-	 * @NoAdminRequired
55
-	 *
56
-	 * @param string|null filter
57
-	 * @return \JsonSerializable[]
58
-	 */
59
-	public function index($filter = null) {
60
-		return $this->manager->getEntries($this->userSession->getUser(), $filter);
61
-	}
53
+    /**
54
+     * @NoAdminRequired
55
+     *
56
+     * @param string|null filter
57
+     * @return \JsonSerializable[]
58
+     */
59
+    public function index($filter = null) {
60
+        return $this->manager->getEntries($this->userSession->getUser(), $filter);
61
+    }
62 62
 
63
-	/**
64
-	 * @NoAdminRequired
65
-	 *
66
-	 * @param integer $shareType
67
-	 * @param string $shareWith
68
-	 * @return JSONResponse|\JsonSerializable
69
-	 */
70
-	public function findOne($shareType, $shareWith) {
71
-		$contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);
63
+    /**
64
+     * @NoAdminRequired
65
+     *
66
+     * @param integer $shareType
67
+     * @param string $shareWith
68
+     * @return JSONResponse|\JsonSerializable
69
+     */
70
+    public function findOne($shareType, $shareWith) {
71
+        $contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);
72 72
 
73
-		if ($contact) {
74
-			return $contact;
75
-		}
76
-		return new JSONResponse([], Http::STATUS_NOT_FOUND);
77
-	}
73
+        if ($contact) {
74
+            return $contact;
75
+        }
76
+        return new JSONResponse([], Http::STATUS_NOT_FOUND);
77
+    }
78 78
 }
Please login to merge, or discard this patch.
apps/comments/appinfo/routes.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
  */
22 22
 
23 23
 return [
24
-	'routes' => [
25
-		['name' => 'Notifications#view', 'url' => '/notifications/view/{id}', 'verb' => 'GET'],
26
-	]
24
+    'routes' => [
25
+        ['name' => 'Notifications#view', 'url' => '/notifications/view/{id}', 'verb' => 'GET'],
26
+    ]
27 27
 ];
Please login to merge, or discard this patch.
files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,15 +29,15 @@
 block discarded – undo
29 29
  * Authentication mechanism or backend has insufficient data
30 30
  */
31 31
 class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException {
32
-	/**
33
-	 * StorageNotAvailableException constructor.
34
-	 *
35
-	 * @param string $message
36
-	 * @param int $code
37
-	 * @param \Exception|null $previous
38
-	 * @since 6.0.0
39
-	 */
40
-	public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) {
41
-		parent::__construct($message, $code, $previous);
42
-	}
32
+    /**
33
+     * StorageNotAvailableException constructor.
34
+     *
35
+     * @param string $message
36
+     * @param int $code
37
+     * @param \Exception|null $previous
38
+     * @since 6.0.0
39
+     */
40
+    public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) {
41
+        parent::__construct($message, $code, $previous);
42
+    }
43 43
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/IdentifierTrait.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -28,76 +28,76 @@
 block discarded – undo
28 28
  */
29 29
 trait IdentifierTrait {
30 30
 
31
-	/** @var string */
32
-	protected $identifier;
31
+    /** @var string */
32
+    protected $identifier;
33 33
 
34
-	/** @var string[] */
35
-	protected $identifierAliases = [];
34
+    /** @var string[] */
35
+    protected $identifierAliases = [];
36 36
 
37
-	/** @var IdentifierTrait */
38
-	protected $deprecateTo = null;
37
+    /** @var IdentifierTrait */
38
+    protected $deprecateTo = null;
39 39
 
40
-	/**
41
-	 * @return string
42
-	 */
43
-	public function getIdentifier() {
44
-		return $this->identifier;
45
-	}
40
+    /**
41
+     * @return string
42
+     */
43
+    public function getIdentifier() {
44
+        return $this->identifier;
45
+    }
46 46
 
47
-	/**
48
-	 * @param string $identifier
49
-	 * @return $this
50
-	 */
51
-	public function setIdentifier($identifier) {
52
-		$this->identifier = $identifier;
53
-		$this->identifierAliases[] = $identifier;
54
-		return $this;
55
-	}
47
+    /**
48
+     * @param string $identifier
49
+     * @return $this
50
+     */
51
+    public function setIdentifier($identifier) {
52
+        $this->identifier = $identifier;
53
+        $this->identifierAliases[] = $identifier;
54
+        return $this;
55
+    }
56 56
 
57
-	/**
58
-	 * @return string[]
59
-	 */
60
-	public function getIdentifierAliases() {
61
-		return $this->identifierAliases;
62
-	}
57
+    /**
58
+     * @return string[]
59
+     */
60
+    public function getIdentifierAliases() {
61
+        return $this->identifierAliases;
62
+    }
63 63
 
64
-	/**
65
-	 * @param string $alias
66
-	 * @return $this
67
-	 */
68
-	public function addIdentifierAlias($alias) {
69
-		$this->identifierAliases[] = $alias;
70
-		return $this;
71
-	}
64
+    /**
65
+     * @param string $alias
66
+     * @return $this
67
+     */
68
+    public function addIdentifierAlias($alias) {
69
+        $this->identifierAliases[] = $alias;
70
+        return $this;
71
+    }
72 72
 
73
-	/**
74
-	 * @return object|null
75
-	 */
76
-	public function getDeprecateTo() {
77
-		return $this->deprecateTo;
78
-	}
73
+    /**
74
+     * @return object|null
75
+     */
76
+    public function getDeprecateTo() {
77
+        return $this->deprecateTo;
78
+    }
79 79
 
80
-	/**
81
-	 * @param object $destinationObject
82
-	 * @return self
83
-	 */
84
-	public function deprecateTo($destinationObject) {
85
-		$this->deprecateTo = $destinationObject;
86
-		return $this;
87
-	}
80
+    /**
81
+     * @param object $destinationObject
82
+     * @return self
83
+     */
84
+    public function deprecateTo($destinationObject) {
85
+        $this->deprecateTo = $destinationObject;
86
+        return $this;
87
+    }
88 88
 
89
-	/**
90
-	 * @return array
91
-	 */
92
-	public function jsonSerializeIdentifier() {
93
-		$data = [
94
-			'identifier' => $this->identifier,
95
-			'identifierAliases' => $this->identifierAliases,
96
-		];
97
-		if ($this->deprecateTo) {
98
-			$data['deprecateTo'] = $this->deprecateTo->getIdentifier();
99
-		}
100
-		return $data;
101
-	}
89
+    /**
90
+     * @return array
91
+     */
92
+    public function jsonSerializeIdentifier() {
93
+        $data = [
94
+            'identifier' => $this->identifier,
95
+            'identifierAliases' => $this->identifierAliases,
96
+        ];
97
+        if ($this->deprecateTo) {
98
+            $data['deprecateTo'] = $this->deprecateTo->getIdentifier();
99
+        }
100
+        return $data;
101
+    }
102 102
 
103 103
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Create.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -128,32 +128,32 @@  discard block
 block discarded – undo
128 128
 		$authBackend = $this->backendService->getAuthMechanism($authIdentifier);
129 129
 
130 130
 		if (!Filesystem::isValidPath($mountPoint)) {
131
-			$output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
131
+			$output->writeln('<error>Invalid mountpoint "'.$mountPoint.'"</error>');
132 132
 			return 1;
133 133
 		}
134 134
 		if (is_null($storageBackend)) {
135
-			$output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
135
+			$output->writeln('<error>Storage backend with identifier "'.$storageIdentifier.'" not found (see `occ files_external:backends` for possible values)</error>');
136 136
 			return 404;
137 137
 		}
138 138
 		if (is_null($authBackend)) {
139
-			$output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
139
+			$output->writeln('<error>Authentication backend with identifier "'.$authIdentifier.'" not found (see `occ files_external:backends` for possible values)</error>');
140 140
 			return 404;
141 141
 		}
142 142
 		$supportedSchemes = array_keys($storageBackend->getAuthSchemes());
143 143
 		if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
144
-			$output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
144
+			$output->writeln('<error>Authentication backend "'.$authIdentifier.'" not valid for storage backend "'.$storageIdentifier.'" (see `occ files_external:backends storage '.$storageIdentifier.'` for possible values)</error>');
145 145
 			return 1;
146 146
 		}
147 147
 
148 148
 		$config = [];
149 149
 		foreach ($configInput as $configOption) {
150 150
 			if (!strpos($configOption, '=')) {
151
-				$output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
151
+				$output->writeln('<error>Invalid mount configuration option "'.$configOption.'"</error>');
152 152
 				return 1;
153 153
 			}
154 154
 			list($key, $value) = explode('=', $configOption, 2);
155 155
 			if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
156
-				$output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
156
+				$output->writeln('<error>Unknown configuration for backends "'.$key.'"</error>');
157 157
 				return 1;
158 158
 			}
159 159
 			$config[$key] = $value;
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 
168 168
 		if ($user) {
169 169
 			if (!$this->userManager->userExists($user)) {
170
-				$output->writeln('<error>User "' . $user . '" not found</error>');
170
+				$output->writeln('<error>User "'.$user.'" not found</error>');
171 171
 				return 1;
172 172
 			}
173 173
 			$mount->setApplicableUsers([$user]);
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
 		} else {
179 179
 			$this->getStorageService($user)->addStorage($mount);
180 180
 			if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
181
-				$output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
181
+				$output->writeln('<info>Storage created with id '.$mount->getId().'</info>');
182 182
 			} else {
183
-				$output->writeln((string)$mount->getId());
183
+				$output->writeln((string) $mount->getId());
184 184
 			}
185 185
 		}
186 186
 		return 0;
Please login to merge, or discard this patch.
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -44,182 +44,182 @@
 block discarded – undo
44 44
 use Symfony\Component\Console\Output\OutputInterface;
45 45
 
46 46
 class Create extends Base {
47
-	/**
48
-	 * @var GlobalStoragesService
49
-	 */
50
-	private $globalService;
51
-
52
-	/**
53
-	 * @var UserStoragesService
54
-	 */
55
-	private $userService;
56
-
57
-	/**
58
-	 * @var IUserManager
59
-	 */
60
-	private $userManager;
61
-
62
-	/** @var BackendService */
63
-	private $backendService;
64
-
65
-	/** @var IUserSession */
66
-	private $userSession;
67
-
68
-	public function __construct(GlobalStoragesService $globalService,
69
-						 UserStoragesService $userService,
70
-						 IUserManager $userManager,
71
-						 IUserSession $userSession,
72
-						 BackendService $backendService
73
-	) {
74
-		parent::__construct();
75
-		$this->globalService = $globalService;
76
-		$this->userService = $userService;
77
-		$this->userManager = $userManager;
78
-		$this->userSession = $userSession;
79
-		$this->backendService = $backendService;
80
-	}
81
-
82
-	protected function configure() {
83
-		$this
84
-			->setName('files_external:create')
85
-			->setDescription('Create a new mount configuration')
86
-			->addOption(
87
-				'user',
88
-				'',
89
-				InputOption::VALUE_OPTIONAL,
90
-				'user to add the mount configuration for, if not set the mount will be added as system mount'
91
-			)
92
-			->addArgument(
93
-				'mount_point',
94
-				InputArgument::REQUIRED,
95
-				'mount point for the new mount'
96
-			)
97
-			->addArgument(
98
-				'storage_backend',
99
-				InputArgument::REQUIRED,
100
-				'storage backend identifier for the new mount, see `occ files_external:backends` for possible values'
101
-			)
102
-			->addArgument(
103
-				'authentication_backend',
104
-				InputArgument::REQUIRED,
105
-				'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values'
106
-			)
107
-			->addOption(
108
-				'config',
109
-				'c',
110
-				InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
111
-				'Mount configuration option in key=value format'
112
-			)
113
-			->addOption(
114
-				'dry',
115
-				'',
116
-				InputOption::VALUE_NONE,
117
-				'Don\'t save the created mount, only list the new mount'
118
-			);
119
-		parent::configure();
120
-	}
121
-
122
-	protected function execute(InputInterface $input, OutputInterface $output): int {
123
-		$user = $input->getOption('user');
124
-		$mountPoint = $input->getArgument('mount_point');
125
-		$storageIdentifier = $input->getArgument('storage_backend');
126
-		$authIdentifier = $input->getArgument('authentication_backend');
127
-		$configInput = $input->getOption('config');
128
-
129
-		$storageBackend = $this->backendService->getBackend($storageIdentifier);
130
-		$authBackend = $this->backendService->getAuthMechanism($authIdentifier);
131
-
132
-		if (!Filesystem::isValidPath($mountPoint)) {
133
-			$output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
134
-			return 1;
135
-		}
136
-		if (is_null($storageBackend)) {
137
-			$output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
138
-			return 404;
139
-		}
140
-		if (is_null($authBackend)) {
141
-			$output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
142
-			return 404;
143
-		}
144
-		$supportedSchemes = array_keys($storageBackend->getAuthSchemes());
145
-		if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
146
-			$output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
147
-			return 1;
148
-		}
149
-
150
-		$config = [];
151
-		foreach ($configInput as $configOption) {
152
-			if (!strpos($configOption, '=')) {
153
-				$output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
154
-				return 1;
155
-			}
156
-			list($key, $value) = explode('=', $configOption, 2);
157
-			if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
158
-				$output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
159
-				return 1;
160
-			}
161
-			$config[$key] = $value;
162
-		}
163
-
164
-		$mount = new StorageConfig();
165
-		$mount->setMountPoint($mountPoint);
166
-		$mount->setBackend($storageBackend);
167
-		$mount->setAuthMechanism($authBackend);
168
-		$mount->setBackendOptions($config);
169
-
170
-		if ($user) {
171
-			if (!$this->userManager->userExists($user)) {
172
-				$output->writeln('<error>User "' . $user . '" not found</error>');
173
-				return 1;
174
-			}
175
-			$mount->setApplicableUsers([$user]);
176
-		}
177
-
178
-		if ($input->getOption('dry')) {
179
-			$this->showMount($user, $mount, $input, $output);
180
-		} else {
181
-			$this->getStorageService($user)->addStorage($mount);
182
-			if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
183
-				$output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
184
-			} else {
185
-				$output->writeln((string)$mount->getId());
186
-			}
187
-		}
188
-		return 0;
189
-	}
190
-
191
-	private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
192
-		$params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
193
-		foreach ($params as $param) {
194
-			/** @var DefinitionParameter $param */
195
-			if ($param->getName() === $key) {
196
-				if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) {
197
-					$value = ($value === 'true');
198
-				}
199
-				return true;
200
-			}
201
-		}
202
-		return false;
203
-	}
204
-
205
-	private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
206
-		$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
207
-		$listInput = new ArrayInput([], $listCommand->getDefinition());
208
-		$listInput->setOption('output', $input->getOption('output'));
209
-		$listInput->setOption('show-password', true);
210
-		$listCommand->listMounts($user, [$mount], $listInput, $output);
211
-	}
212
-
213
-	protected function getStorageService($userId) {
214
-		if (!empty($userId)) {
215
-			$user = $this->userManager->get($userId);
216
-			if (is_null($user)) {
217
-				throw new NoUserException("user $userId not found");
218
-			}
219
-			$this->userSession->setUser($user);
220
-			return $this->userService;
221
-		} else {
222
-			return $this->globalService;
223
-		}
224
-	}
47
+    /**
48
+     * @var GlobalStoragesService
49
+     */
50
+    private $globalService;
51
+
52
+    /**
53
+     * @var UserStoragesService
54
+     */
55
+    private $userService;
56
+
57
+    /**
58
+     * @var IUserManager
59
+     */
60
+    private $userManager;
61
+
62
+    /** @var BackendService */
63
+    private $backendService;
64
+
65
+    /** @var IUserSession */
66
+    private $userSession;
67
+
68
+    public function __construct(GlobalStoragesService $globalService,
69
+                            UserStoragesService $userService,
70
+                            IUserManager $userManager,
71
+                            IUserSession $userSession,
72
+                            BackendService $backendService
73
+    ) {
74
+        parent::__construct();
75
+        $this->globalService = $globalService;
76
+        $this->userService = $userService;
77
+        $this->userManager = $userManager;
78
+        $this->userSession = $userSession;
79
+        $this->backendService = $backendService;
80
+    }
81
+
82
+    protected function configure() {
83
+        $this
84
+            ->setName('files_external:create')
85
+            ->setDescription('Create a new mount configuration')
86
+            ->addOption(
87
+                'user',
88
+                '',
89
+                InputOption::VALUE_OPTIONAL,
90
+                'user to add the mount configuration for, if not set the mount will be added as system mount'
91
+            )
92
+            ->addArgument(
93
+                'mount_point',
94
+                InputArgument::REQUIRED,
95
+                'mount point for the new mount'
96
+            )
97
+            ->addArgument(
98
+                'storage_backend',
99
+                InputArgument::REQUIRED,
100
+                'storage backend identifier for the new mount, see `occ files_external:backends` for possible values'
101
+            )
102
+            ->addArgument(
103
+                'authentication_backend',
104
+                InputArgument::REQUIRED,
105
+                'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values'
106
+            )
107
+            ->addOption(
108
+                'config',
109
+                'c',
110
+                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
111
+                'Mount configuration option in key=value format'
112
+            )
113
+            ->addOption(
114
+                'dry',
115
+                '',
116
+                InputOption::VALUE_NONE,
117
+                'Don\'t save the created mount, only list the new mount'
118
+            );
119
+        parent::configure();
120
+    }
121
+
122
+    protected function execute(InputInterface $input, OutputInterface $output): int {
123
+        $user = $input->getOption('user');
124
+        $mountPoint = $input->getArgument('mount_point');
125
+        $storageIdentifier = $input->getArgument('storage_backend');
126
+        $authIdentifier = $input->getArgument('authentication_backend');
127
+        $configInput = $input->getOption('config');
128
+
129
+        $storageBackend = $this->backendService->getBackend($storageIdentifier);
130
+        $authBackend = $this->backendService->getAuthMechanism($authIdentifier);
131
+
132
+        if (!Filesystem::isValidPath($mountPoint)) {
133
+            $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
134
+            return 1;
135
+        }
136
+        if (is_null($storageBackend)) {
137
+            $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
138
+            return 404;
139
+        }
140
+        if (is_null($authBackend)) {
141
+            $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
142
+            return 404;
143
+        }
144
+        $supportedSchemes = array_keys($storageBackend->getAuthSchemes());
145
+        if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
146
+            $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
147
+            return 1;
148
+        }
149
+
150
+        $config = [];
151
+        foreach ($configInput as $configOption) {
152
+            if (!strpos($configOption, '=')) {
153
+                $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
154
+                return 1;
155
+            }
156
+            list($key, $value) = explode('=', $configOption, 2);
157
+            if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
158
+                $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
159
+                return 1;
160
+            }
161
+            $config[$key] = $value;
162
+        }
163
+
164
+        $mount = new StorageConfig();
165
+        $mount->setMountPoint($mountPoint);
166
+        $mount->setBackend($storageBackend);
167
+        $mount->setAuthMechanism($authBackend);
168
+        $mount->setBackendOptions($config);
169
+
170
+        if ($user) {
171
+            if (!$this->userManager->userExists($user)) {
172
+                $output->writeln('<error>User "' . $user . '" not found</error>');
173
+                return 1;
174
+            }
175
+            $mount->setApplicableUsers([$user]);
176
+        }
177
+
178
+        if ($input->getOption('dry')) {
179
+            $this->showMount($user, $mount, $input, $output);
180
+        } else {
181
+            $this->getStorageService($user)->addStorage($mount);
182
+            if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
183
+                $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
184
+            } else {
185
+                $output->writeln((string)$mount->getId());
186
+            }
187
+        }
188
+        return 0;
189
+    }
190
+
191
+    private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
192
+        $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
193
+        foreach ($params as $param) {
194
+            /** @var DefinitionParameter $param */
195
+            if ($param->getName() === $key) {
196
+                if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) {
197
+                    $value = ($value === 'true');
198
+                }
199
+                return true;
200
+            }
201
+        }
202
+        return false;
203
+    }
204
+
205
+    private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
206
+        $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
207
+        $listInput = new ArrayInput([], $listCommand->getDefinition());
208
+        $listInput->setOption('output', $input->getOption('output'));
209
+        $listInput->setOption('show-password', true);
210
+        $listCommand->listMounts($user, [$mount], $listInput, $output);
211
+    }
212
+
213
+    protected function getStorageService($userId) {
214
+        if (!empty($userId)) {
215
+            $user = $this->userManager->get($userId);
216
+            if (is_null($user)) {
217
+                throw new NoUserException("user $userId not found");
218
+            }
219
+            $this->userSession->setUser($user);
220
+            return $this->userService;
221
+        } else {
222
+            return $this->globalService;
223
+        }
224
+    }
225 225
 }
Please login to merge, or discard this patch.
lib/public/Util.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -304,9 +304,9 @@
 block discarded – undo
304 304
 	 */
305 305
 	public static function linkToRemote($service) {
306 306
 		$urlGenerator = \OC::$server->getURLGenerator();
307
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
307
+		$remoteBase = $urlGenerator->linkTo('', 'remote.php').'/'.$service;
308 308
 		return $urlGenerator->getAbsoluteURL(
309
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
309
+			$remoteBase.(($service[strlen($service) - 1] != '/') ? '/' : '')
310 310
 		);
311 311
 	}
312 312
 
Please login to merge, or discard this patch.
Indentation   +472 added lines, -472 removed lines patch added patch discarded remove patch
@@ -58,476 +58,476 @@
 block discarded – undo
58 58
  * @since 4.0.0
59 59
  */
60 60
 class Util {
61
-	/**
62
-	 * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
63
-	 */
64
-	public const DEBUG = 0;
65
-	/**
66
-	 * @deprecated 14.0.0 use \OCP\ILogger::INFO
67
-	 */
68
-	public const INFO = 1;
69
-	/**
70
-	 * @deprecated 14.0.0 use \OCP\ILogger::WARN
71
-	 */
72
-	public const WARN = 2;
73
-	/**
74
-	 * @deprecated 14.0.0 use \OCP\ILogger::ERROR
75
-	 */
76
-	public const ERROR = 3;
77
-	/**
78
-	 * @deprecated 14.0.0 use \OCP\ILogger::FATAL
79
-	 */
80
-	public const FATAL = 4;
81
-
82
-	/** \OCP\Share\IManager */
83
-	private static $shareManager;
84
-
85
-	/**
86
-	 * get the current installed version of Nextcloud
87
-	 * @return array
88
-	 * @since 4.0.0
89
-	 */
90
-	public static function getVersion() {
91
-		return \OC_Util::getVersion();
92
-	}
93
-
94
-	/**
95
-	 * @since 17.0.0
96
-	 */
97
-	public static function hasExtendedSupport(): bool {
98
-		try {
99
-			/** @var \OCP\Support\Subscription\IRegistry */
100
-			$subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class);
101
-			return $subscriptionRegistry->delegateHasExtendedSupport();
102
-		} catch (AppFramework\QueryException $e) {
103
-		}
104
-		return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false);
105
-	}
106
-
107
-	/**
108
-	 * Set current update channel
109
-	 * @param string $channel
110
-	 * @since 8.1.0
111
-	 */
112
-	public static function setChannel($channel) {
113
-		\OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
114
-	}
115
-
116
-	/**
117
-	 * Get current update channel
118
-	 * @return string
119
-	 * @since 8.1.0
120
-	 */
121
-	public static function getChannel() {
122
-		return \OC_Util::getChannel();
123
-	}
124
-
125
-	/**
126
-	 * write a message in the log
127
-	 * @param string $app
128
-	 * @param string $message
129
-	 * @param int $level
130
-	 * @since 4.0.0
131
-	 * @deprecated 13.0.0 use log of \OCP\ILogger
132
-	 */
133
-	public static function writeLog($app, $message, $level) {
134
-		$context = ['app' => $app];
135
-		\OC::$server->getLogger()->log($level, $message, $context);
136
-	}
137
-
138
-	/**
139
-	 * check if sharing is disabled for the current user
140
-	 *
141
-	 * @return boolean
142
-	 * @since 7.0.0
143
-	 * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
144
-	 */
145
-	public static function isSharingDisabledForUser() {
146
-		if (self::$shareManager === null) {
147
-			self::$shareManager = \OC::$server->getShareManager();
148
-		}
149
-
150
-		$user = \OC::$server->getUserSession()->getUser();
151
-		if ($user !== null) {
152
-			$user = $user->getUID();
153
-		}
154
-
155
-		return self::$shareManager->sharingDisabledForUser($user);
156
-	}
157
-
158
-	/**
159
-	 * get l10n object
160
-	 * @param string $application
161
-	 * @param string|null $language
162
-	 * @return \OCP\IL10N
163
-	 * @since 6.0.0 - parameter $language was added in 8.0.0
164
-	 */
165
-	public static function getL10N($application, $language = null) {
166
-		return \OC::$server->getL10N($application, $language);
167
-	}
168
-
169
-	/**
170
-	 * add a css file
171
-	 * @param string $application
172
-	 * @param string $file
173
-	 * @since 4.0.0
174
-	 */
175
-	public static function addStyle($application, $file = null) {
176
-		\OC_Util::addStyle($application, $file);
177
-	}
178
-
179
-	/**
180
-	 * add a javascript file
181
-	 * @param string $application
182
-	 * @param string $file
183
-	 * @since 4.0.0
184
-	 */
185
-	public static function addScript($application, $file = null) {
186
-		\OC_Util::addScript($application, $file);
187
-	}
188
-
189
-	/**
190
-	 * Add a translation JS file
191
-	 * @param string $application application id
192
-	 * @param string $languageCode language code, defaults to the current locale
193
-	 * @since 8.0.0
194
-	 */
195
-	public static function addTranslations($application, $languageCode = null) {
196
-		\OC_Util::addTranslations($application, $languageCode);
197
-	}
198
-
199
-	/**
200
-	 * Add a custom element to the header
201
-	 * If $text is null then the element will be written as empty element.
202
-	 * So use "" to get a closing tag.
203
-	 * @param string $tag tag name of the element
204
-	 * @param array $attributes array of attributes for the element
205
-	 * @param string $text the text content for the element
206
-	 * @since 4.0.0
207
-	 */
208
-	public static function addHeader($tag, $attributes, $text = null) {
209
-		\OC_Util::addHeader($tag, $attributes, $text);
210
-	}
211
-
212
-	/**
213
-	 * Creates an absolute url to the given app and file.
214
-	 * @param string $app app
215
-	 * @param string $file file
216
-	 * @param array $args array with param=>value, will be appended to the returned url
217
-	 * 	The value of $args will be urlencoded
218
-	 * @return string the url
219
-	 * @since 4.0.0 - parameter $args was added in 4.5.0
220
-	 */
221
-	public static function linkToAbsolute($app, $file, $args = []) {
222
-		$urlGenerator = \OC::$server->getURLGenerator();
223
-		return $urlGenerator->getAbsoluteURL(
224
-			$urlGenerator->linkTo($app, $file, $args)
225
-		);
226
-	}
227
-
228
-	/**
229
-	 * Creates an absolute url for remote use.
230
-	 * @param string $service id
231
-	 * @return string the url
232
-	 * @since 4.0.0
233
-	 */
234
-	public static function linkToRemote($service) {
235
-		$urlGenerator = \OC::$server->getURLGenerator();
236
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
237
-		return $urlGenerator->getAbsoluteURL(
238
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
239
-		);
240
-	}
241
-
242
-	/**
243
-	 * Creates an absolute url for public use
244
-	 * @param string $service id
245
-	 * @return string the url
246
-	 * @since 4.5.0
247
-	 * @deprecated 15.0.0 - use OCP\IURLGenerator
248
-	 */
249
-	public static function linkToPublic($service) {
250
-		$urlGenerator = \OC::$server->getURLGenerator();
251
-		if ($service === 'files') {
252
-			return $urlGenerator->getAbsoluteURL('/s');
253
-		}
254
-		return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service);
255
-	}
256
-
257
-	/**
258
-	 * Returns the server host name without an eventual port number
259
-	 * @return string the server hostname
260
-	 * @since 5.0.0
261
-	 */
262
-	public static function getServerHostName() {
263
-		$host_name = \OC::$server->getRequest()->getServerHost();
264
-		// strip away port number (if existing)
265
-		$colon_pos = strpos($host_name, ':');
266
-		if ($colon_pos != false) {
267
-			$host_name = substr($host_name, 0, $colon_pos);
268
-		}
269
-		return $host_name;
270
-	}
271
-
272
-	/**
273
-	 * Returns the default email address
274
-	 * @param string $user_part the user part of the address
275
-	 * @return string the default email address
276
-	 *
277
-	 * Assembles a default email address (using the server hostname
278
-	 * and the given user part, and returns it
279
-	 * Example: when given lostpassword-noreply as $user_part param,
280
-	 *     and is currently accessed via http(s)://example.com/,
281
-	 *     it would return '[email protected]'
282
-	 *
283
-	 * If the configuration value 'mail_from_address' is set in
284
-	 * config.php, this value will override the $user_part that
285
-	 * is passed to this function
286
-	 * @since 5.0.0
287
-	 */
288
-	public static function getDefaultEmailAddress($user_part) {
289
-		$config = \OC::$server->getConfig();
290
-		$user_part = $config->getSystemValue('mail_from_address', $user_part);
291
-		$host_name = self::getServerHostName();
292
-		$host_name = $config->getSystemValue('mail_domain', $host_name);
293
-		$defaultEmailAddress = $user_part.'@'.$host_name;
294
-
295
-		$mailer = \OC::$server->getMailer();
296
-		if ($mailer->validateMailAddress($defaultEmailAddress)) {
297
-			return $defaultEmailAddress;
298
-		}
299
-
300
-		// in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
301
-		return $user_part.'@localhost.localdomain';
302
-	}
303
-
304
-	/**
305
-	 * Make a human file size (2048 to 2 kB)
306
-	 * @param int $bytes file size in bytes
307
-	 * @return string a human readable file size
308
-	 * @since 4.0.0
309
-	 */
310
-	public static function humanFileSize($bytes) {
311
-		return \OC_Helper::humanFileSize($bytes);
312
-	}
313
-
314
-	/**
315
-	 * Make a computer file size (2 kB to 2048)
316
-	 * @param string $str file size in a fancy format
317
-	 * @return float a file size in bytes
318
-	 *
319
-	 * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
320
-	 * @since 4.0.0
321
-	 */
322
-	public static function computerFileSize($str) {
323
-		return \OC_Helper::computerFileSize($str);
324
-	}
325
-
326
-	/**
327
-	 * connects a function to a hook
328
-	 *
329
-	 * @param string $signalClass class name of emitter
330
-	 * @param string $signalName name of signal
331
-	 * @param string|object $slotClass class name of slot
332
-	 * @param string $slotName name of slot
333
-	 * @return bool
334
-	 *
335
-	 * This function makes it very easy to connect to use hooks.
336
-	 *
337
-	 * TODO: write example
338
-	 * @since 4.0.0
339
-	 * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener
340
-	 */
341
-	public static function connectHook($signalClass, $signalName, $slotClass, $slotName) {
342
-		return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
343
-	}
344
-
345
-	/**
346
-	 * Emits a signal. To get data from the slot use references!
347
-	 * @param string $signalclass class name of emitter
348
-	 * @param string $signalname name of signal
349
-	 * @param array $params default: array() array with additional data
350
-	 * @return bool true if slots exists or false if not
351
-	 *
352
-	 * TODO: write example
353
-	 * @since 4.0.0
354
-	 * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent
355
-	 */
356
-	public static function emitHook($signalclass, $signalname, $params = []) {
357
-		return \OC_Hook::emit($signalclass, $signalname, $params);
358
-	}
359
-
360
-	/**
361
-	 * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
362
-	 * multiple OC_Template elements which invoke `callRegister`. If the value
363
-	 * would not be cached these unit-tests would fail.
364
-	 * @var string
365
-	 */
366
-	private static $token = '';
367
-
368
-	/**
369
-	 * Register an get/post call. This is important to prevent CSRF attacks
370
-	 * @since 4.5.0
371
-	 */
372
-	public static function callRegister() {
373
-		if (self::$token === '') {
374
-			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
375
-		}
376
-		return self::$token;
377
-	}
378
-
379
-	/**
380
-	 * Used to sanitize HTML
381
-	 *
382
-	 * This function is used to sanitize HTML and should be applied on any
383
-	 * string or array of strings before displaying it on a web page.
384
-	 *
385
-	 * @param string|array $value
386
-	 * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
387
-	 * @since 4.5.0
388
-	 */
389
-	public static function sanitizeHTML($value) {
390
-		return \OC_Util::sanitizeHTML($value);
391
-	}
392
-
393
-	/**
394
-	 * Public function to encode url parameters
395
-	 *
396
-	 * This function is used to encode path to file before output.
397
-	 * Encoding is done according to RFC 3986 with one exception:
398
-	 * Character '/' is preserved as is.
399
-	 *
400
-	 * @param string $component part of URI to encode
401
-	 * @return string
402
-	 * @since 6.0.0
403
-	 */
404
-	public static function encodePath($component) {
405
-		return \OC_Util::encodePath($component);
406
-	}
407
-
408
-	/**
409
-	 * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
410
-	 *
411
-	 * @param array $input The array to work on
412
-	 * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
413
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
414
-	 * @return array
415
-	 * @since 4.5.0
416
-	 */
417
-	public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
418
-		return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
419
-	}
420
-
421
-	/**
422
-	 * performs a search in a nested array
423
-	 *
424
-	 * @param array $haystack the array to be searched
425
-	 * @param string $needle the search string
426
-	 * @param mixed $index optional, only search this key name
427
-	 * @return mixed the key of the matching field, otherwise false
428
-	 * @since 4.5.0
429
-	 * @deprecated 15.0.0
430
-	 */
431
-	public static function recursiveArraySearch($haystack, $needle, $index = null) {
432
-		return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
433
-	}
434
-
435
-	/**
436
-	 * calculates the maximum upload size respecting system settings, free space and user quota
437
-	 *
438
-	 * @param string $dir the current folder where the user currently operates
439
-	 * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
440
-	 * @return int number of bytes representing
441
-	 * @since 5.0.0
442
-	 */
443
-	public static function maxUploadFilesize($dir, $free = null) {
444
-		return \OC_Helper::maxUploadFilesize($dir, $free);
445
-	}
446
-
447
-	/**
448
-	 * Calculate free space left within user quota
449
-	 * @param string $dir the current folder where the user currently operates
450
-	 * @return int number of bytes representing
451
-	 * @since 7.0.0
452
-	 */
453
-	public static function freeSpace($dir) {
454
-		return \OC_Helper::freeSpace($dir);
455
-	}
456
-
457
-	/**
458
-	 * Calculate PHP upload limit
459
-	 *
460
-	 * @return int number of bytes representing
461
-	 * @since 7.0.0
462
-	 */
463
-	public static function uploadLimit() {
464
-		return \OC_Helper::uploadLimit();
465
-	}
466
-
467
-	/**
468
-	 * Returns whether the given file name is valid
469
-	 * @param string $file file name to check
470
-	 * @return bool true if the file name is valid, false otherwise
471
-	 * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
472
-	 * @since 7.0.0
473
-	 * @suppress PhanDeprecatedFunction
474
-	 */
475
-	public static function isValidFileName($file) {
476
-		return \OC_Util::isValidFileName($file);
477
-	}
478
-
479
-	/**
480
-	 * Compare two strings to provide a natural sort
481
-	 * @param string $a first string to compare
482
-	 * @param string $b second string to compare
483
-	 * @return int -1 if $b comes before $a, 1 if $a comes before $b
484
-	 * or 0 if the strings are identical
485
-	 * @since 7.0.0
486
-	 */
487
-	public static function naturalSortCompare($a, $b) {
488
-		return \OC\NaturalSort::getInstance()->compare($a, $b);
489
-	}
490
-
491
-	/**
492
-	 * check if a password is required for each public link
493
-	 * @return boolean
494
-	 * @since 7.0.0
495
-	 */
496
-	public static function isPublicLinkPasswordRequired() {
497
-		return \OC_Util::isPublicLinkPasswordRequired();
498
-	}
499
-
500
-	/**
501
-	 * check if share API enforces a default expire date
502
-	 * @return boolean
503
-	 * @since 8.0.0
504
-	 */
505
-	public static function isDefaultExpireDateEnforced() {
506
-		return \OC_Util::isDefaultExpireDateEnforced();
507
-	}
508
-
509
-	protected static $needUpgradeCache = null;
510
-
511
-	/**
512
-	 * Checks whether the current version needs upgrade.
513
-	 *
514
-	 * @return bool true if upgrade is needed, false otherwise
515
-	 * @since 7.0.0
516
-	 */
517
-	public static function needUpgrade() {
518
-		if (!isset(self::$needUpgradeCache)) {
519
-			self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
520
-		}
521
-		return self::$needUpgradeCache;
522
-	}
523
-
524
-	/**
525
-	 * is this Internet explorer ?
526
-	 *
527
-	 * @return boolean
528
-	 * @since 14.0.0
529
-	 */
530
-	public static function isIe() {
531
-		return \OC_Util::isIe();
532
-	}
61
+    /**
62
+     * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
63
+     */
64
+    public const DEBUG = 0;
65
+    /**
66
+     * @deprecated 14.0.0 use \OCP\ILogger::INFO
67
+     */
68
+    public const INFO = 1;
69
+    /**
70
+     * @deprecated 14.0.0 use \OCP\ILogger::WARN
71
+     */
72
+    public const WARN = 2;
73
+    /**
74
+     * @deprecated 14.0.0 use \OCP\ILogger::ERROR
75
+     */
76
+    public const ERROR = 3;
77
+    /**
78
+     * @deprecated 14.0.0 use \OCP\ILogger::FATAL
79
+     */
80
+    public const FATAL = 4;
81
+
82
+    /** \OCP\Share\IManager */
83
+    private static $shareManager;
84
+
85
+    /**
86
+     * get the current installed version of Nextcloud
87
+     * @return array
88
+     * @since 4.0.0
89
+     */
90
+    public static function getVersion() {
91
+        return \OC_Util::getVersion();
92
+    }
93
+
94
+    /**
95
+     * @since 17.0.0
96
+     */
97
+    public static function hasExtendedSupport(): bool {
98
+        try {
99
+            /** @var \OCP\Support\Subscription\IRegistry */
100
+            $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class);
101
+            return $subscriptionRegistry->delegateHasExtendedSupport();
102
+        } catch (AppFramework\QueryException $e) {
103
+        }
104
+        return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false);
105
+    }
106
+
107
+    /**
108
+     * Set current update channel
109
+     * @param string $channel
110
+     * @since 8.1.0
111
+     */
112
+    public static function setChannel($channel) {
113
+        \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
114
+    }
115
+
116
+    /**
117
+     * Get current update channel
118
+     * @return string
119
+     * @since 8.1.0
120
+     */
121
+    public static function getChannel() {
122
+        return \OC_Util::getChannel();
123
+    }
124
+
125
+    /**
126
+     * write a message in the log
127
+     * @param string $app
128
+     * @param string $message
129
+     * @param int $level
130
+     * @since 4.0.0
131
+     * @deprecated 13.0.0 use log of \OCP\ILogger
132
+     */
133
+    public static function writeLog($app, $message, $level) {
134
+        $context = ['app' => $app];
135
+        \OC::$server->getLogger()->log($level, $message, $context);
136
+    }
137
+
138
+    /**
139
+     * check if sharing is disabled for the current user
140
+     *
141
+     * @return boolean
142
+     * @since 7.0.0
143
+     * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
144
+     */
145
+    public static function isSharingDisabledForUser() {
146
+        if (self::$shareManager === null) {
147
+            self::$shareManager = \OC::$server->getShareManager();
148
+        }
149
+
150
+        $user = \OC::$server->getUserSession()->getUser();
151
+        if ($user !== null) {
152
+            $user = $user->getUID();
153
+        }
154
+
155
+        return self::$shareManager->sharingDisabledForUser($user);
156
+    }
157
+
158
+    /**
159
+     * get l10n object
160
+     * @param string $application
161
+     * @param string|null $language
162
+     * @return \OCP\IL10N
163
+     * @since 6.0.0 - parameter $language was added in 8.0.0
164
+     */
165
+    public static function getL10N($application, $language = null) {
166
+        return \OC::$server->getL10N($application, $language);
167
+    }
168
+
169
+    /**
170
+     * add a css file
171
+     * @param string $application
172
+     * @param string $file
173
+     * @since 4.0.0
174
+     */
175
+    public static function addStyle($application, $file = null) {
176
+        \OC_Util::addStyle($application, $file);
177
+    }
178
+
179
+    /**
180
+     * add a javascript file
181
+     * @param string $application
182
+     * @param string $file
183
+     * @since 4.0.0
184
+     */
185
+    public static function addScript($application, $file = null) {
186
+        \OC_Util::addScript($application, $file);
187
+    }
188
+
189
+    /**
190
+     * Add a translation JS file
191
+     * @param string $application application id
192
+     * @param string $languageCode language code, defaults to the current locale
193
+     * @since 8.0.0
194
+     */
195
+    public static function addTranslations($application, $languageCode = null) {
196
+        \OC_Util::addTranslations($application, $languageCode);
197
+    }
198
+
199
+    /**
200
+     * Add a custom element to the header
201
+     * If $text is null then the element will be written as empty element.
202
+     * So use "" to get a closing tag.
203
+     * @param string $tag tag name of the element
204
+     * @param array $attributes array of attributes for the element
205
+     * @param string $text the text content for the element
206
+     * @since 4.0.0
207
+     */
208
+    public static function addHeader($tag, $attributes, $text = null) {
209
+        \OC_Util::addHeader($tag, $attributes, $text);
210
+    }
211
+
212
+    /**
213
+     * Creates an absolute url to the given app and file.
214
+     * @param string $app app
215
+     * @param string $file file
216
+     * @param array $args array with param=>value, will be appended to the returned url
217
+     * 	The value of $args will be urlencoded
218
+     * @return string the url
219
+     * @since 4.0.0 - parameter $args was added in 4.5.0
220
+     */
221
+    public static function linkToAbsolute($app, $file, $args = []) {
222
+        $urlGenerator = \OC::$server->getURLGenerator();
223
+        return $urlGenerator->getAbsoluteURL(
224
+            $urlGenerator->linkTo($app, $file, $args)
225
+        );
226
+    }
227
+
228
+    /**
229
+     * Creates an absolute url for remote use.
230
+     * @param string $service id
231
+     * @return string the url
232
+     * @since 4.0.0
233
+     */
234
+    public static function linkToRemote($service) {
235
+        $urlGenerator = \OC::$server->getURLGenerator();
236
+        $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
237
+        return $urlGenerator->getAbsoluteURL(
238
+            $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
239
+        );
240
+    }
241
+
242
+    /**
243
+     * Creates an absolute url for public use
244
+     * @param string $service id
245
+     * @return string the url
246
+     * @since 4.5.0
247
+     * @deprecated 15.0.0 - use OCP\IURLGenerator
248
+     */
249
+    public static function linkToPublic($service) {
250
+        $urlGenerator = \OC::$server->getURLGenerator();
251
+        if ($service === 'files') {
252
+            return $urlGenerator->getAbsoluteURL('/s');
253
+        }
254
+        return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service);
255
+    }
256
+
257
+    /**
258
+     * Returns the server host name without an eventual port number
259
+     * @return string the server hostname
260
+     * @since 5.0.0
261
+     */
262
+    public static function getServerHostName() {
263
+        $host_name = \OC::$server->getRequest()->getServerHost();
264
+        // strip away port number (if existing)
265
+        $colon_pos = strpos($host_name, ':');
266
+        if ($colon_pos != false) {
267
+            $host_name = substr($host_name, 0, $colon_pos);
268
+        }
269
+        return $host_name;
270
+    }
271
+
272
+    /**
273
+     * Returns the default email address
274
+     * @param string $user_part the user part of the address
275
+     * @return string the default email address
276
+     *
277
+     * Assembles a default email address (using the server hostname
278
+     * and the given user part, and returns it
279
+     * Example: when given lostpassword-noreply as $user_part param,
280
+     *     and is currently accessed via http(s)://example.com/,
281
+     *     it would return '[email protected]'
282
+     *
283
+     * If the configuration value 'mail_from_address' is set in
284
+     * config.php, this value will override the $user_part that
285
+     * is passed to this function
286
+     * @since 5.0.0
287
+     */
288
+    public static function getDefaultEmailAddress($user_part) {
289
+        $config = \OC::$server->getConfig();
290
+        $user_part = $config->getSystemValue('mail_from_address', $user_part);
291
+        $host_name = self::getServerHostName();
292
+        $host_name = $config->getSystemValue('mail_domain', $host_name);
293
+        $defaultEmailAddress = $user_part.'@'.$host_name;
294
+
295
+        $mailer = \OC::$server->getMailer();
296
+        if ($mailer->validateMailAddress($defaultEmailAddress)) {
297
+            return $defaultEmailAddress;
298
+        }
299
+
300
+        // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
301
+        return $user_part.'@localhost.localdomain';
302
+    }
303
+
304
+    /**
305
+     * Make a human file size (2048 to 2 kB)
306
+     * @param int $bytes file size in bytes
307
+     * @return string a human readable file size
308
+     * @since 4.0.0
309
+     */
310
+    public static function humanFileSize($bytes) {
311
+        return \OC_Helper::humanFileSize($bytes);
312
+    }
313
+
314
+    /**
315
+     * Make a computer file size (2 kB to 2048)
316
+     * @param string $str file size in a fancy format
317
+     * @return float a file size in bytes
318
+     *
319
+     * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
320
+     * @since 4.0.0
321
+     */
322
+    public static function computerFileSize($str) {
323
+        return \OC_Helper::computerFileSize($str);
324
+    }
325
+
326
+    /**
327
+     * connects a function to a hook
328
+     *
329
+     * @param string $signalClass class name of emitter
330
+     * @param string $signalName name of signal
331
+     * @param string|object $slotClass class name of slot
332
+     * @param string $slotName name of slot
333
+     * @return bool
334
+     *
335
+     * This function makes it very easy to connect to use hooks.
336
+     *
337
+     * TODO: write example
338
+     * @since 4.0.0
339
+     * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener
340
+     */
341
+    public static function connectHook($signalClass, $signalName, $slotClass, $slotName) {
342
+        return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
343
+    }
344
+
345
+    /**
346
+     * Emits a signal. To get data from the slot use references!
347
+     * @param string $signalclass class name of emitter
348
+     * @param string $signalname name of signal
349
+     * @param array $params default: array() array with additional data
350
+     * @return bool true if slots exists or false if not
351
+     *
352
+     * TODO: write example
353
+     * @since 4.0.0
354
+     * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent
355
+     */
356
+    public static function emitHook($signalclass, $signalname, $params = []) {
357
+        return \OC_Hook::emit($signalclass, $signalname, $params);
358
+    }
359
+
360
+    /**
361
+     * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
362
+     * multiple OC_Template elements which invoke `callRegister`. If the value
363
+     * would not be cached these unit-tests would fail.
364
+     * @var string
365
+     */
366
+    private static $token = '';
367
+
368
+    /**
369
+     * Register an get/post call. This is important to prevent CSRF attacks
370
+     * @since 4.5.0
371
+     */
372
+    public static function callRegister() {
373
+        if (self::$token === '') {
374
+            self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
375
+        }
376
+        return self::$token;
377
+    }
378
+
379
+    /**
380
+     * Used to sanitize HTML
381
+     *
382
+     * This function is used to sanitize HTML and should be applied on any
383
+     * string or array of strings before displaying it on a web page.
384
+     *
385
+     * @param string|array $value
386
+     * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
387
+     * @since 4.5.0
388
+     */
389
+    public static function sanitizeHTML($value) {
390
+        return \OC_Util::sanitizeHTML($value);
391
+    }
392
+
393
+    /**
394
+     * Public function to encode url parameters
395
+     *
396
+     * This function is used to encode path to file before output.
397
+     * Encoding is done according to RFC 3986 with one exception:
398
+     * Character '/' is preserved as is.
399
+     *
400
+     * @param string $component part of URI to encode
401
+     * @return string
402
+     * @since 6.0.0
403
+     */
404
+    public static function encodePath($component) {
405
+        return \OC_Util::encodePath($component);
406
+    }
407
+
408
+    /**
409
+     * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
410
+     *
411
+     * @param array $input The array to work on
412
+     * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
413
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
414
+     * @return array
415
+     * @since 4.5.0
416
+     */
417
+    public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
418
+        return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
419
+    }
420
+
421
+    /**
422
+     * performs a search in a nested array
423
+     *
424
+     * @param array $haystack the array to be searched
425
+     * @param string $needle the search string
426
+     * @param mixed $index optional, only search this key name
427
+     * @return mixed the key of the matching field, otherwise false
428
+     * @since 4.5.0
429
+     * @deprecated 15.0.0
430
+     */
431
+    public static function recursiveArraySearch($haystack, $needle, $index = null) {
432
+        return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
433
+    }
434
+
435
+    /**
436
+     * calculates the maximum upload size respecting system settings, free space and user quota
437
+     *
438
+     * @param string $dir the current folder where the user currently operates
439
+     * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
440
+     * @return int number of bytes representing
441
+     * @since 5.0.0
442
+     */
443
+    public static function maxUploadFilesize($dir, $free = null) {
444
+        return \OC_Helper::maxUploadFilesize($dir, $free);
445
+    }
446
+
447
+    /**
448
+     * Calculate free space left within user quota
449
+     * @param string $dir the current folder where the user currently operates
450
+     * @return int number of bytes representing
451
+     * @since 7.0.0
452
+     */
453
+    public static function freeSpace($dir) {
454
+        return \OC_Helper::freeSpace($dir);
455
+    }
456
+
457
+    /**
458
+     * Calculate PHP upload limit
459
+     *
460
+     * @return int number of bytes representing
461
+     * @since 7.0.0
462
+     */
463
+    public static function uploadLimit() {
464
+        return \OC_Helper::uploadLimit();
465
+    }
466
+
467
+    /**
468
+     * Returns whether the given file name is valid
469
+     * @param string $file file name to check
470
+     * @return bool true if the file name is valid, false otherwise
471
+     * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
472
+     * @since 7.0.0
473
+     * @suppress PhanDeprecatedFunction
474
+     */
475
+    public static function isValidFileName($file) {
476
+        return \OC_Util::isValidFileName($file);
477
+    }
478
+
479
+    /**
480
+     * Compare two strings to provide a natural sort
481
+     * @param string $a first string to compare
482
+     * @param string $b second string to compare
483
+     * @return int -1 if $b comes before $a, 1 if $a comes before $b
484
+     * or 0 if the strings are identical
485
+     * @since 7.0.0
486
+     */
487
+    public static function naturalSortCompare($a, $b) {
488
+        return \OC\NaturalSort::getInstance()->compare($a, $b);
489
+    }
490
+
491
+    /**
492
+     * check if a password is required for each public link
493
+     * @return boolean
494
+     * @since 7.0.0
495
+     */
496
+    public static function isPublicLinkPasswordRequired() {
497
+        return \OC_Util::isPublicLinkPasswordRequired();
498
+    }
499
+
500
+    /**
501
+     * check if share API enforces a default expire date
502
+     * @return boolean
503
+     * @since 8.0.0
504
+     */
505
+    public static function isDefaultExpireDateEnforced() {
506
+        return \OC_Util::isDefaultExpireDateEnforced();
507
+    }
508
+
509
+    protected static $needUpgradeCache = null;
510
+
511
+    /**
512
+     * Checks whether the current version needs upgrade.
513
+     *
514
+     * @return bool true if upgrade is needed, false otherwise
515
+     * @since 7.0.0
516
+     */
517
+    public static function needUpgrade() {
518
+        if (!isset(self::$needUpgradeCache)) {
519
+            self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
520
+        }
521
+        return self::$needUpgradeCache;
522
+    }
523
+
524
+    /**
525
+     * is this Internet explorer ?
526
+     *
527
+     * @return boolean
528
+     * @since 14.0.0
529
+     */
530
+    public static function isIe() {
531
+        return \OC_Util::isIe();
532
+    }
533 533
 }
Please login to merge, or discard this patch.
lib/public/Route/IRouter.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -36,91 +36,91 @@
 block discarded – undo
36 36
  */
37 37
 interface IRouter {
38 38
 
39
-	/**
40
-	 * Get the files to load the routes from
41
-	 *
42
-	 * @return string[]
43
-	 * @since 7.0.0
44
-	 * @deprecated 9.0.0
45
-	 */
46
-	public function getRoutingFiles();
39
+    /**
40
+     * Get the files to load the routes from
41
+     *
42
+     * @return string[]
43
+     * @since 7.0.0
44
+     * @deprecated 9.0.0
45
+     */
46
+    public function getRoutingFiles();
47 47
 
48
-	/**
49
-	 * @return string
50
-	 * @since 7.0.0
51
-	 * @deprecated 9.0.0
52
-	 */
53
-	public function getCacheKey();
48
+    /**
49
+     * @return string
50
+     * @since 7.0.0
51
+     * @deprecated 9.0.0
52
+     */
53
+    public function getCacheKey();
54 54
 
55
-	/**
56
-	 * Loads the routes
57
-	 *
58
-	 * @param null|string $app
59
-	 * @since 7.0.0
60
-	 * @deprecated 9.0.0
61
-	 */
62
-	public function loadRoutes($app = null);
55
+    /**
56
+     * Loads the routes
57
+     *
58
+     * @param null|string $app
59
+     * @since 7.0.0
60
+     * @deprecated 9.0.0
61
+     */
62
+    public function loadRoutes($app = null);
63 63
 
64
-	/**
65
-	 * Sets the collection to use for adding routes
66
-	 *
67
-	 * @param string $name Name of the collection to use.
68
-	 * @return void
69
-	 * @since 7.0.0
70
-	 * @deprecated 9.0.0
71
-	 */
72
-	public function useCollection($name);
64
+    /**
65
+     * Sets the collection to use for adding routes
66
+     *
67
+     * @param string $name Name of the collection to use.
68
+     * @return void
69
+     * @since 7.0.0
70
+     * @deprecated 9.0.0
71
+     */
72
+    public function useCollection($name);
73 73
 
74
-	/**
75
-	 * returns the current collection name in use for adding routes
76
-	 *
77
-	 * @return string the collection name
78
-	 * @since 8.0.0
79
-	 * @deprecated 9.0.0
80
-	 */
81
-	public function getCurrentCollection();
74
+    /**
75
+     * returns the current collection name in use for adding routes
76
+     *
77
+     * @return string the collection name
78
+     * @since 8.0.0
79
+     * @deprecated 9.0.0
80
+     */
81
+    public function getCurrentCollection();
82 82
 
83
-	/**
84
-	 * Create a \OCP\Route\IRoute.
85
-	 *
86
-	 * @param string $name Name of the route to create.
87
-	 * @param string $pattern The pattern to match
88
-	 * @param array $defaults An array of default parameter values
89
-	 * @param array $requirements An array of requirements for parameters (regexes)
90
-	 * @return \OCP\Route\IRoute
91
-	 * @since 7.0.0
92
-	 * @deprecated 9.0.0
93
-	 */
94
-	public function create($name, $pattern, array $defaults = [], array $requirements = []);
83
+    /**
84
+     * Create a \OCP\Route\IRoute.
85
+     *
86
+     * @param string $name Name of the route to create.
87
+     * @param string $pattern The pattern to match
88
+     * @param array $defaults An array of default parameter values
89
+     * @param array $requirements An array of requirements for parameters (regexes)
90
+     * @return \OCP\Route\IRoute
91
+     * @since 7.0.0
92
+     * @deprecated 9.0.0
93
+     */
94
+    public function create($name, $pattern, array $defaults = [], array $requirements = []);
95 95
 
96
-	/**
97
-	 * Find the route matching $url.
98
-	 *
99
-	 * @param string $url The url to find
100
-	 * @throws \Exception
101
-	 * @return void
102
-	 * @since 7.0.0
103
-	 * @deprecated 9.0.0
104
-	 */
105
-	public function match($url);
96
+    /**
97
+     * Find the route matching $url.
98
+     *
99
+     * @param string $url The url to find
100
+     * @throws \Exception
101
+     * @return void
102
+     * @since 7.0.0
103
+     * @deprecated 9.0.0
104
+     */
105
+    public function match($url);
106 106
 
107
-	/**
108
-	 * Get the url generator
109
-	 *
110
-	 * @since 7.0.0
111
-	 * @deprecated 9.0.0
112
-	 */
113
-	public function getGenerator();
107
+    /**
108
+     * Get the url generator
109
+     *
110
+     * @since 7.0.0
111
+     * @deprecated 9.0.0
112
+     */
113
+    public function getGenerator();
114 114
 
115
-	/**
116
-	 * Generate url based on $name and $parameters
117
-	 *
118
-	 * @param string $name Name of the route to use.
119
-	 * @param array $parameters Parameters for the route
120
-	 * @param bool $absolute
121
-	 * @return string
122
-	 * @since 7.0.0
123
-	 * @deprecated 9.0.0
124
-	 */
125
-	public function generate($name, $parameters = [], $absolute = false);
115
+    /**
116
+     * Generate url based on $name and $parameters
117
+     *
118
+     * @param string $name Name of the route to use.
119
+     * @param array $parameters Parameters for the route
120
+     * @param bool $absolute
121
+     * @return string
122
+     * @since 7.0.0
123
+     * @deprecated 9.0.0
124
+     */
125
+    public function generate($name, $parameters = [], $absolute = false);
126 126
 }
Please login to merge, or discard this patch.