Passed
Push — master ( 054d26...1aa76e )
by Julius
13:07 queued 12s
created
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.
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   +572 added lines, -572 removed lines patch added patch discarded remove patch
@@ -56,576 +56,576 @@
 block discarded – undo
56 56
  * @since 4.0.0
57 57
  */
58 58
 class Util {
59
-	/**
60
-	 * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
61
-	 */
62
-	public const DEBUG = 0;
63
-	/**
64
-	 * @deprecated 14.0.0 use \OCP\ILogger::INFO
65
-	 */
66
-	public const INFO = 1;
67
-	/**
68
-	 * @deprecated 14.0.0 use \OCP\ILogger::WARN
69
-	 */
70
-	public const WARN = 2;
71
-	/**
72
-	 * @deprecated 14.0.0 use \OCP\ILogger::ERROR
73
-	 */
74
-	public const ERROR = 3;
75
-	/**
76
-	 * @deprecated 14.0.0 use \OCP\ILogger::FATAL
77
-	 */
78
-	public const FATAL = 4;
79
-
80
-	/** @var \OCP\Share\IManager */
81
-	private static $shareManager;
82
-
83
-	/** @var array */
84
-	private static $scripts = [];
85
-
86
-	/** @var array */
87
-	private static $scriptDeps = [];
88
-
89
-	/** @var array */
90
-	private static $sortedScriptDeps = [];
91
-
92
-	/**
93
-	 * get the current installed version of Nextcloud
94
-	 * @return array
95
-	 * @since 4.0.0
96
-	 */
97
-	public static function getVersion() {
98
-		return \OC_Util::getVersion();
99
-	}
100
-
101
-	/**
102
-	 * @since 17.0.0
103
-	 */
104
-	public static function hasExtendedSupport(): bool {
105
-		try {
106
-			/** @var \OCP\Support\Subscription\IRegistry */
107
-			$subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class);
108
-			return $subscriptionRegistry->delegateHasExtendedSupport();
109
-		} catch (AppFramework\QueryException $e) {
110
-		}
111
-		return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false);
112
-	}
113
-
114
-	/**
115
-	 * Set current update channel
116
-	 * @param string $channel
117
-	 * @since 8.1.0
118
-	 */
119
-	public static function setChannel($channel) {
120
-		\OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
121
-	}
122
-
123
-	/**
124
-	 * Get current update channel
125
-	 * @return string
126
-	 * @since 8.1.0
127
-	 */
128
-	public static function getChannel() {
129
-		return \OC_Util::getChannel();
130
-	}
131
-
132
-	/**
133
-	 * write a message in the log
134
-	 * @param string $app
135
-	 * @param string $message
136
-	 * @param int $level
137
-	 * @since 4.0.0
138
-	 * @deprecated 13.0.0 use log of \OCP\ILogger
139
-	 */
140
-	public static function writeLog($app, $message, $level) {
141
-		$context = ['app' => $app];
142
-		\OC::$server->getLogger()->log($level, $message, $context);
143
-	}
144
-
145
-	/**
146
-	 * check if sharing is disabled for the current user
147
-	 *
148
-	 * @return boolean
149
-	 * @since 7.0.0
150
-	 * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
151
-	 */
152
-	public static function isSharingDisabledForUser() {
153
-		if (self::$shareManager === null) {
154
-			self::$shareManager = \OC::$server->getShareManager();
155
-		}
156
-
157
-		$user = \OC::$server->getUserSession()->getUser();
158
-		if ($user !== null) {
159
-			$user = $user->getUID();
160
-		}
161
-
162
-		return self::$shareManager->sharingDisabledForUser($user);
163
-	}
164
-
165
-	/**
166
-	 * get l10n object
167
-	 * @param string $application
168
-	 * @param string|null $language
169
-	 * @return \OCP\IL10N
170
-	 * @since 6.0.0 - parameter $language was added in 8.0.0
171
-	 */
172
-	public static function getL10N($application, $language = null) {
173
-		return \OC::$server->getL10N($application, $language);
174
-	}
175
-
176
-	/**
177
-	 * add a css file
178
-	 * @param string $application
179
-	 * @param string $file
180
-	 * @since 4.0.0
181
-	 */
182
-	public static function addStyle($application, $file = null) {
183
-		\OC_Util::addStyle($application, $file);
184
-	}
185
-
186
-	/**
187
-	 * add a javascript file
188
-	 *
189
-	 * @param string $application
190
-	 * @param string|null $file
191
-	 * @param string $afterAppId
192
-	 * @since 4.0.0
193
-	 */
194
-	public static function addScript(string $application, string $file = null, string $afterAppId = 'core'): void {
195
-		if (!empty($application)) {
196
-			$path = "$application/js/$file";
197
-		} else {
198
-			$path = "js/$file";
199
-		}
200
-
201
-		// Inject js translations if we load a script for
202
-		// a specific app that is not core, as those js files
203
-		// need separate handling
204
-		if ($application !== 'core'
205
-			&& $file !== null
206
-			&& strpos($file, 'l10n') === false) {
207
-			self::addTranslations($application);
208
-		}
209
-
210
-		// store app in dependency list
211
-		if (!array_key_exists($application, self::$scriptDeps)) {
212
-			self::$scriptDeps[$application] = new AppScriptDependency($application, [$afterAppId]);
213
-		} else {
214
-			self::$scriptDeps[$application]->addDep($afterAppId);
215
-		}
216
-
217
-		self::$scripts[$application][] = $path;
218
-	}
219
-
220
-	/**
221
-	 * Return the list of scripts injected to the page
222
-	 *
223
-	 * @return array
224
-	 * @since 24.0.0
225
-	 */
226
-	public static function getScripts(): array {
227
-		// Sort scriptDeps into sortedScriptDeps
228
-		$scriptSort = \OC::$server->get(AppScriptSort::class);
229
-		$sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps);
230
-
231
-		// Flatten array and remove duplicates
232
-		$sortedScripts = $sortedScripts ? array_merge(...array_values(($sortedScripts))) : [];
233
-
234
-		// Override core-common and core-main order
235
-		array_unshift($sortedScripts, 'core/js/common', 'core/js/main');
236
-
237
-		return array_unique($sortedScripts);
238
-	}
239
-
240
-	/**
241
-	 * Add a translation JS file
242
-	 * @param string $application application id
243
-	 * @param string $languageCode language code, defaults to the current locale
244
-	 * @since 8.0.0
245
-	 */
246
-	public static function addTranslations($application, $languageCode = null) {
247
-		if (is_null($languageCode)) {
248
-			$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
249
-		}
250
-		if (!empty($application)) {
251
-			$path = "$application/l10n/$languageCode";
252
-		} else {
253
-			$path = "l10n/$languageCode";
254
-		}
255
-		self::$scripts[$application][] = $path;
256
-	}
257
-
258
-	/**
259
-	 * Add a custom element to the header
260
-	 * If $text is null then the element will be written as empty element.
261
-	 * So use "" to get a closing tag.
262
-	 * @param string $tag tag name of the element
263
-	 * @param array $attributes array of attributes for the element
264
-	 * @param string $text the text content for the element
265
-	 * @since 4.0.0
266
-	 */
267
-	public static function addHeader($tag, $attributes, $text = null) {
268
-		\OC_Util::addHeader($tag, $attributes, $text);
269
-	}
270
-
271
-	/**
272
-	 * Creates an absolute url to the given app and file.
273
-	 * @param string $app app
274
-	 * @param string $file file
275
-	 * @param array $args array with param=>value, will be appended to the returned url
276
-	 * 	The value of $args will be urlencoded
277
-	 * @return string the url
278
-	 * @since 4.0.0 - parameter $args was added in 4.5.0
279
-	 */
280
-	public static function linkToAbsolute($app, $file, $args = []) {
281
-		$urlGenerator = \OC::$server->getURLGenerator();
282
-		return $urlGenerator->getAbsoluteURL(
283
-			$urlGenerator->linkTo($app, $file, $args)
284
-		);
285
-	}
286
-
287
-	/**
288
-	 * Creates an absolute url for remote use.
289
-	 * @param string $service id
290
-	 * @return string the url
291
-	 * @since 4.0.0
292
-	 */
293
-	public static function linkToRemote($service) {
294
-		$urlGenerator = \OC::$server->getURLGenerator();
295
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
296
-		return $urlGenerator->getAbsoluteURL(
297
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
298
-		);
299
-	}
300
-
301
-	/**
302
-	 * Creates an absolute url for public use
303
-	 * @param string $service id
304
-	 * @return string the url
305
-	 * @since 4.5.0
306
-	 * @deprecated 15.0.0 - use OCP\IURLGenerator
307
-	 */
308
-	public static function linkToPublic($service) {
309
-		$urlGenerator = \OC::$server->getURLGenerator();
310
-		if ($service === 'files') {
311
-			return $urlGenerator->getAbsoluteURL('/s');
312
-		}
313
-		return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service);
314
-	}
315
-
316
-	/**
317
-	 * Returns the server host name without an eventual port number
318
-	 * @return string the server hostname
319
-	 * @since 5.0.0
320
-	 */
321
-	public static function getServerHostName() {
322
-		$host_name = \OC::$server->getRequest()->getServerHost();
323
-		// strip away port number (if existing)
324
-		$colon_pos = strpos($host_name, ':');
325
-		if ($colon_pos != false) {
326
-			$host_name = substr($host_name, 0, $colon_pos);
327
-		}
328
-		return $host_name;
329
-	}
330
-
331
-	/**
332
-	 * Returns the default email address
333
-	 * @param string $user_part the user part of the address
334
-	 * @return string the default email address
335
-	 *
336
-	 * Assembles a default email address (using the server hostname
337
-	 * and the given user part, and returns it
338
-	 * Example: when given lostpassword-noreply as $user_part param,
339
-	 *     and is currently accessed via http(s)://example.com/,
340
-	 *     it would return '[email protected]'
341
-	 *
342
-	 * If the configuration value 'mail_from_address' is set in
343
-	 * config.php, this value will override the $user_part that
344
-	 * is passed to this function
345
-	 * @since 5.0.0
346
-	 */
347
-	public static function getDefaultEmailAddress($user_part) {
348
-		$config = \OC::$server->getConfig();
349
-		$user_part = $config->getSystemValue('mail_from_address', $user_part);
350
-		$host_name = self::getServerHostName();
351
-		$host_name = $config->getSystemValue('mail_domain', $host_name);
352
-		$defaultEmailAddress = $user_part.'@'.$host_name;
353
-
354
-		$mailer = \OC::$server->getMailer();
355
-		if ($mailer->validateMailAddress($defaultEmailAddress)) {
356
-			return $defaultEmailAddress;
357
-		}
358
-
359
-		// in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
360
-		return $user_part.'@localhost.localdomain';
361
-	}
362
-
363
-	/**
364
-	 * Make a human file size (2048 to 2 kB)
365
-	 * @param int $bytes file size in bytes
366
-	 * @return string a human readable file size
367
-	 * @since 4.0.0
368
-	 */
369
-	public static function humanFileSize($bytes) {
370
-		return \OC_Helper::humanFileSize($bytes);
371
-	}
372
-
373
-	/**
374
-	 * Make a computer file size (2 kB to 2048)
375
-	 * @param string $str file size in a fancy format
376
-	 * @return float|false a file size in bytes
377
-	 *
378
-	 * Inspired by: https://www.php.net/manual/en/function.filesize.php#92418
379
-	 * @since 4.0.0
380
-	 */
381
-	public static function computerFileSize($str) {
382
-		return \OC_Helper::computerFileSize($str);
383
-	}
384
-
385
-	/**
386
-	 * connects a function to a hook
387
-	 *
388
-	 * @param string $signalClass class name of emitter
389
-	 * @param string $signalName name of signal
390
-	 * @param string|object $slotClass class name of slot
391
-	 * @param string $slotName name of slot
392
-	 * @return bool
393
-	 *
394
-	 * This function makes it very easy to connect to use hooks.
395
-	 *
396
-	 * TODO: write example
397
-	 * @since 4.0.0
398
-	 * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener
399
-	 */
400
-	public static function connectHook($signalClass, $signalName, $slotClass, $slotName) {
401
-		return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
402
-	}
403
-
404
-	/**
405
-	 * Emits a signal. To get data from the slot use references!
406
-	 * @param string $signalclass class name of emitter
407
-	 * @param string $signalname name of signal
408
-	 * @param array $params default: array() array with additional data
409
-	 * @return bool true if slots exists or false if not
410
-	 *
411
-	 * TODO: write example
412
-	 * @since 4.0.0
413
-	 * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent
414
-	 */
415
-	public static function emitHook($signalclass, $signalname, $params = []) {
416
-		return \OC_Hook::emit($signalclass, $signalname, $params);
417
-	}
418
-
419
-	/**
420
-	 * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
421
-	 * multiple OC_Template elements which invoke `callRegister`. If the value
422
-	 * would not be cached these unit-tests would fail.
423
-	 * @var string
424
-	 */
425
-	private static $token = '';
426
-
427
-	/**
428
-	 * Register an get/post call. This is important to prevent CSRF attacks
429
-	 * @since 4.5.0
430
-	 */
431
-	public static function callRegister() {
432
-		if (self::$token === '') {
433
-			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
434
-		}
435
-		return self::$token;
436
-	}
437
-
438
-	/**
439
-	 * Used to sanitize HTML
440
-	 *
441
-	 * This function is used to sanitize HTML and should be applied on any
442
-	 * string or array of strings before displaying it on a web page.
443
-	 *
444
-	 * @param string|string[] $value
445
-	 * @return string|string[] an array of sanitized strings or a single sanitized string, depends on the input parameter.
446
-	 * @since 4.5.0
447
-	 */
448
-	public static function sanitizeHTML($value) {
449
-		return \OC_Util::sanitizeHTML($value);
450
-	}
451
-
452
-	/**
453
-	 * Public function to encode url parameters
454
-	 *
455
-	 * This function is used to encode path to file before output.
456
-	 * Encoding is done according to RFC 3986 with one exception:
457
-	 * Character '/' is preserved as is.
458
-	 *
459
-	 * @param string $component part of URI to encode
460
-	 * @return string
461
-	 * @since 6.0.0
462
-	 */
463
-	public static function encodePath($component) {
464
-		return \OC_Util::encodePath($component);
465
-	}
466
-
467
-	/**
468
-	 * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
469
-	 *
470
-	 * @param array $input The array to work on
471
-	 * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
472
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
473
-	 * @return array
474
-	 * @since 4.5.0
475
-	 */
476
-	public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
477
-		return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
478
-	}
479
-
480
-	/**
481
-	 * performs a search in a nested array
482
-	 *
483
-	 * @param array $haystack the array to be searched
484
-	 * @param string $needle the search string
485
-	 * @param mixed $index optional, only search this key name
486
-	 * @return mixed the key of the matching field, otherwise false
487
-	 * @since 4.5.0
488
-	 * @deprecated 15.0.0
489
-	 */
490
-	public static function recursiveArraySearch($haystack, $needle, $index = null) {
491
-		return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
492
-	}
493
-
494
-	/**
495
-	 * calculates the maximum upload size respecting system settings, free space and user quota
496
-	 *
497
-	 * @param string $dir the current folder where the user currently operates
498
-	 * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
499
-	 * @return int number of bytes representing
500
-	 * @since 5.0.0
501
-	 */
502
-	public static function maxUploadFilesize($dir, $free = null) {
503
-		return \OC_Helper::maxUploadFilesize($dir, $free);
504
-	}
505
-
506
-	/**
507
-	 * Calculate free space left within user quota
508
-	 * @param string $dir the current folder where the user currently operates
509
-	 * @return int number of bytes representing
510
-	 * @since 7.0.0
511
-	 */
512
-	public static function freeSpace($dir) {
513
-		return \OC_Helper::freeSpace($dir);
514
-	}
515
-
516
-	/**
517
-	 * Calculate PHP upload limit
518
-	 *
519
-	 * @return int number of bytes representing
520
-	 * @since 7.0.0
521
-	 */
522
-	public static function uploadLimit() {
523
-		return \OC_Helper::uploadLimit();
524
-	}
525
-
526
-	/**
527
-	 * Returns whether the given file name is valid
528
-	 * @param string $file file name to check
529
-	 * @return bool true if the file name is valid, false otherwise
530
-	 * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
531
-	 * @since 7.0.0
532
-	 * @suppress PhanDeprecatedFunction
533
-	 */
534
-	public static function isValidFileName($file) {
535
-		return \OC_Util::isValidFileName($file);
536
-	}
537
-
538
-	/**
539
-	 * Compare two strings to provide a natural sort
540
-	 * @param string $a first string to compare
541
-	 * @param string $b second string to compare
542
-	 * @return int -1 if $b comes before $a, 1 if $a comes before $b
543
-	 * or 0 if the strings are identical
544
-	 * @since 7.0.0
545
-	 */
546
-	public static function naturalSortCompare($a, $b) {
547
-		return \OC\NaturalSort::getInstance()->compare($a, $b);
548
-	}
549
-
550
-	/**
551
-	 * Check if a password is required for each public link
552
-	 *
553
-	 * @param bool $checkGroupMembership Check group membership exclusion
554
-	 * @return boolean
555
-	 * @since 7.0.0
556
-	 */
557
-	public static function isPublicLinkPasswordRequired(bool $checkGroupMembership = true) {
558
-		return \OC_Util::isPublicLinkPasswordRequired($checkGroupMembership);
559
-	}
560
-
561
-	/**
562
-	 * check if share API enforces a default expire date
563
-	 * @return boolean
564
-	 * @since 8.0.0
565
-	 */
566
-	public static function isDefaultExpireDateEnforced() {
567
-		return \OC_Util::isDefaultExpireDateEnforced();
568
-	}
569
-
570
-	protected static $needUpgradeCache = null;
571
-
572
-	/**
573
-	 * Checks whether the current version needs upgrade.
574
-	 *
575
-	 * @return bool true if upgrade is needed, false otherwise
576
-	 * @since 7.0.0
577
-	 */
578
-	public static function needUpgrade() {
579
-		if (!isset(self::$needUpgradeCache)) {
580
-			self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
581
-		}
582
-		return self::$needUpgradeCache;
583
-	}
584
-
585
-	/**
586
-	 * Sometimes a string has to be shortened to fit within a certain maximum
587
-	 * data length in bytes. substr() you may break multibyte characters,
588
-	 * because it operates on single byte level. mb_substr() operates on
589
-	 * characters, so does not ensure that the shortend string satisfies the
590
-	 * max length in bytes.
591
-	 *
592
-	 * For example, json_encode is messing with multibyte characters a lot,
593
-	 * replacing them with something along "\u1234".
594
-	 *
595
-	 * This function shortens the string with by $accurancy (-5) from
596
-	 * $dataLength characters, until it fits within $dataLength bytes.
597
-	 *
598
-	 * @since 23.0.0
599
-	 */
600
-	public static function shortenMultibyteString(string $subject, int $dataLength, int $accuracy = 5): string {
601
-		$temp = mb_substr($subject, 0, $dataLength);
602
-		// json encodes encapsulates the string in double quotes, they need to be substracted
603
-		while ((strlen(json_encode($temp)) - 2) > $dataLength) {
604
-			$temp = mb_substr($temp, 0, -$accuracy);
605
-		}
606
-		return $temp;
607
-	}
608
-
609
-	/**
610
-	 * Check if a function is enabled in the php configuration
611
-	 *
612
-	 * @since 25.0.0
613
-	 */
614
-	public static function isFunctionEnabled(string $functionName): bool {
615
-		if (!function_exists($functionName)) {
616
-			return false;
617
-		}
618
-		$ini = \OCP\Server::get(IniGetWrapper::class);
619
-		$disabled = explode(',', $ini->get('disable_functions') ?: '');
620
-		$disabled = array_map('trim', $disabled);
621
-		if (in_array($functionName, $disabled)) {
622
-			return false;
623
-		}
624
-		$disabled = explode(',', $ini->get('suhosin.executor.func.blacklist') ?: '');
625
-		$disabled = array_map('trim', $disabled);
626
-		if (in_array($functionName, $disabled)) {
627
-			return false;
628
-		}
629
-		return true;
630
-	}
59
+    /**
60
+     * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
61
+     */
62
+    public const DEBUG = 0;
63
+    /**
64
+     * @deprecated 14.0.0 use \OCP\ILogger::INFO
65
+     */
66
+    public const INFO = 1;
67
+    /**
68
+     * @deprecated 14.0.0 use \OCP\ILogger::WARN
69
+     */
70
+    public const WARN = 2;
71
+    /**
72
+     * @deprecated 14.0.0 use \OCP\ILogger::ERROR
73
+     */
74
+    public const ERROR = 3;
75
+    /**
76
+     * @deprecated 14.0.0 use \OCP\ILogger::FATAL
77
+     */
78
+    public const FATAL = 4;
79
+
80
+    /** @var \OCP\Share\IManager */
81
+    private static $shareManager;
82
+
83
+    /** @var array */
84
+    private static $scripts = [];
85
+
86
+    /** @var array */
87
+    private static $scriptDeps = [];
88
+
89
+    /** @var array */
90
+    private static $sortedScriptDeps = [];
91
+
92
+    /**
93
+     * get the current installed version of Nextcloud
94
+     * @return array
95
+     * @since 4.0.0
96
+     */
97
+    public static function getVersion() {
98
+        return \OC_Util::getVersion();
99
+    }
100
+
101
+    /**
102
+     * @since 17.0.0
103
+     */
104
+    public static function hasExtendedSupport(): bool {
105
+        try {
106
+            /** @var \OCP\Support\Subscription\IRegistry */
107
+            $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class);
108
+            return $subscriptionRegistry->delegateHasExtendedSupport();
109
+        } catch (AppFramework\QueryException $e) {
110
+        }
111
+        return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false);
112
+    }
113
+
114
+    /**
115
+     * Set current update channel
116
+     * @param string $channel
117
+     * @since 8.1.0
118
+     */
119
+    public static function setChannel($channel) {
120
+        \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
121
+    }
122
+
123
+    /**
124
+     * Get current update channel
125
+     * @return string
126
+     * @since 8.1.0
127
+     */
128
+    public static function getChannel() {
129
+        return \OC_Util::getChannel();
130
+    }
131
+
132
+    /**
133
+     * write a message in the log
134
+     * @param string $app
135
+     * @param string $message
136
+     * @param int $level
137
+     * @since 4.0.0
138
+     * @deprecated 13.0.0 use log of \OCP\ILogger
139
+     */
140
+    public static function writeLog($app, $message, $level) {
141
+        $context = ['app' => $app];
142
+        \OC::$server->getLogger()->log($level, $message, $context);
143
+    }
144
+
145
+    /**
146
+     * check if sharing is disabled for the current user
147
+     *
148
+     * @return boolean
149
+     * @since 7.0.0
150
+     * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
151
+     */
152
+    public static function isSharingDisabledForUser() {
153
+        if (self::$shareManager === null) {
154
+            self::$shareManager = \OC::$server->getShareManager();
155
+        }
156
+
157
+        $user = \OC::$server->getUserSession()->getUser();
158
+        if ($user !== null) {
159
+            $user = $user->getUID();
160
+        }
161
+
162
+        return self::$shareManager->sharingDisabledForUser($user);
163
+    }
164
+
165
+    /**
166
+     * get l10n object
167
+     * @param string $application
168
+     * @param string|null $language
169
+     * @return \OCP\IL10N
170
+     * @since 6.0.0 - parameter $language was added in 8.0.0
171
+     */
172
+    public static function getL10N($application, $language = null) {
173
+        return \OC::$server->getL10N($application, $language);
174
+    }
175
+
176
+    /**
177
+     * add a css file
178
+     * @param string $application
179
+     * @param string $file
180
+     * @since 4.0.0
181
+     */
182
+    public static function addStyle($application, $file = null) {
183
+        \OC_Util::addStyle($application, $file);
184
+    }
185
+
186
+    /**
187
+     * add a javascript file
188
+     *
189
+     * @param string $application
190
+     * @param string|null $file
191
+     * @param string $afterAppId
192
+     * @since 4.0.0
193
+     */
194
+    public static function addScript(string $application, string $file = null, string $afterAppId = 'core'): void {
195
+        if (!empty($application)) {
196
+            $path = "$application/js/$file";
197
+        } else {
198
+            $path = "js/$file";
199
+        }
200
+
201
+        // Inject js translations if we load a script for
202
+        // a specific app that is not core, as those js files
203
+        // need separate handling
204
+        if ($application !== 'core'
205
+            && $file !== null
206
+            && strpos($file, 'l10n') === false) {
207
+            self::addTranslations($application);
208
+        }
209
+
210
+        // store app in dependency list
211
+        if (!array_key_exists($application, self::$scriptDeps)) {
212
+            self::$scriptDeps[$application] = new AppScriptDependency($application, [$afterAppId]);
213
+        } else {
214
+            self::$scriptDeps[$application]->addDep($afterAppId);
215
+        }
216
+
217
+        self::$scripts[$application][] = $path;
218
+    }
219
+
220
+    /**
221
+     * Return the list of scripts injected to the page
222
+     *
223
+     * @return array
224
+     * @since 24.0.0
225
+     */
226
+    public static function getScripts(): array {
227
+        // Sort scriptDeps into sortedScriptDeps
228
+        $scriptSort = \OC::$server->get(AppScriptSort::class);
229
+        $sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps);
230
+
231
+        // Flatten array and remove duplicates
232
+        $sortedScripts = $sortedScripts ? array_merge(...array_values(($sortedScripts))) : [];
233
+
234
+        // Override core-common and core-main order
235
+        array_unshift($sortedScripts, 'core/js/common', 'core/js/main');
236
+
237
+        return array_unique($sortedScripts);
238
+    }
239
+
240
+    /**
241
+     * Add a translation JS file
242
+     * @param string $application application id
243
+     * @param string $languageCode language code, defaults to the current locale
244
+     * @since 8.0.0
245
+     */
246
+    public static function addTranslations($application, $languageCode = null) {
247
+        if (is_null($languageCode)) {
248
+            $languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
249
+        }
250
+        if (!empty($application)) {
251
+            $path = "$application/l10n/$languageCode";
252
+        } else {
253
+            $path = "l10n/$languageCode";
254
+        }
255
+        self::$scripts[$application][] = $path;
256
+    }
257
+
258
+    /**
259
+     * Add a custom element to the header
260
+     * If $text is null then the element will be written as empty element.
261
+     * So use "" to get a closing tag.
262
+     * @param string $tag tag name of the element
263
+     * @param array $attributes array of attributes for the element
264
+     * @param string $text the text content for the element
265
+     * @since 4.0.0
266
+     */
267
+    public static function addHeader($tag, $attributes, $text = null) {
268
+        \OC_Util::addHeader($tag, $attributes, $text);
269
+    }
270
+
271
+    /**
272
+     * Creates an absolute url to the given app and file.
273
+     * @param string $app app
274
+     * @param string $file file
275
+     * @param array $args array with param=>value, will be appended to the returned url
276
+     * 	The value of $args will be urlencoded
277
+     * @return string the url
278
+     * @since 4.0.0 - parameter $args was added in 4.5.0
279
+     */
280
+    public static function linkToAbsolute($app, $file, $args = []) {
281
+        $urlGenerator = \OC::$server->getURLGenerator();
282
+        return $urlGenerator->getAbsoluteURL(
283
+            $urlGenerator->linkTo($app, $file, $args)
284
+        );
285
+    }
286
+
287
+    /**
288
+     * Creates an absolute url for remote use.
289
+     * @param string $service id
290
+     * @return string the url
291
+     * @since 4.0.0
292
+     */
293
+    public static function linkToRemote($service) {
294
+        $urlGenerator = \OC::$server->getURLGenerator();
295
+        $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
296
+        return $urlGenerator->getAbsoluteURL(
297
+            $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
298
+        );
299
+    }
300
+
301
+    /**
302
+     * Creates an absolute url for public use
303
+     * @param string $service id
304
+     * @return string the url
305
+     * @since 4.5.0
306
+     * @deprecated 15.0.0 - use OCP\IURLGenerator
307
+     */
308
+    public static function linkToPublic($service) {
309
+        $urlGenerator = \OC::$server->getURLGenerator();
310
+        if ($service === 'files') {
311
+            return $urlGenerator->getAbsoluteURL('/s');
312
+        }
313
+        return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service);
314
+    }
315
+
316
+    /**
317
+     * Returns the server host name without an eventual port number
318
+     * @return string the server hostname
319
+     * @since 5.0.0
320
+     */
321
+    public static function getServerHostName() {
322
+        $host_name = \OC::$server->getRequest()->getServerHost();
323
+        // strip away port number (if existing)
324
+        $colon_pos = strpos($host_name, ':');
325
+        if ($colon_pos != false) {
326
+            $host_name = substr($host_name, 0, $colon_pos);
327
+        }
328
+        return $host_name;
329
+    }
330
+
331
+    /**
332
+     * Returns the default email address
333
+     * @param string $user_part the user part of the address
334
+     * @return string the default email address
335
+     *
336
+     * Assembles a default email address (using the server hostname
337
+     * and the given user part, and returns it
338
+     * Example: when given lostpassword-noreply as $user_part param,
339
+     *     and is currently accessed via http(s)://example.com/,
340
+     *     it would return '[email protected]'
341
+     *
342
+     * If the configuration value 'mail_from_address' is set in
343
+     * config.php, this value will override the $user_part that
344
+     * is passed to this function
345
+     * @since 5.0.0
346
+     */
347
+    public static function getDefaultEmailAddress($user_part) {
348
+        $config = \OC::$server->getConfig();
349
+        $user_part = $config->getSystemValue('mail_from_address', $user_part);
350
+        $host_name = self::getServerHostName();
351
+        $host_name = $config->getSystemValue('mail_domain', $host_name);
352
+        $defaultEmailAddress = $user_part.'@'.$host_name;
353
+
354
+        $mailer = \OC::$server->getMailer();
355
+        if ($mailer->validateMailAddress($defaultEmailAddress)) {
356
+            return $defaultEmailAddress;
357
+        }
358
+
359
+        // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
360
+        return $user_part.'@localhost.localdomain';
361
+    }
362
+
363
+    /**
364
+     * Make a human file size (2048 to 2 kB)
365
+     * @param int $bytes file size in bytes
366
+     * @return string a human readable file size
367
+     * @since 4.0.0
368
+     */
369
+    public static function humanFileSize($bytes) {
370
+        return \OC_Helper::humanFileSize($bytes);
371
+    }
372
+
373
+    /**
374
+     * Make a computer file size (2 kB to 2048)
375
+     * @param string $str file size in a fancy format
376
+     * @return float|false a file size in bytes
377
+     *
378
+     * Inspired by: https://www.php.net/manual/en/function.filesize.php#92418
379
+     * @since 4.0.0
380
+     */
381
+    public static function computerFileSize($str) {
382
+        return \OC_Helper::computerFileSize($str);
383
+    }
384
+
385
+    /**
386
+     * connects a function to a hook
387
+     *
388
+     * @param string $signalClass class name of emitter
389
+     * @param string $signalName name of signal
390
+     * @param string|object $slotClass class name of slot
391
+     * @param string $slotName name of slot
392
+     * @return bool
393
+     *
394
+     * This function makes it very easy to connect to use hooks.
395
+     *
396
+     * TODO: write example
397
+     * @since 4.0.0
398
+     * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener
399
+     */
400
+    public static function connectHook($signalClass, $signalName, $slotClass, $slotName) {
401
+        return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
402
+    }
403
+
404
+    /**
405
+     * Emits a signal. To get data from the slot use references!
406
+     * @param string $signalclass class name of emitter
407
+     * @param string $signalname name of signal
408
+     * @param array $params default: array() array with additional data
409
+     * @return bool true if slots exists or false if not
410
+     *
411
+     * TODO: write example
412
+     * @since 4.0.0
413
+     * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent
414
+     */
415
+    public static function emitHook($signalclass, $signalname, $params = []) {
416
+        return \OC_Hook::emit($signalclass, $signalname, $params);
417
+    }
418
+
419
+    /**
420
+     * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
421
+     * multiple OC_Template elements which invoke `callRegister`. If the value
422
+     * would not be cached these unit-tests would fail.
423
+     * @var string
424
+     */
425
+    private static $token = '';
426
+
427
+    /**
428
+     * Register an get/post call. This is important to prevent CSRF attacks
429
+     * @since 4.5.0
430
+     */
431
+    public static function callRegister() {
432
+        if (self::$token === '') {
433
+            self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
434
+        }
435
+        return self::$token;
436
+    }
437
+
438
+    /**
439
+     * Used to sanitize HTML
440
+     *
441
+     * This function is used to sanitize HTML and should be applied on any
442
+     * string or array of strings before displaying it on a web page.
443
+     *
444
+     * @param string|string[] $value
445
+     * @return string|string[] an array of sanitized strings or a single sanitized string, depends on the input parameter.
446
+     * @since 4.5.0
447
+     */
448
+    public static function sanitizeHTML($value) {
449
+        return \OC_Util::sanitizeHTML($value);
450
+    }
451
+
452
+    /**
453
+     * Public function to encode url parameters
454
+     *
455
+     * This function is used to encode path to file before output.
456
+     * Encoding is done according to RFC 3986 with one exception:
457
+     * Character '/' is preserved as is.
458
+     *
459
+     * @param string $component part of URI to encode
460
+     * @return string
461
+     * @since 6.0.0
462
+     */
463
+    public static function encodePath($component) {
464
+        return \OC_Util::encodePath($component);
465
+    }
466
+
467
+    /**
468
+     * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
469
+     *
470
+     * @param array $input The array to work on
471
+     * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
472
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
473
+     * @return array
474
+     * @since 4.5.0
475
+     */
476
+    public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
477
+        return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
478
+    }
479
+
480
+    /**
481
+     * performs a search in a nested array
482
+     *
483
+     * @param array $haystack the array to be searched
484
+     * @param string $needle the search string
485
+     * @param mixed $index optional, only search this key name
486
+     * @return mixed the key of the matching field, otherwise false
487
+     * @since 4.5.0
488
+     * @deprecated 15.0.0
489
+     */
490
+    public static function recursiveArraySearch($haystack, $needle, $index = null) {
491
+        return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
492
+    }
493
+
494
+    /**
495
+     * calculates the maximum upload size respecting system settings, free space and user quota
496
+     *
497
+     * @param string $dir the current folder where the user currently operates
498
+     * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
499
+     * @return int number of bytes representing
500
+     * @since 5.0.0
501
+     */
502
+    public static function maxUploadFilesize($dir, $free = null) {
503
+        return \OC_Helper::maxUploadFilesize($dir, $free);
504
+    }
505
+
506
+    /**
507
+     * Calculate free space left within user quota
508
+     * @param string $dir the current folder where the user currently operates
509
+     * @return int number of bytes representing
510
+     * @since 7.0.0
511
+     */
512
+    public static function freeSpace($dir) {
513
+        return \OC_Helper::freeSpace($dir);
514
+    }
515
+
516
+    /**
517
+     * Calculate PHP upload limit
518
+     *
519
+     * @return int number of bytes representing
520
+     * @since 7.0.0
521
+     */
522
+    public static function uploadLimit() {
523
+        return \OC_Helper::uploadLimit();
524
+    }
525
+
526
+    /**
527
+     * Returns whether the given file name is valid
528
+     * @param string $file file name to check
529
+     * @return bool true if the file name is valid, false otherwise
530
+     * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
531
+     * @since 7.0.0
532
+     * @suppress PhanDeprecatedFunction
533
+     */
534
+    public static function isValidFileName($file) {
535
+        return \OC_Util::isValidFileName($file);
536
+    }
537
+
538
+    /**
539
+     * Compare two strings to provide a natural sort
540
+     * @param string $a first string to compare
541
+     * @param string $b second string to compare
542
+     * @return int -1 if $b comes before $a, 1 if $a comes before $b
543
+     * or 0 if the strings are identical
544
+     * @since 7.0.0
545
+     */
546
+    public static function naturalSortCompare($a, $b) {
547
+        return \OC\NaturalSort::getInstance()->compare($a, $b);
548
+    }
549
+
550
+    /**
551
+     * Check if a password is required for each public link
552
+     *
553
+     * @param bool $checkGroupMembership Check group membership exclusion
554
+     * @return boolean
555
+     * @since 7.0.0
556
+     */
557
+    public static function isPublicLinkPasswordRequired(bool $checkGroupMembership = true) {
558
+        return \OC_Util::isPublicLinkPasswordRequired($checkGroupMembership);
559
+    }
560
+
561
+    /**
562
+     * check if share API enforces a default expire date
563
+     * @return boolean
564
+     * @since 8.0.0
565
+     */
566
+    public static function isDefaultExpireDateEnforced() {
567
+        return \OC_Util::isDefaultExpireDateEnforced();
568
+    }
569
+
570
+    protected static $needUpgradeCache = null;
571
+
572
+    /**
573
+     * Checks whether the current version needs upgrade.
574
+     *
575
+     * @return bool true if upgrade is needed, false otherwise
576
+     * @since 7.0.0
577
+     */
578
+    public static function needUpgrade() {
579
+        if (!isset(self::$needUpgradeCache)) {
580
+            self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
581
+        }
582
+        return self::$needUpgradeCache;
583
+    }
584
+
585
+    /**
586
+     * Sometimes a string has to be shortened to fit within a certain maximum
587
+     * data length in bytes. substr() you may break multibyte characters,
588
+     * because it operates on single byte level. mb_substr() operates on
589
+     * characters, so does not ensure that the shortend string satisfies the
590
+     * max length in bytes.
591
+     *
592
+     * For example, json_encode is messing with multibyte characters a lot,
593
+     * replacing them with something along "\u1234".
594
+     *
595
+     * This function shortens the string with by $accurancy (-5) from
596
+     * $dataLength characters, until it fits within $dataLength bytes.
597
+     *
598
+     * @since 23.0.0
599
+     */
600
+    public static function shortenMultibyteString(string $subject, int $dataLength, int $accuracy = 5): string {
601
+        $temp = mb_substr($subject, 0, $dataLength);
602
+        // json encodes encapsulates the string in double quotes, they need to be substracted
603
+        while ((strlen(json_encode($temp)) - 2) > $dataLength) {
604
+            $temp = mb_substr($temp, 0, -$accuracy);
605
+        }
606
+        return $temp;
607
+    }
608
+
609
+    /**
610
+     * Check if a function is enabled in the php configuration
611
+     *
612
+     * @since 25.0.0
613
+     */
614
+    public static function isFunctionEnabled(string $functionName): bool {
615
+        if (!function_exists($functionName)) {
616
+            return false;
617
+        }
618
+        $ini = \OCP\Server::get(IniGetWrapper::class);
619
+        $disabled = explode(',', $ini->get('disable_functions') ?: '');
620
+        $disabled = array_map('trim', $disabled);
621
+        if (in_array($functionName, $disabled)) {
622
+            return false;
623
+        }
624
+        $disabled = explode(',', $ini->get('suhosin.executor.func.blacklist') ?: '');
625
+        $disabled = array_map('trim', $disabled);
626
+        if (in_array($functionName, $disabled)) {
627
+            return false;
628
+        }
629
+        return true;
630
+    }
631 631
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Controller.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
 		// default responders
