Completed
Pull Request — master (#3233)
by Christoph
95:52 queued 83:56
created
lib/private/Federation/CloudId.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -23,54 +23,54 @@
 block discarded – undo
23 23
 use OCP\Federation\ICloudId;
24 24
 
25 25
 class CloudId implements ICloudId {
26
-	/** @var string */
27
-	private $id;
28
-	/** @var string */
29
-	private $user;
30
-	/** @var string */
31
-	private $remote;
26
+    /** @var string */
27
+    private $id;
28
+    /** @var string */
29
+    private $user;
30
+    /** @var string */
31
+    private $remote;
32 32
 
33
-	/**
34
-	 * CloudId constructor.
35
-	 *
36
-	 * @param string $id
37
-	 * @param string $user
38
-	 * @param string $remote
39
-	 */
40
-	public function __construct($id, $user, $remote) {
41
-		$this->id = $id;
42
-		$this->user = $user;
43
-		$this->remote = $remote;
44
-	}
33
+    /**
34
+     * CloudId constructor.
35
+     *
36
+     * @param string $id
37
+     * @param string $user
38
+     * @param string $remote
39
+     */
40
+    public function __construct($id, $user, $remote) {
41
+        $this->id = $id;
42
+        $this->user = $user;
43
+        $this->remote = $remote;
44
+    }
45 45
 
46
-	/**
47
-	 * The full remote cloud id
48
-	 *
49
-	 * @return string
50
-	 */
51
-	public function getId() {
52
-		return $this->id;
53
-	}
46
+    /**
47
+     * The full remote cloud id
48
+     *
49
+     * @return string
50
+     */
51
+    public function getId() {
52
+        return $this->id;
53
+    }
54 54
 
55
-	public function getDisplayId() {
56
-		return str_replace('https://', '', str_replace('http://', '', $this->getId()));
57
-	}
55
+    public function getDisplayId() {
56
+        return str_replace('https://', '', str_replace('http://', '', $this->getId()));
57
+    }
58 58
 
59
-	/**
60
-	 * The username on the remote server
61
-	 *
62
-	 * @return string
63
-	 */
64
-	public function getUser() {
65
-		return $this->user;
66
-	}
59
+    /**
60
+     * The username on the remote server
61
+     *
62
+     * @return string
63
+     */
64
+    public function getUser() {
65
+        return $this->user;
66
+    }
67 67
 
68
-	/**
69
-	 * The base address of the remote server
70
-	 *
71
-	 * @return string
72
-	 */
73
-	public function getRemote() {
74
-		return $this->remote;
75
-	}
68
+    /**
69
+     * The base address of the remote server
70
+     *
71
+     * @return string
72
+     */
73
+    public function getRemote() {
74
+        return $this->remote;
75
+    }
76 76
 }
Please login to merge, or discard this patch.
lib/private/DatabaseException.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@
 block discarded – undo
24 24
 namespace OC;
25 25
 
26 26
 class DatabaseException extends \Exception {
27
-	private $query;
27
+    private $query;
28 28
 
29
-	//FIXME getQuery seems to be unused, maybe use parent constructor with $message, $code and $previous
30
-	public function __construct($message, $query = null){
31
-		parent::__construct($message);
32
-		$this->query = $query;
33
-	}
29
+    //FIXME getQuery seems to be unused, maybe use parent constructor with $message, $code and $previous
30
+    public function __construct($message, $query = null){
31
+        parent::__construct($message);
32
+        $this->query = $query;
33
+    }
34 34
 
35
-	public function getQuery() {
36
-		return $this->query;
37
-	}
35
+    public function getQuery() {
36
+        return $this->query;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
lib/private/Log/Errorlog.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -28,20 +28,20 @@
 block discarded – undo
28 28
 class Errorlog {
29 29
 
30 30
 
31
-	/**
32
-	 * Init class data
33
-	 */
34
-	public static function init() {
35
-	}
31
+    /**
32
+     * Init class data
33
+     */
34
+    public static function init() {
35
+    }
36 36
 
37
-	/**
38
-	 * write a message in the log
39
-	 * @param string $app
40
-	 * @param string $message
41
-	 * @param int $level
42
-	 */
43
-	public static function write($app, $message, $level) {
44
-		error_log('[owncloud]['.$app.']['.$level.'] '.$message);
45
-	}
37
+    /**
38
+     * write a message in the log
39
+     * @param string $app
40
+     * @param string $message
41
+     * @param int $level
42
+     */
43
+    public static function write($app, $message, $level) {
44
+        error_log('[owncloud]['.$app.']['.$level.'] '.$message);
45
+    }
46 46
 }
47 47
 
Please login to merge, or discard this patch.
lib/private/Log/Syslog.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -26,31 +26,31 @@
 block discarded – undo
26 26
 namespace OC\Log;
27 27
 
28 28
 class Syslog {
29
-	static protected $levels = array(
30
-		\OCP\Util::DEBUG => LOG_DEBUG,
31
-		\OCP\Util::INFO => LOG_INFO,
32
-		\OCP\Util::WARN => LOG_WARNING,
33
-		\OCP\Util::ERROR => LOG_ERR,
34
-		\OCP\Util::FATAL => LOG_CRIT,
35
-	);
29
+    static protected $levels = array(
30
+        \OCP\Util::DEBUG => LOG_DEBUG,
31
+        \OCP\Util::INFO => LOG_INFO,
32
+        \OCP\Util::WARN => LOG_WARNING,
33
+        \OCP\Util::ERROR => LOG_ERR,
34
+        \OCP\Util::FATAL => LOG_CRIT,
35
+    );
36 36
 
37
-	/**
38
-	 * Init class data
39
-	 */
40
-	public static function init() {
41
-		openlog(\OC::$server->getSystemConfig()->getValue("syslog_tag", "ownCloud"), LOG_PID | LOG_CONS, LOG_USER);
42
-		// Close at shutdown
43
-		register_shutdown_function('closelog');
44
-	}
37
+    /**
38
+     * Init class data
39
+     */
40
+    public static function init() {
41
+        openlog(\OC::$server->getSystemConfig()->getValue("syslog_tag", "ownCloud"), LOG_PID | LOG_CONS, LOG_USER);
42
+        // Close at shutdown
43
+        register_shutdown_function('closelog');
44
+    }
45 45
 
46
-	/**
47
-	 * write a message in the log
48
-	 * @param string $app
49
-	 * @param string $message
50
-	 * @param int $level
51
-	 */
52
-	public static function write($app, $message, $level) {
53
-		$syslog_level = self::$levels[$level];
54
-		syslog($syslog_level, '{'.$app.'} '.$message);
55
-	}
46
+    /**
47
+     * write a message in the log
48
+     * @param string $app
49
+     * @param string $message
50
+     * @param int $level
51
+     */
52
+    public static function write($app, $message, $level) {
53
+        $syslog_level = self::$levels[$level];
54
+        syslog($syslog_level, '{'.$app.'} '.$message);
55
+    }
56 56
 }
Please login to merge, or discard this patch.
lib/private/Log/ErrorHandler.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -28,74 +28,74 @@
 block discarded – undo
28 28
 use OCP\ILogger;
29 29
 
30 30
 class ErrorHandler {
31
-	/** @var ILogger */
32
-	private static $logger;
31
+    /** @var ILogger */
32
+    private static $logger;
33 33
 
34
-	/**
35
-	 * remove password in URLs
36
-	 * @param string $msg
37
-	 * @return string
38
-	 */
39
-	protected static function removePassword($msg) {
40
-		return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg);
41
-	}
34
+    /**
35
+     * remove password in URLs
36
+     * @param string $msg
37
+     * @return string
38
+     */
39
+    protected static function removePassword($msg) {
40
+        return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg);
41
+    }
42 42
 
43
-	public static function register($debug=false) {
44
-		$handler = new ErrorHandler();
43
+    public static function register($debug=false) {
44
+        $handler = new ErrorHandler();
45 45
 
46
-		if ($debug) {
47
-			set_error_handler(array($handler, 'onAll'), E_ALL);
48
-			if (\OC::$CLI) {
49
-				set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
50
-			}
51
-		} else {
52
-			set_error_handler(array($handler, 'onError'));
53
-		}
54
-		register_shutdown_function(array($handler, 'onShutdown'));
55
-		set_exception_handler(array($handler, 'onException'));
56
-	}
46
+        if ($debug) {
47
+            set_error_handler(array($handler, 'onAll'), E_ALL);
48
+            if (\OC::$CLI) {
49
+                set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
50
+            }
51
+        } else {
52
+            set_error_handler(array($handler, 'onError'));
53
+        }
54
+        register_shutdown_function(array($handler, 'onShutdown'));
55
+        set_exception_handler(array($handler, 'onException'));
56
+    }
57 57
 
58
-	public static function setLogger(ILogger $logger) {
59
-		self::$logger = $logger;
60
-	}
58
+    public static function setLogger(ILogger $logger) {
59
+        self::$logger = $logger;
60
+    }
61 61
 
62
-	//Fatal errors handler
63
-	public static function onShutdown() {
64
-		$error = error_get_last();
65
-		if($error && self::$logger) {
66
-			//ob_end_clean();
67
-			$msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line'];
68
-			self::$logger->critical(self::removePassword($msg), array('app' => 'PHP'));
69
-		}
70
-	}
62
+    //Fatal errors handler
63
+    public static function onShutdown() {
64
+        $error = error_get_last();
65
+        if($error && self::$logger) {
66
+            //ob_end_clean();
67
+            $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line'];
68
+            self::$logger->critical(self::removePassword($msg), array('app' => 'PHP'));
69
+        }
70
+    }
71 71
 
72
-	/**
73
-	 * 	Uncaught exception handler
74
-	 *
75
-	 * @param \Exception $exception
76
-	 */
77
-	public static function onException($exception) {
78
-		$class = get_class($exception);
79
-		$msg = $exception->getMessage();
80
-		$msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine();
81
-		self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']);
82
-	}
72
+    /**
73
+     * 	Uncaught exception handler
74
+     *
75
+     * @param \Exception $exception
76
+     */
77
+    public static function onException($exception) {
78
+        $class = get_class($exception);
79
+        $msg = $exception->getMessage();
80
+        $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine();
81
+        self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']);
82
+    }
83 83
 
84
-	//Recoverable errors handler
85
-	public static function onError($number, $message, $file, $line) {
86
-		if (error_reporting() === 0) {
87
-			return;
88
-		}
89
-		$msg = $message . ' at ' . $file . '#' . $line;
90
-		self::$logger->error(self::removePassword($msg), array('app' => 'PHP'));
84
+    //Recoverable errors handler
85
+    public static function onError($number, $message, $file, $line) {
86
+        if (error_reporting() === 0) {
87
+            return;
88
+        }
89
+        $msg = $message . ' at ' . $file . '#' . $line;
90
+        self::$logger->error(self::removePassword($msg), array('app' => 'PHP'));
91 91
 
92
-	}
92
+    }
93 93
 
94
-	//Recoverable handler which catch all errors, warnings and notices
95
-	public static function onAll($number, $message, $file, $line) {
96
-		$msg = $message . ' at ' . $file . '#' . $line;
97
-		self::$logger->debug(self::removePassword($msg), array('app' => 'PHP'));
94
+    //Recoverable handler which catch all errors, warnings and notices
95
+    public static function onAll($number, $message, $file, $line) {
96
+        $msg = $message . ' at ' . $file . '#' . $line;
97
+        self::$logger->debug(self::removePassword($msg), array('app' => 'PHP'));
98 98
 
99
-	}
99
+    }
100 100
 
101 101
 }
Please login to merge, or discard this patch.
lib/private/Log/Rotate.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -31,23 +31,23 @@
 block discarded – undo
31 31
  * location and manage that with your own tools.
32 32
  */
33 33
 class Rotate extends \OC\BackgroundJob\Job {
34
-	private $max_log_size;
35
-	public function run($dummy) {
36
-		$systemConfig = \OC::$server->getSystemConfig();
37
-		$logFile = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log');
38
-		$this->max_log_size = \OC::$server->getConfig()->getSystemValue('log_rotate_size', false);
39
-		if ($this->max_log_size) {
40
-			$filesize = @filesize($logFile);
41
-			if ($filesize >= $this->max_log_size) {
42
-				$this->rotate($logFile);
43
-			}
44
-		}
45
-	}
34
+    private $max_log_size;
35
+    public function run($dummy) {
36
+        $systemConfig = \OC::$server->getSystemConfig();
37
+        $logFile = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log');
38
+        $this->max_log_size = \OC::$server->getConfig()->getSystemValue('log_rotate_size', false);
39
+        if ($this->max_log_size) {
40
+            $filesize = @filesize($logFile);
41
+            if ($filesize >= $this->max_log_size) {
42
+                $this->rotate($logFile);
43
+            }
44
+        }
45
+    }
46 46
 
47
-	protected function rotate($logfile) {
48
-		$rotatedLogfile = $logfile.'.1';
49
-		rename($logfile, $rotatedLogfile);
50
-		$msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"';
51
-		\OCP\Util::writeLog('OC\Log\Rotate', $msg, \OCP\Util::WARN);
52
-	}
47
+    protected function rotate($logfile) {
48
+        $rotatedLogfile = $logfile.'.1';
49
+        rename($logfile, $rotatedLogfile);
50
+        $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"';
51
+        \OCP\Util::writeLog('OC\Log\Rotate', $msg, \OCP\Util::WARN);
52
+    }
53 53
 }
Please login to merge, or discard this patch.
lib/private/Search.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -34,97 +34,97 @@
 block discarded – undo
34 34
  */
35 35
 class Search implements ISearch {
36 36
 
37
-	private $providers = array();
38
-	private $registeredProviders = array();
37
+    private $providers = array();
38
+    private $registeredProviders = array();
39 39
 
40
-	/**
41
-	 * Search all providers for $query
42
-	 * @param string $query
43
-	 * @param string[] $inApps optionally limit results to the given apps
44
-	 * @return array An array of OC\Search\Result's
45
-	 */
46
-	public function search($query, array $inApps = array()) {
47
-		// old apps might assume they get all results, so we set size 0
48
-		return $this->searchPaged($query, $inApps, 1, 0);
49
-	}
40
+    /**
41
+     * Search all providers for $query
42
+     * @param string $query
43
+     * @param string[] $inApps optionally limit results to the given apps
44
+     * @return array An array of OC\Search\Result's
45
+     */
46
+    public function search($query, array $inApps = array()) {
47
+        // old apps might assume they get all results, so we set size 0
48
+        return $this->searchPaged($query, $inApps, 1, 0);
49
+    }
50 50
 
51
-	/**
52
-	 * Search all providers for $query
53
-	 * @param string $query
54
-	 * @param string[] $inApps optionally limit results to the given apps
55
-	 * @param int $page pages start at page 1
56
-	 * @param int $size, 0 = all
57
-	 * @return array An array of OC\Search\Result's
58
-	 */
59
-	public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) {
60
-		$this->initProviders();
61
-		$results = array();
62
-		foreach($this->providers as $provider) {
63
-			/** @var $provider Provider */
64
-			if ( ! $provider->providesResultsFor($inApps) ) {
65
-				continue;
66
-			}
67
-			if ($provider instanceof PagedProvider) {
68
-				$results = array_merge($results, $provider->searchPaged($query, $page, $size));
69
-			} else if ($provider instanceof Provider) {
70
-				$providerResults = $provider->search($query);
71
-				if ($size > 0) {
72
-					$slicedResults = array_slice($providerResults, ($page - 1) * $size, $size);
73
-					$results = array_merge($results, $slicedResults);
74
-				} else {
75
-					$results = array_merge($results, $providerResults);
76
-				}
77
-			} else {
78
-				\OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider));
79
-			}
80
-		}
81
-		return $results;
82
-	}
51
+    /**
52
+     * Search all providers for $query
53
+     * @param string $query
54
+     * @param string[] $inApps optionally limit results to the given apps
55
+     * @param int $page pages start at page 1
56
+     * @param int $size, 0 = all
57
+     * @return array An array of OC\Search\Result's
58
+     */
59
+    public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) {
60
+        $this->initProviders();
61
+        $results = array();
62
+        foreach($this->providers as $provider) {
63
+            /** @var $provider Provider */
64
+            if ( ! $provider->providesResultsFor($inApps) ) {
65
+                continue;
66
+            }
67
+            if ($provider instanceof PagedProvider) {
68
+                $results = array_merge($results, $provider->searchPaged($query, $page, $size));
69
+            } else if ($provider instanceof Provider) {
70
+                $providerResults = $provider->search($query);
71
+                if ($size > 0) {
72
+                    $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size);
73
+                    $results = array_merge($results, $slicedResults);
74
+                } else {
75
+                    $results = array_merge($results, $providerResults);
76
+                }
77
+            } else {
78
+                \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider));
79
+            }
80
+        }
81
+        return $results;
82
+    }
83 83
 