80 80
 		$this->responders = [
81
-			'json' => function ($data) {
81
+			'json' => function($data) {
82 82
 				if ($data instanceof DataResponse) {
83 83
 					$response = new JSONResponse(
84 84
 						$data->getData(),
@@ -153,6 +153,6 @@  discard block
 block discarded – undo
153 153
 			return $responder($response);
154 154
 		}
155 155
 		throw new \DomainException('No responder registered for format '.
156
-			$format . '!');
156
+			$format.'!');
157 157
 	}
158 158
 }
Please login to merge, or discard this patch.
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -45,122 +45,122 @@
 block discarded – undo
45 45
  */
46 46
 abstract class Controller {
47 47
 
48
-	/**
49
-	 * app name
50
-	 * @var string
51
-	 * @since 7.0.0
52
-	 */
53
-	protected $appName;
54
-
55
-	/**
56
-	 * current request
57
-	 * @var \OCP\IRequest
58
-	 * @since 6.0.0
59
-	 */
60
-	protected $request;
61
-
62
-	/**
63
-	 * @var array
64
-	 * @since 7.0.0
65
-	 */
66
-	private $responders;
67
-
68
-	/**
69
-	 * constructor of the controller
70
-	 * @param string $appName the name of the app
71
-	 * @param IRequest $request an instance of the request
72
-	 * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
73
-	 */
74
-	public function __construct($appName,
75
-								IRequest $request) {
76
-		$this->appName = $appName;
77
-		$this->request = $request;
78
-
79
-		// default responders
80
-		$this->responders = [
81
-			'json' => function ($data) {
82
-				if ($data instanceof DataResponse) {
83
-					$response = new JSONResponse(
84
-						$data->getData(),
85
-						$data->getStatus()
86
-					);
87
-					$dataHeaders = $data->getHeaders();
88
-					$headers = $response->getHeaders();
89
-					// do not overwrite Content-Type if it already exists
90
-					if (isset($dataHeaders['Content-Type'])) {
91
-						unset($headers['Content-Type']);
92
-					}
93
-					$response->setHeaders(array_merge($dataHeaders, $headers));
94
-
95
-					if ($data->getETag() !== null) {
96
-						$response->setETag($data->getETag());
97
-					}
98
-					if ($data->getLastModified() !== null) {
99
-						$response->setLastModified($data->getLastModified());
100
-					}
101
-
102
-					return $response;
103
-				}
104
-				return new JSONResponse($data);
105
-			}
106
-		];
107
-	}
108
-
109
-
110
-	/**
111
-	 * Parses an HTTP accept header and returns the supported responder type
112
-	 * @param string $acceptHeader
113
-	 * @param string $default
114
-	 * @return string the responder type
115
-	 * @since 7.0.0
116
-	 * @since 9.1.0 Added default parameter
117
-	 */
118
-	public function getResponderByHTTPHeader($acceptHeader, $default = 'json') {
119
-		$headers = explode(',', $acceptHeader);
120
-
121
-		// return the first matching responder
122
-		foreach ($headers as $header) {
123
-			$header = strtolower(trim($header));
124
-
125
-			$responder = str_replace('application/', '', $header);
126
-
127
-			if (array_key_exists($responder, $this->responders)) {
128
-				return $responder;
129
-			}
130
-		}
131
-
132
-		// no matching header return default
133
-		return $default;
134
-	}
135
-
136
-
137
-	/**
138
-	 * Registers a formatter for a type
139
-	 * @param string $format
140
-	 * @param \Closure $responder
141
-	 * @since 7.0.0
142
-	 */
143
-	protected function registerResponder($format, \Closure $responder) {
144
-		$this->responders[$format] = $responder;
145
-	}
146
-
147
-
148
-	/**
149
-	 * Serializes and formats a response
150
-	 * @param mixed $response the value that was returned from a controller and
151
-	 * is not a Response instance
152
-	 * @param string $format the format for which a formatter has been registered
153
-	 * @throws \DomainException if format does not match a registered formatter
154
-	 * @return Response
155
-	 * @since 7.0.0
156
-	 */
157
-	public function buildResponse($response, $format = 'json') {
158
-		if (array_key_exists($format, $this->responders)) {
159
-			$responder = $this->responders[$format];
160
-
161
-			return $responder($response);
162
-		}
163
-		throw new \DomainException('No responder registered for format '.
164
-			$format . '!');
165
-	}
48
+    /**
49
+     * app name
50
+     * @var string
51
+     * @since 7.0.0
52
+     */
53
+    protected $appName;
54
+
55
+    /**
56
+     * current request
57
+     * @var \OCP\IRequest
58
+     * @since 6.0.0
59
+     */
60
+    protected $request;
61
+
62
+    /**
63
+     * @var array
64
+     * @since 7.0.0
65
+     */
66
+    private $responders;
67
+
68
+    /**
69
+     * constructor of the controller
70
+     * @param string $appName the name of the app
71
+     * @param IRequest $request an instance of the request
72
+     * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
73
+     */
74
+    public function __construct($appName,
75
+                                IRequest $request) {
76
+        $this->appName = $appName;
77
+        $this->request = $request;
78
+
79
+        // default responders
80
+        $this->responders = [
81
+            'json' => function ($data) {
82
+                if ($data instanceof DataResponse) {
83
+                    $response = new JSONResponse(
84
+                        $data->getData(),
85
+                        $data->getStatus()
86
+                    );
87
+                    $dataHeaders = $data->getHeaders();
88
+                    $headers = $response->getHeaders();
89
+                    // do not overwrite Content-Type if it already exists
90
+                    if (isset($dataHeaders['Content-Type'])) {
91
+                        unset($headers['Content-Type']);
92
+                    }
93
+                    $response->setHeaders(array_merge($dataHeaders, $headers));
94
+
95
+                    if ($data->getETag() !== null) {
96
+                        $response->setETag($data->getETag());
97
+                    }
98
+                    if ($data->getLastModified() !== null) {
99
+                        $response->setLastModified($data->getLastModified());
100
+                    }
101
+
102
+                    return $response;
103
+                }
104
+                return new JSONResponse($data);
105
+            }
106
+        ];
107
+    }
108
+
109
+
110
+    /**
111
+     * Parses an HTTP accept header and returns the supported responder type
112
+     * @param string $acceptHeader
113
+     * @param string $default
114
+     * @return string the responder type
115
+     * @since 7.0.0
116
+     * @since 9.1.0 Added default parameter
117
+     */
118
+    public function getResponderByHTTPHeader($acceptHeader, $default = 'json') {
119
+        $headers = explode(',', $acceptHeader);
120
+
121
+        // return the first matching responder
122
+        foreach ($headers as $header) {
123
+            $header = strtolower(trim($header));
124
+
125
+            $responder = str_replace('application/', '', $header);
126
+
127
+            if (array_key_exists($responder, $this->responders)) {
128
+                return $responder;
129
+            }
130
+        }
131
+
132
+        // no matching header return default
133
+        return $default;
134
+    }
135
+
136
+
137
+    /**
138
+     * Registers a formatter for a type
139
+     * @param string $format
140
+     * @param \Closure $responder
141
+     * @since 7.0.0
142
+     */
143
+    protected function registerResponder($format, \Closure $responder) {
144
+        $this->responders[$format] = $responder;
145
+    }
146
+
147
+
148
+    /**
149
+     * Serializes and formats a response
150
+     * @param mixed $response the value that was returned from a controller and
151
+     * is not a Response instance
152
+     * @param string $format the format for which a formatter has been registered
153
+     * @throws \DomainException if format does not match a registered formatter
154
+     * @return Response
155
+     * @since 7.0.0
156
+     */
157
+    public function buildResponse($response, $format = 'json') {
158
+        if (array_key_exists($format, $this->responders)) {
159
+            $responder = $this->responders[$format];
160
+
161
+            return $responder($response);
162
+        }
163
+        throw new \DomainException('No responder registered for format '.
164
+            $format . '!');
165
+    }
166 166
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Middleware.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -42,67 +42,67 @@
 block discarded – undo
42 42
 abstract class Middleware {
43 43
 
44 44
 
45
-	/**
46
-	 * This is being run in normal order before the controller is being
47
-	 * called which allows several modifications and checks
48
-	 *
49
-	 * @param Controller $controller the controller that is being called
50
-	 * @param string $methodName the name of the method that will be called on
51
-	 *                           the controller
52
-	 * @since 6.0.0
53
-	 */
54
-	public function beforeController($controller, $methodName) {
55
-	}
45
+    /**
46
+     * This is being run in normal order before the controller is being
47
+     * called which allows several modifications and checks
48
+     *
49
+     * @param Controller $controller the controller that is being called
50
+     * @param string $methodName the name of the method that will be called on
51
+     *                           the controller
52
+     * @since 6.0.0
53
+     */
54
+    public function beforeController($controller, $methodName) {
55
+    }
56 56
 
57 57
 
58
-	/**
59
-	 * This is being run when either the beforeController method or the
60
-	 * controller method itself is throwing an exception. The middleware is
61
-	 * asked in reverse order to handle the exception and to return a response.
62
-	 * If the response is null, it is assumed that the exception could not be
63
-	 * handled and the error will be thrown again
64
-	 *
65
-	 * @param Controller $controller the controller that is being called
66
-	 * @param string $methodName the name of the method that will be called on
67
-	 *                           the controller
68
-	 * @param \Exception $exception the thrown exception
69
-	 * @throws \Exception the passed in exception if it can't handle it
70
-	 * @return Response a Response object in case that the exception was handled
71
-	 * @since 6.0.0
72
-	 */
73
-	public function afterException($controller, $methodName, \Exception $exception) {
74
-		throw $exception;
75
-	}
58
+    /**
59
+     * This is being run when either the beforeController method or the
60
+     * controller method itself is throwing an exception. The middleware is
61
+     * asked in reverse order to handle the exception and to return a response.
62
+     * If the response is null, it is assumed that the exception could not be
63
+     * handled and the error will be thrown again
64
+     *
65
+     * @param Controller $controller the controller that is being called
66
+     * @param string $methodName the name of the method that will be called on
67
+     *                           the controller
68
+     * @param \Exception $exception the thrown exception
69
+     * @throws \Exception the passed in exception if it can't handle it
70
+     * @return Response a Response object in case that the exception was handled
71
+     * @since 6.0.0
72
+     */
73
+    public function afterException($controller, $methodName, \Exception $exception) {
74
+        throw $exception;
75
+    }
76 76
 
77 77
 
78
-	/**
79
-	 * This is being run after a successful controllermethod call and allows
80
-	 * the manipulation of a Response object. The middleware is run in reverse order
81
-	 *
82
-	 * @param Controller $controller the controller that is being called
83
-	 * @param string $methodName the name of the method that will be called on
84
-	 *                           the controller
85
-	 * @param Response $response the generated response from the controller
86
-	 * @return Response a Response object
87
-	 * @since 6.0.0
88
-	 */
89
-	public function afterController($controller, $methodName, Response $response) {
90
-		return $response;
91
-	}
78
+    /**
79
+     * This is being run after a successful controllermethod call and allows
80
+     * the manipulation of a Response object. The middleware is run in reverse order
81
+     *
82
+     * @param Controller $controller the controller that is being called
83
+     * @param string $methodName the name of the method that will be called on
84
+     *                           the controller
85
+     * @param Response $response the generated response from the controller
86
+     * @return Response a Response object
87
+     * @since 6.0.0
88
+     */
89
+    public function afterController($controller, $methodName, Response $response) {
90
+        return $response;
91
+    }
92 92
 
93 93
 
94
-	/**
95
-	 * This is being run after the response object has been rendered and
96
-	 * allows the manipulation of the output. The middleware is run in reverse order
97
-	 *
98
-	 * @param Controller $controller the controller that is being called
99
-	 * @param string $methodName the name of the method that will be called on
100
-	 *                           the controller
101
-	 * @param string $output the generated output from a response
102
-	 * @return string the output that should be printed
103
-	 * @since 6.0.0
104
-	 */
105
-	public function beforeOutput($controller, $methodName, $output) {
106
-		return $output;
107
-	}
94
+    /**
95
+     * This is being run after the response object has been rendered and
96
+     * allows the manipulation of the output. The middleware is run in reverse order
97
+     *
98
+     * @param Controller $controller the controller that is being called
99
+     * @param string $methodName the name of the method that will be called on
100
+     *                           the controller
101
+     * @param string $output the generated output from a response
102
+     * @return string the output that should be printed
103
+     * @since 6.0.0
104
+     */
105
+    public function beforeOutput($controller, $methodName, $output) {
106
+        return $output;
107
+    }
108 108
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSNotFoundException.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@
 block discarded – undo
32 32
  * @since 9.1.0
33 33
  */
34 34
 class OCSNotFoundException extends OCSException {
35
-	/**
36
-	 * OCSNotFoundException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_NOT_FOUND, $previous);
44
-	}
35
+    /**
36
+     * OCSNotFoundException constructor.
37
+     *
38
+     * @param string $message
39
+     * @param Exception|null $previous
40
+     * @since 9.1.0
41
+     */
42
+    public function __construct($message = '', Exception $previous = null) {
43
+        parent::__construct($message, Http::STATUS_NOT_FOUND, $previous);
44
+    }
45 45
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSForbiddenException.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@
 block discarded – undo
32 32
  * @since 9.1.0
33 33
  */
34 34
 class OCSForbiddenException extends OCSException {
35
-	/**
36
-	 * OCSForbiddenException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_FORBIDDEN, $previous);
44
-	}
35
+    /**
36
+     * OCSForbiddenException constructor.
37
+     *
38
+     * @param string $message
39
+     * @param Exception|null $previous
40
+     * @since 9.1.0
41
+     */
42
+    public function __construct($message = '', Exception $previous = null) {
43
+        parent::__construct($message, Http::STATUS_FORBIDDEN, $previous);
44
+    }
45 45
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSBadRequestException.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@
 block discarded – undo
32 32
  * @since 9.1.0
33 33
  */
34 34
 class OCSBadRequestException extends OCSException {
35
-	/**
36
-	 * OCSBadRequestException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous);
44
-	}
35
+    /**
36
+     * OCSBadRequestException constructor.
37
+     *
38
+     * @param string $message
39
+     * @param Exception|null $previous
40
+     * @since 9.1.0
41
+     */
42
+    public function __construct($message = '', Exception $previous = null) {
43
+        parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous);
44
+    }
45 45
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/FileDisplayResponse.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		$this->file = $file;
52 52
 		$this->setStatus($statusCode);
53 53
 		$this->setHeaders(array_merge($this->getHeaders(), $headers));
54
-		$this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"');
54
+		$this->addHeader('Content-Disposition', 'inline; filename="'.rawurldecode($file->getName()).'"');
55 55
 
56 56
 		$this->setETag($file->getEtag());
57 57
 		$lastModified = new \DateTime();
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	public function callback(IOutput $output) {
67 67
 		if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
68
-			$output->setHeader('Content-Length: ' . $this->file->getSize());
68
+			$output->setHeader('Content-Length: '.$this->file->getSize());
69 69
 			$output->setOutput($this->file->getContent());
70 70
 		}
71 71
 	}
Please login to merge, or discard this patch.
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -32,40 +32,40 @@
 block discarded – undo
32 32
  */
33 33
 class FileDisplayResponse extends Response implements ICallbackResponse {
34 34
 
35
-	/** @var \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile */
36
-	private $file;
35
+    /** @var \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile */
36
+    private $file;
37 37
 
38
-	/**
39
-	 * FileDisplayResponse constructor.
40
-	 *
41
-	 * @param \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile $file
42
-	 * @param int $statusCode
43
-	 * @param array $headers
44
-	 * @since 11.0.0
45
-	 */
46
-	public function __construct($file, $statusCode = Http::STATUS_OK,
47
-								$headers = []) {
48
-		parent::__construct();
38
+    /**
39
+     * FileDisplayResponse constructor.
40
+     *
41
+     * @param \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile $file
42
+     * @param int $statusCode
43
+     * @param array $headers
44
+     * @since 11.0.0
45
+     */
46
+    public function __construct($file, $statusCode = Http::STATUS_OK,
47
+                                $headers = []) {
48
+        parent::__construct();
49 49
 
50
-		$this->file = $file;
51
-		$this->setStatus($statusCode);
52
-		$this->setHeaders(array_merge($this->getHeaders(), $headers));
53
-		$this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"');
50
+        $this->file = $file;
51
+        $this->setStatus($statusCode);
52
+        $this->setHeaders(array_merge($this->getHeaders(), $headers));
53
+        $this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"');
54 54
 
55
-		$this->setETag($file->getEtag());
56
-		$lastModified = new \DateTime();
57
-		$lastModified->setTimestamp($file->getMTime());
58
-		$this->setLastModified($lastModified);
59
-	}
55
+        $this->setETag($file->getEtag());
56
+        $lastModified = new \DateTime();
57
+        $lastModified->setTimestamp($file->getMTime());
58
+        $this->setLastModified($lastModified);
59
+    }
60 60
 
61
-	/**
62
-	 * @param IOutput $output
63
-	 * @since 11.0.0
64
-	 */
65
-	public function callback(IOutput $output) {
66
-		if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
67
-			$output->setHeader('Content-Length: ' . $this->file->getSize());
68
-			$output->setOutput($this->file->getContent());
69
-		}
70
-	}
61
+    /**
62
+     * @param IOutput $output
63
+     * @since 11.0.0
64
+     */
65
+    public function callback(IOutput $output) {
66
+        if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
67
+            $output->setHeader('Content-Length: ' . $this->file->getSize());
68
+            $output->setOutput($this->file->getContent());
69
+        }
70
+    }
71 71
 }
Please login to merge, or discard this patch.
lib/private/IntegrityCheck/Iterator/ExcludeFoldersByPathFilterIterator.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -35,17 +35,17 @@
 block discarded – undo
35 35
 		}
36 36
 
37 37
 		$excludedFolders = [
38
-			rtrim($root . '/data', '/'),
39
-			rtrim($root . '/themes', '/'),
40
-			rtrim($root . '/config', '/'),
41
-			rtrim($root . '/apps', '/'),
42
-			rtrim($root . '/assets', '/'),
43
-			rtrim($root . '/lost+found', '/'),
38
+			rtrim($root.'/data', '/'),
39
+			rtrim($root.'/themes', '/'),
40
+			rtrim($root.'/config', '/'),
41
+			rtrim($root.'/apps', '/'),
42
+			rtrim($root.'/assets', '/'),
43
+			rtrim($root.'/lost+found', '/'),
44 44
 			// Ignore folders generated by updater since the updater is replaced
45 45
 			// after the integrity check is run.
46 46
 			// See https://github.com/owncloud/updater/issues/318#issuecomment-212497846
47
-			rtrim($root . '/updater', '/'),
48
-			rtrim($root . '/_oc_upgrade', '/'),
47
+			rtrim($root.'/updater', '/'),
48
+			rtrim($root.'/_oc_upgrade', '/'),
49 49
 		];
50 50
 		$customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', '');
51 51
 		if ($customDataDir !== '') {
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -28,42 +28,42 @@
 block discarded – undo
28 28
 namespace OC\IntegrityCheck\Iterator;
29 29
 
30 30
 class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator {
31
-	private $excludedFolders;
31
+    private $excludedFolders;
32 32
 
33
-	public function __construct(\RecursiveIterator $iterator, $root = '') {
34
-		parent::__construct($iterator);
33
+    public function __construct(\RecursiveIterator $iterator, $root = '') {
34
+        parent::__construct($iterator);
35 35
 
36
-		$appFolders = \OC::$APPSROOTS;
37
-		foreach ($appFolders as $key => $appFolder) {
38
-			$appFolders[$key] = rtrim($appFolder['path'], '/');
39
-		}
36
+        $appFolders = \OC::$APPSROOTS;
37
+        foreach ($appFolders as $key => $appFolder) {
38
+            $appFolders[$key] = rtrim($appFolder['path'], '/');
39
+        }
40 40
 
41
-		$excludedFolders = [
42
-			rtrim($root . '/data', '/'),
43
-			rtrim($root . '/themes', '/'),
44
-			rtrim($root . '/config', '/'),
45
-			rtrim($root . '/apps', '/'),
46
-			rtrim($root . '/assets', '/'),
47
-			rtrim($root . '/lost+found', '/'),
48
-			// Ignore folders generated by updater since the updater is replaced
49
-			// after the integrity check is run.
50
-			// See https://github.com/owncloud/updater/issues/318#issuecomment-212497846
51
-			rtrim($root . '/updater', '/'),
52
-			rtrim($root . '/_oc_upgrade', '/'),
53
-		];
54
-		$customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', '');
55
-		if ($customDataDir !== '') {
56
-			$excludedFolders[] = rtrim($customDataDir, '/');
57
-		}
41
+        $excludedFolders = [
42
+            rtrim($root . '/data', '/'),
43
+            rtrim($root . '/themes', '/'),
44
+            rtrim($root . '/config', '/'),
45
+            rtrim($root . '/apps', '/'),
46
+            rtrim($root . '/assets', '/'),
47
+            rtrim($root . '/lost+found', '/'),
48
+            // Ignore folders generated by updater since the updater is replaced
49
+            // after the integrity check is run.
50
+            // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846
51
+            rtrim($root . '/updater', '/'),
52
+            rtrim($root . '/_oc_upgrade', '/'),
53
+        ];
54
+        $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', '');
55
+        if ($customDataDir !== '') {
56
+            $excludedFolders[] = rtrim($customDataDir, '/');
57
+        }
58 58
 
59
-		$this->excludedFolders = array_merge($excludedFolders, $appFolders);
60
-	}
59
+        $this->excludedFolders = array_merge($excludedFolders, $appFolders);
60
+    }
61 61
 
62
-	public function accept(): bool {
63
-		return !\in_array(
64
-			$this->current()->getPathName(),
65
-			$this->excludedFolders,
66
-			true
67
-		);
68
-	}
62
+    public function accept(): bool {
63
+        return !\in_array(
64
+            $this->current()->getPathName(),
65
+            $this->excludedFolders,
66
+            true
67
+        );
68
+    }
69 69
 }
Please login to merge, or discard this patch.