84
-	/**
85
-	 * Remove all registered search providers
86
-	 */
87
-	public function clearProviders() {
88
-		$this->providers = array();
89
-		$this->registeredProviders = array();
90
-	}
84
+    /**
85
+     * Remove all registered search providers
86
+     */
87
+    public function clearProviders() {
88
+        $this->providers = array();
89
+        $this->registeredProviders = array();
90
+    }
91 91
 
92
-	/**
93
-	 * Remove one existing search provider
94
-	 * @param string $provider class name of a OC\Search\Provider
95
-	 */
96
-	public function removeProvider($provider) {
97
-		$this->registeredProviders = array_filter(
98
-			$this->registeredProviders,
99
-			function ($element) use ($provider) {
100
-				return ($element['class'] != $provider);
101
-			}
102
-		);
103
-		// force regeneration of providers on next search
104
-		$this->providers = array();
105
-	}
92
+    /**
93
+     * Remove one existing search provider
94
+     * @param string $provider class name of a OC\Search\Provider
95
+     */
96
+    public function removeProvider($provider) {
97
+        $this->registeredProviders = array_filter(
98
+            $this->registeredProviders,
99
+            function ($element) use ($provider) {
100
+                return ($element['class'] != $provider);
101
+            }
102
+        );
103
+        // force regeneration of providers on next search
104
+        $this->providers = array();
105
+    }
106 106
 
107
-	/**
108
-	 * Register a new search provider to search with
109
-	 * @param string $class class name of a OC\Search\Provider
110
-	 * @param array $options optional
111
-	 */
112
-	public function registerProvider($class, array $options = array()) {
113
-		$this->registeredProviders[] = array('class' => $class, 'options' => $options);
114
-	}
107
+    /**
108
+     * Register a new search provider to search with
109
+     * @param string $class class name of a OC\Search\Provider
110
+     * @param array $options optional
111
+     */
112
+    public function registerProvider($class, array $options = array()) {
113
+        $this->registeredProviders[] = array('class' => $class, 'options' => $options);
114
+    }
115 115
 
116
-	/**
117
-	 * Create instances of all the registered search providers
118
-	 */
119
-	private function initProviders() {
120
-		if( ! empty($this->providers) ) {
121
-			return;
122
-		}
123
-		foreach($this->registeredProviders as $provider) {
124
-			$class = $provider['class'];
125
-			$options = $provider['options'];
126
-			$this->providers[] = new $class($options);
127
-		}
128
-	}
116
+    /**
117
+     * Create instances of all the registered search providers
118
+     */
119
+    private function initProviders() {
120
+        if( ! empty($this->providers) ) {
121
+            return;
122
+        }
123
+        foreach($this->registeredProviders as $provider) {
124
+            $class = $provider['class'];
125
+            $options = $provider['options'];
126
+            $this->providers[] = new $class($options);
127
+        }
128
+    }
129 129
 
130 130
 }
Please login to merge, or discard this patch.
lib/private/SystemConfig.php 1 patch
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -35,126 +35,126 @@
 block discarded – undo
35 35
  */
36 36
 class SystemConfig {
37 37
 
38
-	/** @var array */
39
-	protected $sensitiveValues = [
40
-		'dbpassword' => true,
41
-		'dbuser' => true,
42
-		'mail_smtpname' => true,
43
-		'mail_smtppassword' => true,
44
-		'passwordsalt' => true,
45
-		'secret' => true,
46
-		'updater.secret' => true,
47
-		'proxyuserpwd' => true,
48
-		'log.condition' => [
49
-			'shared_secret' => true,
50
-		],
51
-		'license-key' => true,
52
-		'redis' => [
53
-			'password' => true,
54
-		],
55
-		'objectstore' => [
56
-			'arguments' => [
57
-				'password' => true,
58
-				'options' => [
59
-					'credentials' => [
60
-						'key' => true,
61
-						'secret' => true,
62
-					]
63
-				]
64
-			],
65
-		],
66
-	];
67
-
68
-	/** @var Config */
69
-	private $config;
70
-
71
-	public function __construct(Config $config) {
72
-		$this->config = $config;
73
-	}
74
-
75
-	/**
76
-	 * Lists all available config keys
77
-	 * @return array an array of key names
78
-	 */
79
-	public function getKeys() {
80
-		return $this->config->getKeys();
81
-	}
82
-
83
-	/**
84
-	 * Sets a new system wide value
85
-	 *
86
-	 * @param string $key the key of the value, under which will be saved
87
-	 * @param mixed $value the value that should be stored
88
-	 */
89
-	public function setValue($key, $value) {
90
-		$this->config->setValue($key, $value);
91
-	}
92
-
93
-	/**
94
-	 * Sets and deletes values and writes the config.php
95
-	 *
96
-	 * @param array $configs Associative array with `key => value` pairs
97
-	 *                       If value is null, the config key will be deleted
98
-	 */
99
-	public function setValues(array $configs) {
100
-		$this->config->setValues($configs);
101
-	}
102
-
103
-	/**
104
-	 * Looks up a system wide defined value
105
-	 *
106
-	 * @param string $key the key of the value, under which it was saved
107
-	 * @param mixed $default the default value to be returned if the value isn't set
108
-	 * @return mixed the value or $default
109
-	 */
110
-	public function getValue($key, $default = '') {
111
-		return $this->config->getValue($key, $default);
112
-	}
113
-
114
-	/**
115
-	 * Looks up a system wide defined value and filters out sensitive data
116
-	 *
117
-	 * @param string $key the key of the value, under which it was saved
118
-	 * @param mixed $default the default value to be returned if the value isn't set
119
-	 * @return mixed the value or $default
120
-	 */
121
-	public function getFilteredValue($key, $default = '') {
122
-		$value = $this->getValue($key, $default);
123
-
124
-		if (isset($this->sensitiveValues[$key])) {
125
-			$value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value);
126
-		}
127
-
128
-		return $value;
129
-	}
130
-
131
-	/**
132
-	 * Delete a system wide defined value
133
-	 *
134
-	 * @param string $key the key of the value, under which it was saved
135
-	 */
136
-	public function deleteValue($key) {
137
-		$this->config->deleteKey($key);
138
-	}
139
-
140
-	/**
141
-	 * @param bool|array $keysToRemove
142
-	 * @param mixed $value
143
-	 * @return mixed
144
-	 */
145
-	protected function removeSensitiveValue($keysToRemove, $value) {
146
-		if ($keysToRemove === true) {
147
-			return IConfig::SENSITIVE_VALUE;
148
-		}
149
-
150
-		if (is_array($value)) {
151
-			foreach ($keysToRemove as $keyToRemove => $valueToRemove) {
152
-				if (isset($value[$keyToRemove])) {
153
-					$value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]);
154
-				}
155
-			}
156
-		}
157
-
158
-		return $value;
159
-	}
38
+    /** @var array */
39
+    protected $sensitiveValues = [
40
+        'dbpassword' => true,
41
+        'dbuser' => true,
42
+        'mail_smtpname' => true,
43
+        'mail_smtppassword' => true,
44
+        'passwordsalt' => true,
45
+        'secret' => true,
46
+        'updater.secret' => true,
47
+        'proxyuserpwd' => true,
48
+        'log.condition' => [
49
+            'shared_secret' => true,
50
+        ],
51
+        'license-key' => true,
52
+        'redis' => [
53
+            'password' => true,
54
+        ],
55
+        'objectstore' => [
56
+            'arguments' => [
57
+                'password' => true,
58
+                'options' => [
59
+                    'credentials' => [
60
+                        'key' => true,
61
+                        'secret' => true,
62
+                    ]
63
+                ]
64
+            ],
65
+        ],
66
+    ];
67
+
68
+    /** @var Config */
69
+    private $config;
70
+
71
+    public function __construct(Config $config) {
72
+        $this->config = $config;
73
+    }
74
+
75
+    /**
76
+     * Lists all available config keys
77
+     * @return array an array of key names
78
+     */
79
+    public function getKeys() {
80
+        return $this->config->getKeys();
81
+    }
82
+
83
+    /**
84
+     * Sets a new system wide value
85
+     *
86
+     * @param string $key the key of the value, under which will be saved
87
+     * @param mixed $value the value that should be stored
88
+     */
89
+    public function setValue($key, $value) {
90
+        $this->config->setValue($key, $value);
91
+    }
92
+
93
+    /**
94
+     * Sets and deletes values and writes the config.php
95
+     *
96
+     * @param array $configs Associative array with `key => value` pairs
97
+     *                       If value is null, the config key will be deleted
98
+     */
99
+    public function setValues(array $configs) {
100
+        $this->config->setValues($configs);
101
+    }
102
+
103
+    /**
104
+     * Looks up a system wide defined value
105
+     *
106
+     * @param string $key the key of the value, under which it was saved
107
+     * @param mixed $default the default value to be returned if the value isn't set
108
+     * @return mixed the value or $default
109
+     */
110
+    public function getValue($key, $default = '') {
111
+        return $this->config->getValue($key, $default);
112
+    }
113
+
114
+    /**
115
+     * Looks up a system wide defined value and filters out sensitive data
116
+     *
117
+     * @param string $key the key of the value, under which it was saved
118
+     * @param mixed $default the default value to be returned if the value isn't set
119
+     * @return mixed the value or $default
120
+     */
121
+    public function getFilteredValue($key, $default = '') {
122
+        $value = $this->getValue($key, $default);
123
+
124
+        if (isset($this->sensitiveValues[$key])) {
125
+            $value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value);
126
+        }
127
+
128
+        return $value;
129
+    }
130
+
131
+    /**
132
+     * Delete a system wide defined value
133
+     *
134
+     * @param string $key the key of the value, under which it was saved
135
+     */
136
+    public function deleteValue($key) {
137
+        $this->config->deleteKey($key);
138
+    }
139
+
140
+    /**
141
+     * @param bool|array $keysToRemove
142
+     * @param mixed $value
143
+     * @return mixed
144
+     */
145
+    protected function removeSensitiveValue($keysToRemove, $value) {
146
+        if ($keysToRemove === true) {
147
+            return IConfig::SENSITIVE_VALUE;
148
+        }
149
+
150
+        if (is_array($value)) {
151
+            foreach ($keysToRemove as $keyToRemove => $valueToRemove) {
152
+                if (isset($value[$keyToRemove])) {
153
+                    $value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]);
154
+                }
155
+            }
156
+        }
157
+
158
+        return $value;
159
+    }
160 160
 }
Please login to merge, or discard this patch.
lib/private/L10N/L10N.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -28,190 +28,190 @@
 block discarded – undo
28 28
 
29 29
 class L10N implements IL10N {
30 30
 
31
-	/** @var IFactory */
32
-	protected $factory;
33
-
34
-	/** @var string App of this object */
35
-	protected $app;
36
-
37
-	/** @var string Language of this object */
38
-	protected $lang;
39
-
40
-	/** @var string Plural forms (string) */
41
-	private $pluralFormString = 'nplurals=2; plural=(n != 1);';
42
-
43
-	/** @var string Plural forms (function) */
44
-	private $pluralFormFunction = null;
45
-
46
-	/** @var string[] */
47
-	private $translations = [];
48
-
49
-	/**
50
-	 * @param IFactory $factory
51
-	 * @param string $app
52
-	 * @param string $lang
53
-	 * @param array $files
54
-	 */
55
-	public function __construct(IFactory $factory, $app, $lang, array $files) {
56
-		$this->factory = $factory;
57
-		$this->app = $app;
58
-		$this->lang = $lang;
59
-
60
-		$this->translations = [];
61
-		foreach ($files as $languageFile) {
62
-			$this->load($languageFile);
63
-		}
64
-	}
65
-
66
-	/**
67
-	 * The code (en, de, ...) of the language that is used for this instance
68
-	 *
69
-	 * @return string language
70
-	 */
71
-	public function getLanguageCode() {
72
-		return $this->lang;
73
-	}
74
-
75
-	/**
76
-	 * Translating
77
-	 * @param string $text The text we need a translation for
78
-	 * @param array $parameters default:array() Parameters for sprintf
79
-	 * @return string Translation or the same text
80
-	 *
81
-	 * Returns the translation. If no translation is found, $text will be
82
-	 * returned.
83
-	 */
84
-	public function t($text, $parameters = array()) {
85
-		return (string) new \OC_L10N_String($this, $text, $parameters);
86
-	}
87
-
88
-	/**
89
-	 * Translating
90
-	 * @param string $text_singular the string to translate for exactly one object
91
-	 * @param string $text_plural the string to translate for n objects
92
-	 * @param integer $count Number of objects
93
-	 * @param array $parameters default:array() Parameters for sprintf
94
-	 * @return string Translation or the same text
95
-	 *
96
-	 * Returns the translation. If no translation is found, $text will be
97
-	 * returned. %n will be replaced with the number of objects.
98
-	 *
99
-	 * The correct plural is determined by the plural_forms-function
100
-	 * provided by the po file.
101
-	 *
102
-	 */
103
-	public function n($text_singular, $text_plural, $count, $parameters = array()) {
104
-		$identifier = "_${text_singular}_::_${text_plural}_";
105
-		if (isset($this->translations[$identifier])) {
106
-			return (string) new \OC_L10N_String($this, $identifier, $parameters, $count);
107
-		} else {
108
-			if ($count === 1) {
109
-				return (string) new \OC_L10N_String($this, $text_singular, $parameters, $count);
110
-			} else {
111
-				return (string) new \OC_L10N_String($this, $text_plural, $parameters, $count);
112
-			}
113
-		}
114
-	}
115
-
116
-	/**
117
-	 * Localization
118
-	 * @param string $type Type of localization
119
-	 * @param \DateTime|int|string $data parameters for this localization
120
-	 * @param array $options
121
-	 * @return string|int|false
122
-	 *
123
-	 * Returns the localized data.
124
-	 *
125
-	 * Implemented types:
126
-	 *  - date
127
-	 *    - Creates a date
128
-	 *    - params: timestamp (int/string)
129
-	 *  - datetime
130
-	 *    - Creates date and time
131
-	 *    - params: timestamp (int/string)
132
-	 *  - time
133
-	 *    - Creates a time
134
-	 *    - params: timestamp (int/string)
135
-	 *  - firstday: Returns the first day of the week (0 sunday - 6 saturday)
136
-	 *  - jsdate: Returns the short JS date format
137
-	 */
138
-	public function l($type, $data = null, $options = array()) {
139
-		// Use the language of the instance
140
-		$locale = $this->getLanguageCode();
141
-		if ($locale === 'sr@latin') {
142
-			$locale = 'sr_latn';
143
-		}
144
-
145
-		if ($type === 'firstday') {
146
-			return (int) Calendar::getFirstWeekday($locale);
147
-		}
148
-		if ($type === 'jsdate') {
149
-			return (string) Calendar::getDateFormat('short', $locale);
150
-		}
151
-
152
-		$value = new \DateTime();
153
-		if ($data instanceof \DateTime) {
154
-			$value = $data;
155
-		} else if (is_string($data) && !is_numeric($data)) {
156
-			$data = strtotime($data);
157
-			$value->setTimestamp($data);
158
-		} else if ($data !== null) {
159
-			$value->setTimestamp($data);
160
-		}
161
-
162
-		$options = array_merge(array('width' => 'long'), $options);
163
-		$width = $options['width'];
164
-		switch ($type) {
165
-			case 'date':
166
-				return (string) Calendar::formatDate($value, $width, $locale);
167
-			case 'datetime':
168
-				return (string) Calendar::formatDatetime($value, $width, $locale);
169
-			case 'time':
170
-				return (string) Calendar::formatTime($value, $width, $locale);
171
-			default:
172
-				return false;
173
-		}
174
-	}
175
-
176
-	/**
177
-	 * Returns an associative array with all translations
178
-	 *
179
-	 * Called by \OC_L10N_String
180
-	 * @return array
181
-	 */
182
-	public function getTranslations() {
183
-		return $this->translations;
184
-	}
185
-
186
-	/**
187
-	 * Returnsed function accepts the argument $n
188
-	 *
189
-	 * Called by \OC_L10N_String
190
-	 * @return string the plural form function
191
-	 */
192
-	public function getPluralFormFunction() {
193
-		if (is_null($this->pluralFormFunction)) {
194
-			$this->pluralFormFunction = $this->factory->createPluralFunction($this->pluralFormString);
195
-		}
196
-		return $this->pluralFormFunction;
197
-	}
198
-
199
-	/**
200
-	 * @param $translationFile
201
-	 * @return bool
202
-	 */
203
-	protected function load($translationFile) {
204
-		$json = json_decode(file_get_contents($translationFile), true);
205
-		if (!is_array($json)) {
206
-			$jsonError = json_last_error();
207
-			\OC::$server->getLogger()->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']);
208
-			return false;
209
-		}
210
-
211
-		if (!empty($json['pluralForm'])) {
212
-			$this->pluralFormString = $json['pluralForm'];
213
-		}
214
-		$this->translations = array_merge($this->translations, $json['translations']);
215
-		return true;
216
-	}
31
+    /** @var IFactory */
32
+    protected $factory;
33
+
34
+    /** @var string App of this object */
35
+    protected $app;
36
+
37
+    /** @var string Language of this object */
38
+    protected $lang;
39
+
40
+    /** @var string Plural forms (string) */
41
+    private $pluralFormString = 'nplurals=2; plural=(n != 1);';
42
+
43
+    /** @var string Plural forms (function) */
44
+    private $pluralFormFunction = null;
45
+
46
+    /** @var string[] */
47
+    private $translations = [];
48
+
49
+    /**
50
+     * @param IFactory $factory
51
+     * @param string $app
52
+     * @param string $lang
53
+     * @param array $files
54
+     */
55
+    public function __construct(IFactory $factory, $app, $lang, array $files) {
56
+        $this->factory = $factory;
57
+        $this->app = $app;
58
+        $this->lang = $lang;
59
+
60
+        $this->translations = [];
61
+        foreach ($files as $languageFile) {
62
+            $this->load($languageFile);
63
+        }
64
+    }
65
+
66
+    /**
67
+     * The code (en, de, ...) of the language that is used for this instance
68
+     *
69
+     * @return string language
70
+     */
71
+    public function getLanguageCode() {
72
+        return $this->lang;
73
+    }
74
+
75
+    /**
76
+     * Translating
77
+     * @param string $text The text we need a translation for
78
+     * @param array $parameters default:array() Parameters for sprintf
79
+     * @return string Translation or the same text
80
+     *
81
+     * Returns the translation. If no translation is found, $text will be
82
+     * returned.
83
+     */
84
+    public function t($text, $parameters = array()) {
85
+        return (string) new \OC_L10N_String($this, $text, $parameters);
86
+    }
87
+
88
+    /**
89
+     * Translating
90
+     * @param string $text_singular the string to translate for exactly one object
91
+     * @param string $text_plural the string to translate for n objects
92
+     * @param integer $count Number of objects
93
+     * @param array $parameters default:array() Parameters for sprintf
94
+     * @return string Translation or the same text
95
+     *
96
+     * Returns the translation. If no translation is found, $text will be
97
+     * returned. %n will be replaced with the number of objects.
98
+     *
99
+     * The correct plural is determined by the plural_forms-function
100
+     * provided by the po file.
101
+     *
102
+     */
103
+    public function n($text_singular, $text_plural, $count, $parameters = array()) {
104
+        $identifier = "_${text_singular}_::_${text_plural}_";
105
+        if (isset($this->translations[$identifier])) {
106
+            return (string) new \OC_L10N_String($this, $identifier, $parameters, $count);
107
+        } else {
108
+            if ($count === 1) {
109
+                return (string) new \OC_L10N_String($this, $text_singular, $parameters, $count);
110
+            } else {
111
+                return (string) new \OC_L10N_String($this, $text_plural, $parameters, $count);
112
+            }
113
+        }
114
+    }
115
+
116
+    /**
117
+     * Localization
118
+     * @param string $type Type of localization
119
+     * @param \DateTime|int|string $data parameters for this localization
120
+     * @param array $options
121
+     * @return string|int|false
122
+     *
123
+     * Returns the localized data.
124
+     *
125
+     * Implemented types:
126
+     *  - date
127
+     *    - Creates a date
128
+     *    - params: timestamp (int/string)
129
+     *  - datetime
130
+     *    - Creates date and time
131
+     *    - params: timestamp (int/string)
132
+     *  - time
133
+     *    - Creates a time
134
+     *    - params: timestamp (int/string)
135
+     *  - firstday: Returns the first day of the week (0 sunday - 6 saturday)
136
+     *  - jsdate: Returns the short JS date format
137
+     */
138
+    public function l($type, $data = null, $options = array()) {
139
+        // Use the language of the instance
140
+        $locale = $this->getLanguageCode();
141
+        if ($locale === 'sr@latin') {
142
+            $locale = 'sr_latn';
143
+        }
144
+
145
+        if ($type === 'firstday') {
146
+            return (int) Calendar::getFirstWeekday($locale);
147
+        }
148
+        if ($type === 'jsdate') {
149
+            return (string) Calendar::getDateFormat('short', $locale);
150
+        }
151
+
152
+        $value = new \DateTime();
153
+        if ($data instanceof \DateTime) {
154
+            $value = $data;
155
+        } else if (is_string($data) && !is_numeric($data)) {
156
+            $data = strtotime($data);
157
+            $value->setTimestamp($data);
158
+        } else if ($data !== null) {
159
+            $value->setTimestamp($data);
160
+        }
161
+
162
+        $options = array_merge(array('width' => 'long'), $options);
163
+        $width = $options['width'];
164
+        switch ($type) {
165
+            case 'date':
166
+                return (string) Calendar::formatDate($value, $width, $locale);
167
+            case 'datetime':
168
+                return (string) Calendar::formatDatetime($value, $width, $locale);
169
+            case 'time':
170
+                return (string) Calendar::formatTime($value, $width, $locale);
171
+            default:
172
+                return false;
173
+        }
174
+    }
175
+
176
+    /**
177
+     * Returns an associative array with all translations
178
+     *
179
+     * Called by \OC_L10N_String
180
+     * @return array
181
+     */
182
+    public function getTranslations() {
183
+        return $this->translations;
184
+    }
185
+
186
+    /**
187
+     * Returnsed function accepts the argument $n
188
+     *
189
+     * Called by \OC_L10N_String
190
+     * @return string the plural form function
191
+     */
192
+    public function getPluralFormFunction() {
193
+        if (is_null($this->pluralFormFunction)) {
194
+            $this->pluralFormFunction = $this->factory->createPluralFunction($this->pluralFormString);
195
+        }
196
+        return $this->pluralFormFunction;
197
+    }
198
+
199
+    /**
200
+     * @param $translationFile
201
+     * @return bool
202
+     */
203
+    protected function load($translationFile) {
204
+        $json = json_decode(file_get_contents($translationFile), true);
205
+        if (!is_array($json)) {
206
+            $jsonError = json_last_error();
207
+            \OC::$server->getLogger()->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']);
208
+            return false;
209
+        }
210
+
211
+        if (!empty($json['pluralForm'])) {
212
+            $this->pluralFormString = $json['pluralForm'];
213
+        }
214
+        $this->translations = array_merge($this->translations, $json['translations']);
215
+        return true;
216
+    }
217 217
 }
Please login to merge, or discard this patch.