Passed
Push — master ( 22de68...e9bf19 )
by Roeland
10:44 queued 10s
created
lib/private/DB/QueryBuilder/QuoteHelper.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -27,55 +27,55 @@
 block discarded – undo
27 27
 use OCP\DB\QueryBuilder\IQueryFunction;
28 28
 
29 29
 class QuoteHelper {
30
-	/**
31
-	 * @param array|string|ILiteral|IParameter|IQueryFunction $strings string, Literal or Parameter
32
-	 * @return array|string
33
-	 */
34
-	public function quoteColumnNames($strings) {
35
-		if (!is_array($strings)) {
36
-			return $this->quoteColumnName($strings);
37
-		}
30
+    /**
31
+     * @param array|string|ILiteral|IParameter|IQueryFunction $strings string, Literal or Parameter
32
+     * @return array|string
33
+     */
34
+    public function quoteColumnNames($strings) {
35
+        if (!is_array($strings)) {
36
+            return $this->quoteColumnName($strings);
37
+        }
38 38
 
39
-		$return = [];
40
-		foreach ($strings as $string) {
41
-			$return[] = $this->quoteColumnName($string);
42
-		}
39
+        $return = [];
40
+        foreach ($strings as $string) {
41
+            $return[] = $this->quoteColumnName($string);
42
+        }
43 43
 
44
-		return $return;
45
-	}
44
+        return $return;
45
+    }
46 46
 
47
-	/**
48
-	 * @param string|ILiteral|IParameter|IQueryFunction $string string, Literal or Parameter
49
-	 * @return string
50
-	 */
51
-	public function quoteColumnName($string) {
52
-		if ($string instanceof IParameter || $string instanceof ILiteral || $string instanceof IQueryFunction) {
53
-			return (string) $string;
54
-		}
47
+    /**
48
+     * @param string|ILiteral|IParameter|IQueryFunction $string string, Literal or Parameter
49
+     * @return string
50
+     */
51
+    public function quoteColumnName($string) {
52
+        if ($string instanceof IParameter || $string instanceof ILiteral || $string instanceof IQueryFunction) {
53
+            return (string) $string;
54
+        }
55 55
 
56
-		if ($string === null || $string === 'null' || $string === '*') {
57
-			return $string;
58
-		}
56
+        if ($string === null || $string === 'null' || $string === '*') {
57
+            return $string;
58
+        }
59 59
 
60
-		if (!is_string($string)) {
61
-			throw new \InvalidArgumentException('Only strings, Literals and Parameters are allowed');
62
-		}
60
+        if (!is_string($string)) {
61
+            throw new \InvalidArgumentException('Only strings, Literals and Parameters are allowed');
62
+        }
63 63
 
64
-		$string = str_replace(' AS ', ' as ', $string);
65
-		if (substr_count($string, ' as ')) {
66
-			return implode(' as ', array_map([$this, 'quoteColumnName'], explode(' as ', $string, 2)));
67
-		}
64
+        $string = str_replace(' AS ', ' as ', $string);
65
+        if (substr_count($string, ' as ')) {
66
+            return implode(' as ', array_map([$this, 'quoteColumnName'], explode(' as ', $string, 2)));
67
+        }
68 68
 
69
-		if (substr_count($string, '.')) {
70
-			list($alias, $columnName) = explode('.', $string, 2);
69
+        if (substr_count($string, '.')) {
70
+            list($alias, $columnName) = explode('.', $string, 2);
71 71
 
72
-			if ($columnName === '*') {
73
-				return '`' . $alias . '`.*';
74
-			}
72
+            if ($columnName === '*') {
73
+                return '`' . $alias . '`.*';
74
+            }
75 75
 
76
-			return '`' . $alias . '`.`' . $columnName . '`';
77
-		}
76
+            return '`' . $alias . '`.`' . $columnName . '`';
77
+        }
78 78
 
79
-		return '`' . $string . '`';
80
-	}
79
+        return '`' . $string . '`';
80
+    }
81 81
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -70,12 +70,12 @@
 block discarded – undo
70 70
 			list($alias, $columnName) = explode('.', $string, 2);
71 71
 
72 72
 			if ($columnName === '*') {
73
-				return '`' . $alias . '`.*';
73
+				return '`'.$alias.'`.*';
74 74
 			}
75 75
 
76
-			return '`' . $alias . '`.`' . $columnName . '`';
76
+			return '`'.$alias.'`.`'.$columnName.'`';
77 77
 		}
78 78
 
79
-		return '`' . $string . '`';
79
+		return '`'.$string.'`';
80 80
 	}
81 81
 }
Please login to merge, or discard this patch.
lib/private/Route/Router.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	public function __construct(ILogger $logger) {
73 73
 		$this->logger = $logger;
74 74
 		$baseUrl = \OC::$WEBROOT;
75
-		if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
75
+		if (!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
76 76
 			$baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
77 77
 		}
78 78
 		if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) {
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 			$this->routingFiles = [];
99 99
 			foreach (\OC_APP::getEnabledApps() as $app) {
100 100
 				$appPath = \OC_App::getAppPath($app);
101
-				if($appPath !== false) {
102
-					$file = $appPath . '/appinfo/routes.php';
101
+				if ($appPath !== false) {
102
+					$file = $appPath.'/appinfo/routes.php';
103 103
 					if (file_exists($file)) {
104 104
 						$this->routingFiles[$app] = $file;
105 105
 					}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @param null|string $app
116 116
 	 */
117 117
 	public function loadRoutes($app = null) {
118
-		if(is_string($app)) {
118
+		if (is_string($app)) {
119 119
 			$app = \OC_App::cleanAppId($app);
120 120
 		}
121 121
 
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 			if (isset($this->loadedApps[$app])) {
131 131
 				return;
132 132
 			}
133
-			$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
133
+			$file = \OC_App::getAppPath($app).'/appinfo/routes.php';
134 134
 			if ($file !== false && file_exists($file)) {
135 135
 				$routingFiles = [$app => $file];
136 136
 			} else {
137 137
 				$routingFiles = [];
138 138
 			}
139 139
 		}
140
-		\OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
140
+		\OC::$server->getEventLogger()->start('loadroutes'.$requestedApp, 'Loading Routes');
141 141
 		foreach ($routingFiles as $app => $file) {
142 142
 			if (!isset($this->loadedApps[$app])) {
143 143
 				if (!\OC_App::isAppLoaded($app)) {
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 				$this->useCollection($app);
151 151
 				$this->requireRouteFile($file, $app);
152 152
 				$collection = $this->getCollection($app);
153
-				$collection->addPrefix('/apps/' . $app);
153
+				$collection->addPrefix('/apps/'.$app);
154 154
 				$this->root->addCollection($collection);
155 155
 
156 156
 				// Also add the OCS collection
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 		if (!isset($this->loadedApps['core'])) {
163 163
 			$this->loadedApps['core'] = true;
164 164
 			$this->useCollection('root');
165
-			require_once __DIR__ . '/../../../settings/routes.php';
166
-			require_once __DIR__ . '/../../../core/routes.php';
165
+			require_once __DIR__.'/../../../settings/routes.php';
166
+			require_once __DIR__.'/../../../core/routes.php';
167 167
 
168 168
 			// Also add the OCS collection
169 169
 			$collection = $this->getCollection('root.ocs');
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 			$collection->addPrefix('/ocs');
176 176
 			$this->root->addCollection($collection);
177 177
 		}
178
-		\OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
178
+		\OC::$server->getEventLogger()->end('loadroutes'.$requestedApp);
179 179
 	}
180 180
 
181 181
 	/**
@@ -246,14 +246,14 @@  discard block
 block discarded – undo
246 246
 	public function match($url) {
247 247
 		if (substr($url, 0, 6) === '/apps/') {
248 248
 			// empty string / 'apps' / $app / rest of the route
249
-			list(, , $app,) = explode('/', $url, 4);
249
+			list(,, $app,) = explode('/', $url, 4);
250 250
 
251 251
 			$app = \OC_App::cleanAppId($app);
252 252
 			\OC::$REQUESTEDAPP = $app;
253 253
 			$this->loadRoutes($app);
254 254
 		} else if (substr($url, 0, 13) === '/ocsapp/apps/') {
255 255
 			// empty string / 'ocsapp' / 'apps' / $app / rest of the route
256
-			list(, , , $app,) = explode('/', $url, 5);
256
+			list(,,, $app,) = explode('/', $url, 5);
257 257
 
258 258
 			$app = \OC_App::cleanAppId($app);
259 259
 			\OC::$REQUESTEDAPP = $app;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 				// However, since Symfony does not allow empty route names, the route
278 278
 				// we need to match is '/', so we need to append the '/' here.
279 279
 				try {
280
-					$parameters = $matcher->match($url . '/');
280
+					$parameters = $matcher->match($url.'/');
281 281
 				} catch (ResourceNotFoundException $newException) {
282 282
 					// If we still didn't match a route, we throw the original exception
283 283
 					throw $e;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		if (is_array($routes)) {
368 368
 			$appNameSpace = App::buildAppNamespace($appName);
369 369
 
370
-			$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
370
+			$applicationClassName = $appNameSpace.'\\AppInfo\\Application';
371 371
 
372 372
 			if (class_exists($applicationClassName)) {
373 373
 				$application = new $applicationClassName();
Please login to merge, or discard this patch.
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -45,337 +45,337 @@
 block discarded – undo
45 45
 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
46 46
 
47 47
 class Router implements IRouter {
48
-	/** @var RouteCollection[] */
49
-	protected $collections = [];
50
-	/** @var null|RouteCollection */
51
-	protected $collection = null;
52
-	/** @var null|string */
53
-	protected $collectionName = null;
54
-	/** @var null|RouteCollection */
55
-	protected $root = null;
56
-	/** @var null|UrlGenerator */
57
-	protected $generator = null;
58
-	/** @var string[] */
59
-	protected $routingFiles;
60
-	/** @var bool */
61
-	protected $loaded = false;
62
-	/** @var array */
63
-	protected $loadedApps = [];
64
-	/** @var ILogger */
65
-	protected $logger;
66
-	/** @var RequestContext */
67
-	protected $context;
48
+    /** @var RouteCollection[] */
49
+    protected $collections = [];
50
+    /** @var null|RouteCollection */
51
+    protected $collection = null;
52
+    /** @var null|string */
53
+    protected $collectionName = null;
54
+    /** @var null|RouteCollection */
55
+    protected $root = null;
56
+    /** @var null|UrlGenerator */
57
+    protected $generator = null;
58
+    /** @var string[] */
59
+    protected $routingFiles;
60
+    /** @var bool */
61
+    protected $loaded = false;
62
+    /** @var array */
63
+    protected $loadedApps = [];
64
+    /** @var ILogger */
65
+    protected $logger;
66
+    /** @var RequestContext */
67
+    protected $context;
68 68
 
69
-	/**
70
-	 * @param ILogger $logger
71
-	 */
72
-	public function __construct(ILogger $logger) {
73
-		$this->logger = $logger;
74
-		$baseUrl = \OC::$WEBROOT;
75
-		if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
76
-			$baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
77
-		}
78
-		if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) {
79
-			$method = $_SERVER['REQUEST_METHOD'];
80
-		} else {
81
-			$method = 'GET';
82
-		}
83
-		$request = \OC::$server->getRequest();
84
-		$host = $request->getServerHost();
85
-		$schema = $request->getServerProtocol();
86
-		$this->context = new RequestContext($baseUrl, $method, $host, $schema);
87
-		// TODO cache
88
-		$this->root = $this->getCollection('root');
89
-	}
69
+    /**
70
+     * @param ILogger $logger
71
+     */
72
+    public function __construct(ILogger $logger) {
73
+        $this->logger = $logger;
74
+        $baseUrl = \OC::$WEBROOT;
75
+        if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
76
+            $baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
77
+        }
78
+        if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) {
79
+            $method = $_SERVER['REQUEST_METHOD'];
80
+        } else {
81
+            $method = 'GET';
82
+        }
83
+        $request = \OC::$server->getRequest();
84
+        $host = $request->getServerHost();
85
+        $schema = $request->getServerProtocol();
86
+        $this->context = new RequestContext($baseUrl, $method, $host, $schema);
87
+        // TODO cache
88
+        $this->root = $this->getCollection('root');
89
+    }
90 90
 
91
-	/**
92
-	 * Get the files to load the routes from
93
-	 *
94
-	 * @return string[]
95
-	 */
96
-	public function getRoutingFiles() {
97
-		if (!isset($this->routingFiles)) {
98
-			$this->routingFiles = [];
99
-			foreach (\OC_APP::getEnabledApps() as $app) {
100
-				$appPath = \OC_App::getAppPath($app);
101
-				if($appPath !== false) {
102
-					$file = $appPath . '/appinfo/routes.php';
103
-					if (file_exists($file)) {
104
-						$this->routingFiles[$app] = $file;
105
-					}
106
-				}
107
-			}
108
-		}
109
-		return $this->routingFiles;
110
-	}
91
+    /**
92
+     * Get the files to load the routes from
93
+     *
94
+     * @return string[]
95
+     */
96
+    public function getRoutingFiles() {
97
+        if (!isset($this->routingFiles)) {
98
+            $this->routingFiles = [];
99
+            foreach (\OC_APP::getEnabledApps() as $app) {
100
+                $appPath = \OC_App::getAppPath($app);
101
+                if($appPath !== false) {
102
+                    $file = $appPath . '/appinfo/routes.php';
103
+                    if (file_exists($file)) {
104
+                        $this->routingFiles[$app] = $file;
105
+                    }
106
+                }
107
+            }
108
+        }
109
+        return $this->routingFiles;
110
+    }
111 111
 
112
-	/**
113
-	 * Loads the routes
114
-	 *
115
-	 * @param null|string $app
116
-	 */
117
-	public function loadRoutes($app = null) {
118
-		if(is_string($app)) {
119
-			$app = \OC_App::cleanAppId($app);
120
-		}
112
+    /**
113
+     * Loads the routes
114
+     *
115
+     * @param null|string $app
116
+     */
117
+    public function loadRoutes($app = null) {
118
+        if(is_string($app)) {
119
+            $app = \OC_App::cleanAppId($app);
120
+        }
121 121
 
122
-		$requestedApp = $app;
123
-		if ($this->loaded) {
124
-			return;
125
-		}
126
-		if (is_null($app)) {
127
-			$this->loaded = true;
128
-			$routingFiles = $this->getRoutingFiles();
129
-		} else {
130
-			if (isset($this->loadedApps[$app])) {
131
-				return;
132
-			}
133
-			$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
134
-			if ($file !== false && file_exists($file)) {
135
-				$routingFiles = [$app => $file];
136
-			} else {
137
-				$routingFiles = [];
138
-			}
139
-		}
140
-		\OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
141
-		foreach ($routingFiles as $app => $file) {
142
-			if (!isset($this->loadedApps[$app])) {
143
-				if (!\OC_App::isAppLoaded($app)) {
144
-					// app MUST be loaded before app routes
145
-					// try again next time loadRoutes() is called
146
-					$this->loaded = false;
147
-					continue;
148
-				}
149
-				$this->loadedApps[$app] = true;
150
-				$this->useCollection($app);
151
-				$this->requireRouteFile($file, $app);
152
-				$collection = $this->getCollection($app);
153
-				$collection->addPrefix('/apps/' . $app);
154
-				$this->root->addCollection($collection);
122
+        $requestedApp = $app;
123
+        if ($this->loaded) {
124
+            return;
125
+        }
126
+        if (is_null($app)) {
127
+            $this->loaded = true;
128
+            $routingFiles = $this->getRoutingFiles();
129
+        } else {
130
+            if (isset($this->loadedApps[$app])) {
131
+                return;
132
+            }
133
+            $file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
134
+            if ($file !== false && file_exists($file)) {
135
+                $routingFiles = [$app => $file];
136
+            } else {
137
+                $routingFiles = [];
138
+            }
139
+        }
140
+        \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
141
+        foreach ($routingFiles as $app => $file) {
142
+            if (!isset($this->loadedApps[$app])) {
143
+                if (!\OC_App::isAppLoaded($app)) {
144
+                    // app MUST be loaded before app routes
145
+                    // try again next time loadRoutes() is called
146
+                    $this->loaded = false;
147
+                    continue;
148
+                }
149
+                $this->loadedApps[$app] = true;
150
+                $this->useCollection($app);
151
+                $this->requireRouteFile($file, $app);
152
+                $collection = $this->getCollection($app);
153
+                $collection->addPrefix('/apps/' . $app);
154
+                $this->root->addCollection($collection);
155 155
 
156
-				// Also add the OCS collection
157
-				$collection = $this->getCollection($app.'.ocs');
158
-				$collection->addPrefix('/ocsapp');
159
-				$this->root->addCollection($collection);
160
-			}
161
-		}
162
-		if (!isset($this->loadedApps['core'])) {
163
-			$this->loadedApps['core'] = true;
164
-			$this->useCollection('root');
165
-			require_once __DIR__ . '/../../../settings/routes.php';
166
-			require_once __DIR__ . '/../../../core/routes.php';
156
+                // Also add the OCS collection
157
+                $collection = $this->getCollection($app.'.ocs');
158
+                $collection->addPrefix('/ocsapp');
159
+                $this->root->addCollection($collection);
160
+            }
161
+        }
162
+        if (!isset($this->loadedApps['core'])) {
163
+            $this->loadedApps['core'] = true;
164
+            $this->useCollection('root');
165
+            require_once __DIR__ . '/../../../settings/routes.php';
166
+            require_once __DIR__ . '/../../../core/routes.php';
167 167
 
168
-			// Also add the OCS collection
169
-			$collection = $this->getCollection('root.ocs');
170
-			$collection->addPrefix('/ocsapp');
171
-			$this->root->addCollection($collection);
172
-		}
173
-		if ($this->loaded) {
174
-			$collection = $this->getCollection('ocs');
175
-			$collection->addPrefix('/ocs');
176
-			$this->root->addCollection($collection);
177
-		}
178
-		\OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
179
-	}
168
+            // Also add the OCS collection
169
+            $collection = $this->getCollection('root.ocs');
170
+            $collection->addPrefix('/ocsapp');
171
+            $this->root->addCollection($collection);
172
+        }
173
+        if ($this->loaded) {
174
+            $collection = $this->getCollection('ocs');
175
+            $collection->addPrefix('/ocs');
176
+            $this->root->addCollection($collection);
177
+        }
178
+        \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
179
+    }
180 180
 
181
-	/**
182
-	 * @return string
183
-	 * @deprecated
184
-	 */
185
-	public function getCacheKey() {
186
-		return '';
187
-	}
181
+    /**
182
+     * @return string
183
+     * @deprecated
184
+     */
185
+    public function getCacheKey() {
186
+        return '';
187
+    }
188 188
 
189
-	/**
190
-	 * @param string $name
191
-	 * @return \Symfony\Component\Routing\RouteCollection
192
-	 */
193
-	protected function getCollection($name) {
194
-		if (!isset($this->collections[$name])) {
195
-			$this->collections[$name] = new RouteCollection();
196
-		}
197
-		return $this->collections[$name];
198
-	}
189
+    /**
190
+     * @param string $name
191
+     * @return \Symfony\Component\Routing\RouteCollection
192
+     */
193
+    protected function getCollection($name) {
194
+        if (!isset($this->collections[$name])) {
195
+            $this->collections[$name] = new RouteCollection();
196
+        }
197
+        return $this->collections[$name];
198
+    }
199 199
 
200
-	/**
201
-	 * Sets the collection to use for adding routes
202
-	 *
203
-	 * @param string $name Name of the collection to use.
204
-	 * @return void
205
-	 */
206
-	public function useCollection($name) {
207
-		$this->collection = $this->getCollection($name);
208
-		$this->collectionName = $name;
209
-	}
200
+    /**
201
+     * Sets the collection to use for adding routes
202
+     *
203
+     * @param string $name Name of the collection to use.
204
+     * @return void
205
+     */
206
+    public function useCollection($name) {
207
+        $this->collection = $this->getCollection($name);
208
+        $this->collectionName = $name;
209
+    }
210 210
 
211
-	/**
212
-	 * returns the current collection name in use for adding routes
213
-	 *
214
-	 * @return string the collection name
215
-	 */
216
-	public function getCurrentCollection() {
217
-		return $this->collectionName;
218
-	}
211
+    /**
212
+     * returns the current collection name in use for adding routes
213
+     *
214
+     * @return string the collection name
215
+     */
216
+    public function getCurrentCollection() {
217
+        return $this->collectionName;
218
+    }
219 219
 
220 220
 
221
-	/**
222
-	 * Create a \OC\Route\Route.
223
-	 *
224
-	 * @param string $name Name of the route to create.
225
-	 * @param string $pattern The pattern to match
226
-	 * @param array $defaults An array of default parameter values
227
-	 * @param array $requirements An array of requirements for parameters (regexes)
228
-	 * @return \OC\Route\Route
229
-	 */
230
-	public function create($name,
231
-						   $pattern,
232
-						   array $defaults = [],
233
-						   array $requirements = []) {
234
-		$route = new Route($pattern, $defaults, $requirements);
235
-		$this->collection->add($name, $route);
236
-		return $route;
237
-	}
221
+    /**
222
+     * Create a \OC\Route\Route.
223
+     *
224
+     * @param string $name Name of the route to create.
225
+     * @param string $pattern The pattern to match
226
+     * @param array $defaults An array of default parameter values
227
+     * @param array $requirements An array of requirements for parameters (regexes)
228
+     * @return \OC\Route\Route
229
+     */
230
+    public function create($name,
231
+                            $pattern,
232
+                            array $defaults = [],
233
+                            array $requirements = []) {
234
+        $route = new Route($pattern, $defaults, $requirements);
235
+        $this->collection->add($name, $route);
236
+        return $route;
237
+    }
238 238
 
239
-	/**
240
-	 * Find the route matching $url
241
-	 *
242
-	 * @param string $url The url to find
243
-	 * @throws \Exception
244
-	 * @return void
245
-	 */
246
-	public function match($url) {
247
-		if (substr($url, 0, 6) === '/apps/') {
248
-			// empty string / 'apps' / $app / rest of the route
249
-			list(, , $app,) = explode('/', $url, 4);
239
+    /**
240
+     * Find the route matching $url
241
+     *
242
+     * @param string $url The url to find
243
+     * @throws \Exception
244
+     * @return void
245
+     */
246
+    public function match($url) {
247
+        if (substr($url, 0, 6) === '/apps/') {
248
+            // empty string / 'apps' / $app / rest of the route
249
+            list(, , $app,) = explode('/', $url, 4);
250 250
 
251
-			$app = \OC_App::cleanAppId($app);
252
-			\OC::$REQUESTEDAPP = $app;
253
-			$this->loadRoutes($app);
254
-		} else if (substr($url, 0, 13) === '/ocsapp/apps/') {
255
-			// empty string / 'ocsapp' / 'apps' / $app / rest of the route
256
-			list(, , , $app,) = explode('/', $url, 5);
251
+            $app = \OC_App::cleanAppId($app);
252
+            \OC::$REQUESTEDAPP = $app;
253
+            $this->loadRoutes($app);
254
+        } else if (substr($url, 0, 13) === '/ocsapp/apps/') {
255
+            // empty string / 'ocsapp' / 'apps' / $app / rest of the route
256
+            list(, , , $app,) = explode('/', $url, 5);
257 257
 
258
-			$app = \OC_App::cleanAppId($app);
259
-			\OC::$REQUESTEDAPP = $app;
260
-			$this->loadRoutes($app);
261
-		} else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
262
-			\OC::$REQUESTEDAPP = $url;
263
-			if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
264
-				\OC_App::loadApps();
265
-			}
266
-			$this->loadRoutes('core');
267
-		} else {
268
-			$this->loadRoutes();
269
-		}
258
+            $app = \OC_App::cleanAppId($app);
259
+            \OC::$REQUESTEDAPP = $app;
260
+            $this->loadRoutes($app);
261
+        } else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
262
+            \OC::$REQUESTEDAPP = $url;
263
+            if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
264
+                \OC_App::loadApps();
265
+            }
266
+            $this->loadRoutes('core');
267
+        } else {
268
+            $this->loadRoutes();
269
+        }
270 270
 
271
-		$matcher = new UrlMatcher($this->root, $this->context);
272
-		try {
273
-			$parameters = $matcher->match($url);
274
-		} catch (ResourceNotFoundException $e) {
275
-			if (substr($url, -1) !== '/') {
276
-				// We allow links to apps/files? for backwards compatibility reasons
277
-				// However, since Symfony does not allow empty route names, the route
278
-				// we need to match is '/', so we need to append the '/' here.
279
-				try {
280
-					$parameters = $matcher->match($url . '/');
281
-				} catch (ResourceNotFoundException $newException) {
282
-					// If we still didn't match a route, we throw the original exception
283
-					throw $e;
284
-				}
285
-			} else {
286
-				throw $e;
287
-			}
288
-		}
271
+        $matcher = new UrlMatcher($this->root, $this->context);
272
+        try {
273
+            $parameters = $matcher->match($url);
274
+        } catch (ResourceNotFoundException $e) {
275
+            if (substr($url, -1) !== '/') {
276
+                // We allow links to apps/files? for backwards compatibility reasons
277
+                // However, since Symfony does not allow empty route names, the route
278
+                // we need to match is '/', so we need to append the '/' here.
279
+                try {
280
+                    $parameters = $matcher->match($url . '/');
281
+                } catch (ResourceNotFoundException $newException) {
282
+                    // If we still didn't match a route, we throw the original exception
283
+                    throw $e;
284
+                }
285
+            } else {
286
+                throw $e;
287
+            }
288
+        }
289 289
 
290
-		\OC::$server->getEventLogger()->start('run_route', 'Run route');
291
-		if (isset($parameters['action'])) {
292
-			$action = $parameters['action'];
293
-			if (!is_callable($action)) {
294
-				throw new \Exception('not a callable action');
295
-			}
296
-			unset($parameters['action']);
297
-			call_user_func($action, $parameters);
298
-		} elseif (isset($parameters['file'])) {
299
-			include $parameters['file'];
300
-		} else {
301
-			throw new \Exception('no action available');
302
-		}
303
-		\OC::$server->getEventLogger()->end('run_route');
304
-	}
290
+        \OC::$server->getEventLogger()->start('run_route', 'Run route');
291
+        if (isset($parameters['action'])) {
292
+            $action = $parameters['action'];
293
+            if (!is_callable($action)) {
294
+                throw new \Exception('not a callable action');
295
+            }
296
+            unset($parameters['action']);
297
+            call_user_func($action, $parameters);
298
+        } elseif (isset($parameters['file'])) {
299
+            include $parameters['file'];
300
+        } else {
301
+            throw new \Exception('no action available');
302
+        }
303
+        \OC::$server->getEventLogger()->end('run_route');
304
+    }
305 305
 
306
-	/**
307
-	 * Get the url generator
308
-	 *
309
-	 * @return \Symfony\Component\Routing\Generator\UrlGenerator
310
-	 *
311
-	 */
312
-	public function getGenerator() {
313
-		if (null !== $this->generator) {
314
-			return $this->generator;
315
-		}
306
+    /**
307
+     * Get the url generator
308
+     *
309
+     * @return \Symfony\Component\Routing\Generator\UrlGenerator
310
+     *
311
+     */
312
+    public function getGenerator() {
313
+        if (null !== $this->generator) {
314
+            return $this->generator;
315
+        }
316 316
 
317
-		return $this->generator = new UrlGenerator($this->root, $this->context);
318
-	}
317
+        return $this->generator = new UrlGenerator($this->root, $this->context);
318
+    }
319 319
 
320
-	/**
321
-	 * Generate url based on $name and $parameters
322
-	 *
323
-	 * @param string $name Name of the route to use.
324
-	 * @param array $parameters Parameters for the route
325
-	 * @param bool $absolute
326
-	 * @return string
327
-	 */
328
-	public function generate($name,
329
-							 $parameters = [],
330
-							 $absolute = false) {
331
-		$this->loadRoutes();
332
-		try {
333
-			$referenceType = UrlGenerator::ABSOLUTE_URL;
334
-			if ($absolute === false) {
335
-				$referenceType = UrlGenerator::ABSOLUTE_PATH;
336
-			}
337
-			return $this->getGenerator()->generate($name, $parameters, $referenceType);
338
-		} catch (RouteNotFoundException $e) {
339
-			$this->logger->logException($e);
340
-			return '';
341
-		}
342
-	}
320
+    /**
321
+     * Generate url based on $name and $parameters
322
+     *
323
+     * @param string $name Name of the route to use.
324
+     * @param array $parameters Parameters for the route
325
+     * @param bool $absolute
326
+     * @return string
327
+     */
328
+    public function generate($name,
329
+                                $parameters = [],
330
+                                $absolute = false) {
331
+        $this->loadRoutes();
332
+        try {
333
+            $referenceType = UrlGenerator::ABSOLUTE_URL;
334
+            if ($absolute === false) {
335
+                $referenceType = UrlGenerator::ABSOLUTE_PATH;
336
+            }
337
+            return $this->getGenerator()->generate($name, $parameters, $referenceType);
338
+        } catch (RouteNotFoundException $e) {
339
+            $this->logger->logException($e);
340
+            return '';
341
+        }
342
+    }
343 343
 
344
-	/**
345
-	 * To isolate the variable scope used inside the $file it is required in it's own method
346
-	 *
347
-	 * @param string $file the route file location to include
348
-	 * @param string $appName
349
-	 */
350
-	private function requireRouteFile($file, $appName) {
351
-		$this->setupRoutes(include_once $file, $appName);
352
-	}
344
+    /**
345
+     * To isolate the variable scope used inside the $file it is required in it's own method
346
+     *
347
+     * @param string $file the route file location to include
348
+     * @param string $appName
349
+     */
350
+    private function requireRouteFile($file, $appName) {
351
+        $this->setupRoutes(include_once $file, $appName);
352
+    }
353 353
 
354 354
 
355
-	/**
356
-	 * If a routes.php file returns an array, try to set up the application and
357
-	 * register the routes for the app. The application class will be chosen by
358
-	 * camelcasing the appname, e.g.: my_app will be turned into
359
-	 * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default
360
-	 * App will be intialized. This makes it optional to ship an
361
-	 * appinfo/application.php by using the built in query resolver
362
-	 *
363
-	 * @param array $routes the application routes
364
-	 * @param string $appName the name of the app.
365
-	 */
366
-	private function setupRoutes($routes, $appName) {
367
-		if (is_array($routes)) {
368
-			$appNameSpace = App::buildAppNamespace($appName);
355
+    /**
356
+     * If a routes.php file returns an array, try to set up the application and
357
+     * register the routes for the app. The application class will be chosen by
358
+     * camelcasing the appname, e.g.: my_app will be turned into
359
+     * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default
360
+     * App will be intialized. This makes it optional to ship an
361
+     * appinfo/application.php by using the built in query resolver
362
+     *
363
+     * @param array $routes the application routes
364
+     * @param string $appName the name of the app.
365
+     */
366
+    private function setupRoutes($routes, $appName) {
367
+        if (is_array($routes)) {
368
+            $appNameSpace = App::buildAppNamespace($appName);
369 369
 
370
-			$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
370
+            $applicationClassName = $appNameSpace . '\\AppInfo\\Application';
371 371
 
372
-			if (class_exists($applicationClassName)) {
373
-				$application = new $applicationClassName();
374
-			} else {
375
-				$application = new App($appName);
376
-			}
372
+            if (class_exists($applicationClassName)) {
373
+                $application = new $applicationClassName();
374
+            } else {
375
+                $application = new App($appName);
376
+            }
377 377
 
378
-			$application->registerRoutes($this, $routes);
379
-		}
380
-	}
378
+            $application->registerRoutes($this, $routes);
379
+        }
380
+    }
381 381
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/RemoteController.php 2 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -34,156 +34,156 @@
 block discarded – undo
34 34
 
35 35
 class RemoteController extends OCSController {
36 36
 
37
-	/** @var Manager */
38
-	private $externalManager;
39
-
40
-	/** @var ILogger */
41
-	private $logger;
42
-
43
-	/**
44
-	 * @NoAdminRequired
45
-	 *
46
-	 * Remote constructor.
47
-	 *
48
-	 * @param string $appName
49
-	 * @param IRequest $request
50
-	 * @param Manager $externalManager
51
-	 */
52
-	public function __construct($appName,
53
-								IRequest $request,
54
-								Manager $externalManager,
55
-								ILogger $logger) {
56
-		parent::__construct($appName, $request);
57
-
58
-		$this->externalManager = $externalManager;
59
-		$this->logger = $logger;
60
-	}
61
-
62
-	/**
63
-	 * @NoAdminRequired
64
-	 *
65
-	 * Get list of pending remote shares
66
-	 *
67
-	 * @return DataResponse
68
-	 */
69
-	public function getOpenShares() {
70
-		return new DataResponse($this->externalManager->getOpenShares());
71
-	}
72
-
73
-	/**
74
-	 * @NoAdminRequired
75
-	 *
76
-	 * Accept a remote share
77
-	 *
78
-	 * @param int $id
79
-	 * @return DataResponse
80
-	 * @throws OCSNotFoundException
81
-	 */
82
-	public function acceptShare($id) {
83
-		if ($this->externalManager->acceptShare($id)) {
84
-			return new DataResponse();
85
-		}
86
-
87
-		$this->logger->error('Could not accept federated share with id: ' . $id,
88
-			['app' => 'files_sharing']);
89
-
90
-		throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
91
-	}
92
-
93
-	/**
94
-	 * @NoAdminRequired
95
-	 *
96
-	 * Decline a remote share
97
-	 *
98
-	 * @param int $id
99
-	 * @return DataResponse
100
-	 * @throws OCSNotFoundException
101
-	 */
102
-	public function declineShare($id) {
103
-		if ($this->externalManager->declineShare($id)) {
104
-			return new DataResponse();
105
-		}
106
-
107
-		// Make sure the user has no notification for something that does not exist anymore.
108
-		$this->externalManager->processNotification($id);
109
-
110
-		throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
111
-	}
112
-
113
-	/**
114
-	 * @param array $share Share with info from the share_external table
115
-	 * @return array enriched share info with data from the filecache
116
-	 */
117
-	private static function extendShareInfo($share) {
118
-		$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
119
-		$info = $view->getFileInfo($share['mountpoint']);
120
-
121
-		$share['mimetype'] = $info->getMimetype();
122
-		$share['mtime'] = $info->getMTime();
123
-		$share['permissions'] = $info->getPermissions();
124
-		$share['type'] = $info->getType();
125
-		$share['file_id'] = $info->getId();
126
-
127
-		return $share;
128
-	}
129
-
130
-	/**
131
-	 * @NoAdminRequired
132
-	 *
133
-	 * List accepted remote shares
134
-	 *
135
-	 * @return DataResponse
136
-	 */
137
-	public function getShares() {
138
-		$shares = $this->externalManager->getAcceptedShares();
139
-		$shares = array_map('self::extendShareInfo', $shares);
140
-
141
-		return new DataResponse($shares);
142
-	}
143
-
144
-	/**
145
-	 * @NoAdminRequired
146
-	 *
147
-	 * Get info of a remote share
148
-	 *
149
-	 * @param int $id
150
-	 * @return DataResponse
151
-	 * @throws OCSNotFoundException
152
-	 */
153
-	public function getShare($id) {
154
-		$shareInfo = $this->externalManager->getShare($id);
155
-
156
-		if ($shareInfo === false) {
157
-			throw new OCSNotFoundException('share does not exist');
158
-		} else {
159
-			$shareInfo = self::extendShareInfo($shareInfo);
160
-			return new DataResponse($shareInfo);
161
-		}
162
-	}
163
-
164
-	/**
165
-	 * @NoAdminRequired
166
-	 *
167
-	 * Unshare a remote share
168
-	 *
169
-	 * @param int $id
170
-	 * @return DataResponse
171
-	 * @throws OCSNotFoundException
172
-	 * @throws OCSForbiddenException
173
-	 */
174
-	public function unshare($id) {
175
-		$shareInfo = $this->externalManager->getShare($id);
176
-
177
-		if ($shareInfo === false) {
178
-			throw new OCSNotFoundException('Share does not exist');
179
-		}
180
-
181
-		$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
182
-
183
-		if ($this->externalManager->removeShare($mountPoint) === true) {
184
-			return new DataResponse();
185
-		} else {
186
-			throw new OCSForbiddenException('Could not unshare');
187
-		}
188
-	}
37
+    /** @var Manager */
38
+    private $externalManager;
39
+
40
+    /** @var ILogger */
41
+    private $logger;
42
+
43
+    /**
44
+     * @NoAdminRequired
45
+     *
46
+     * Remote constructor.
47
+     *
48
+     * @param string $appName
49
+     * @param IRequest $request
50
+     * @param Manager $externalManager
51
+     */
52
+    public function __construct($appName,
53
+                                IRequest $request,
54
+                                Manager $externalManager,
55
+                                ILogger $logger) {
56
+        parent::__construct($appName, $request);
57
+
58
+        $this->externalManager = $externalManager;
59
+        $this->logger = $logger;
60
+    }
61
+
62
+    /**
63
+     * @NoAdminRequired
64
+     *
65
+     * Get list of pending remote shares
66
+     *
67
+     * @return DataResponse
68
+     */
69
+    public function getOpenShares() {
70
+        return new DataResponse($this->externalManager->getOpenShares());
71
+    }
72
+
73
+    /**
74
+     * @NoAdminRequired
75
+     *
76
+     * Accept a remote share
77
+     *
78
+     * @param int $id
79
+     * @return DataResponse
80
+     * @throws OCSNotFoundException
81
+     */
82
+    public function acceptShare($id) {
83
+        if ($this->externalManager->acceptShare($id)) {
84
+            return new DataResponse();
85
+        }
86
+
87
+        $this->logger->error('Could not accept federated share with id: ' . $id,
88
+            ['app' => 'files_sharing']);
89
+
90
+        throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
91
+    }
92
+
93
+    /**
94
+     * @NoAdminRequired
95
+     *
96
+     * Decline a remote share
97
+     *
98
+     * @param int $id
99
+     * @return DataResponse
100
+     * @throws OCSNotFoundException
101
+     */
102
+    public function declineShare($id) {
103
+        if ($this->externalManager->declineShare($id)) {
104
+            return new DataResponse();
105
+        }
106
+
107
+        // Make sure the user has no notification for something that does not exist anymore.
108
+        $this->externalManager->processNotification($id);
109
+
110
+        throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
111
+    }
112
+
113
+    /**
114
+     * @param array $share Share with info from the share_external table
115
+     * @return array enriched share info with data from the filecache
116
+     */
117
+    private static function extendShareInfo($share) {
118
+        $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
119
+        $info = $view->getFileInfo($share['mountpoint']);
120
+
121
+        $share['mimetype'] = $info->getMimetype();
122
+        $share['mtime'] = $info->getMTime();
123
+        $share['permissions'] = $info->getPermissions();
124
+        $share['type'] = $info->getType();
125
+        $share['file_id'] = $info->getId();
126
+
127
+        return $share;
128
+    }
129
+
130
+    /**
131
+     * @NoAdminRequired
132
+     *
133
+     * List accepted remote shares
134
+     *
135
+     * @return DataResponse
136
+     */
137
+    public function getShares() {
138
+        $shares = $this->externalManager->getAcceptedShares();
139
+        $shares = array_map('self::extendShareInfo', $shares);
140
+
141
+        return new DataResponse($shares);
142
+    }
143
+
144
+    /**
145
+     * @NoAdminRequired
146
+     *
147
+     * Get info of a remote share
148
+     *
149
+     * @param int $id
150
+     * @return DataResponse
151
+     * @throws OCSNotFoundException
152
+     */
153
+    public function getShare($id) {
154
+        $shareInfo = $this->externalManager->getShare($id);
155
+
156
+        if ($shareInfo === false) {
157
+            throw new OCSNotFoundException('share does not exist');
158
+        } else {
159
+            $shareInfo = self::extendShareInfo($shareInfo);
160
+            return new DataResponse($shareInfo);
161
+        }
162
+    }
163
+
164
+    /**
165
+     * @NoAdminRequired
166
+     *
167
+     * Unshare a remote share
168
+     *
169
+     * @param int $id
170
+     * @return DataResponse
171
+     * @throws OCSNotFoundException
172
+     * @throws OCSForbiddenException
173
+     */
174
+    public function unshare($id) {
175
+        $shareInfo = $this->externalManager->getShare($id);
176
+
177
+        if ($shareInfo === false) {
178
+            throw new OCSNotFoundException('Share does not exist');
179
+        }
180
+
181
+        $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
182
+
183
+        if ($this->externalManager->removeShare($mountPoint) === true) {
184
+            return new DataResponse();
185
+        } else {
186
+            throw new OCSForbiddenException('Could not unshare');
187
+        }
188
+    }
189 189
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 			return new DataResponse();
85 85
 		}
86 86
 
87
-		$this->logger->error('Could not accept federated share with id: ' . $id,
87
+		$this->logger->error('Could not accept federated share with id: '.$id,
88 88
 			['app' => 'files_sharing']);
89 89
 
90 90
 		throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @return array enriched share info with data from the filecache
116 116
 	 */
117 117
 	private static function extendShareInfo($share) {
118
-		$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
118
+		$view = new \OC\Files\View('/'.\OC_User::getUser().'/files/');
119 119
 		$info = $view->getFileInfo($share['mountpoint']);
120 120
 
121 121
 		$share['mimetype'] = $info->getMimetype();
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 			throw new OCSNotFoundException('Share does not exist');
179 179
 		}
180 180
 
181
-		$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
181
+		$mountPoint = '/'.\OC_User::getUser().'/files'.$shareInfo['mountpoint'];
182 182
 
183 183
 		if ($this->externalManager->removeShare($mountPoint) === true) {
184 184
 			return new DataResponse();
Please login to merge, or discard this patch.
apps/testing/lib/AppInfo/Application.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -25,18 +25,18 @@
 block discarded – undo
25 25
 use OCA\Testing\AlternativeHomeUserBackend;
26 26
 
27 27
 class Application extends App {
28
-	public function __construct (array $urlParams = array()) {
29
-		$appName = 'testing';
30
-		parent::__construct($appName, $urlParams);
28
+    public function __construct (array $urlParams = array()) {
29
+        $appName = 'testing';
30
+        parent::__construct($appName, $urlParams);
31 31
 
32
-		$c = $this->getContainer();
33
-		$config = $c->getServer()->getConfig();
34
-		if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') {
35
-			$userManager = $c->getServer()->getUserManager();
32
+        $c = $this->getContainer();
33
+        $config = $c->getServer()->getConfig();
34
+        if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') {
35
+            $userManager = $c->getServer()->getUserManager();
36 36
 
37
-			// replace all user backends with this one
38
-			$userManager->clearBackends();
39
-			$userManager->registerBackend($c->query(AlternativeHomeUserBackend::class));
40
-		}
41
-	}
37
+            // replace all user backends with this one
38
+            $userManager->clearBackends();
39
+            $userManager->registerBackend($c->query(AlternativeHomeUserBackend::class));
40
+        }
41
+    }
42 42
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 use OCA\Testing\AlternativeHomeUserBackend;
26 26
 
27 27
 class Application extends App {
28
-	public function __construct (array $urlParams = array()) {
28
+	public function __construct(array $urlParams = array()) {
29 29
 		$appName = 'testing';
30 30
 		parent::__construct($appName, $urlParams);
31 31
 
Please login to merge, or discard this patch.
apps/testing/lib/Controller/ConfigController.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,39 +29,39 @@
 block discarded – undo
29 29
 
30 30
 class ConfigController extends OCSController {
31 31
 
32
-	/** @var IConfig */
33
-	private $config;
32
+    /** @var IConfig */
33
+    private $config;
34 34
 
35
-	/**
36
-	 * @param string $appName
37
-	 * @param IRequest $request
38
-	 * @param IConfig $config
39
-	 */
40
-	public function __construct($appName,
41
-								IRequest $request,
42
-								IConfig $config) {
43
-		parent::__construct($appName, $request);
44
-		$this->config = $config;
45
-	}
35
+    /**
36
+     * @param string $appName
37
+     * @param IRequest $request
38
+     * @param IConfig $config
39
+     */
40
+    public function __construct($appName,
41
+                                IRequest $request,
42
+                                IConfig $config) {
43
+        parent::__construct($appName, $request);
44
+        $this->config = $config;
45
+    }
46 46
 
47
-	/**
48
-	 * @param string $appid
49
-	 * @param string $configkey
50
-	 * @param string $value
51
-	 * @return DataResponse
52
-	 */
53
-	public function setAppValue($appid, $configkey, $value) {
54
-		$this->config->setAppValue($appid, $configkey, $value);
55
-		return new DataResponse();
56
-	}
47
+    /**
48
+     * @param string $appid
49
+     * @param string $configkey
50
+     * @param string $value
51
+     * @return DataResponse
52
+     */
53
+    public function setAppValue($appid, $configkey, $value) {
54
+        $this->config->setAppValue($appid, $configkey, $value);
55
+        return new DataResponse();
56
+    }
57 57
 
58
-	/**
59
-	 * @param string $appid
60
-	 * @param string $configkey
61
-	 * @return DataResponse
62
-	 */
63
-	public function deleteAppValue($appid, $configkey) {
64
-		$this->config->deleteAppValue($appid, $configkey);
65
-		return new DataResponse();
66
-	}
58
+    /**
59
+     * @param string $appid
60
+     * @param string $configkey
61
+     * @return DataResponse
62
+     */
63
+    public function deleteAppValue($appid, $configkey) {
64
+        $this->config->deleteAppValue($appid, $configkey);
65
+        return new DataResponse();
66
+    }
67 67
 }
Please login to merge, or discard this patch.
apps/testing/lib/Controller/LockingController.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -39,208 +39,208 @@
 block discarded – undo
39 39
 
40 40
 class LockingController extends OCSController {
41 41
 
42
-	/** @var ILockingProvider */
43
-	protected $lockingProvider;
44
-
45
-	/** @var FakeDBLockingProvider */
46
-	protected $fakeDBLockingProvider;
47
-
48
-	/** @var IDBConnection */
49
-	protected $connection;
50
-
51
-	/** @var IConfig */
52
-	protected $config;
53
-
54
-	/** @var IRootFolder */
55
-	protected $rootFolder;
56
-
57
-	/**
58
-	 * @param string $appName
59
-	 * @param IRequest $request
60
-	 * @param ILockingProvider $lockingProvider
61
-	 * @param FakeDBLockingProvider $fakeDBLockingProvider
62
-	 * @param IDBConnection $connection
63
-	 * @param IConfig $config
64
-	 * @param IRootFolder $rootFolder
65
-	 */
66
-	public function __construct($appName,
67
-								IRequest $request,
68
-								ILockingProvider $lockingProvider,
69
-								FakeDBLockingProvider $fakeDBLockingProvider,
70
-								IDBConnection $connection,
71
-								IConfig $config,
72
-								IRootFolder $rootFolder) {
73
-		parent::__construct($appName, $request);
74
-
75
-		$this->lockingProvider = $lockingProvider;
76
-		$this->fakeDBLockingProvider = $fakeDBLockingProvider;
77
-		$this->connection = $connection;
78
-		$this->config = $config;
79
-		$this->rootFolder = $rootFolder;
80
-	}
81
-
82
-	/**
83
-	 * @return ILockingProvider
84
-	 * @throws \RuntimeException
85
-	 */
86
-	protected function getLockingProvider() {
87
-		if ($this->lockingProvider instanceof DBLockingProvider) {
88
-			return $this->fakeDBLockingProvider;
89
-		}
90
-		throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
91
-	}
92
-
93
-	/**
94
-	 * @param string $user
95
-	 * @param string $path
96
-	 * @return string
97
-	 * @throws NotFoundException
98
-	 */
99
-	protected function getPath($user, $path) {
100
-		$node = $this->rootFolder->getUserFolder($user)->get($path);
101
-		return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
102
-	}
103
-
104
-	/**
105
-	 * @return DataResponse
106
-	 * @throws OCSException
107
-	 */
108
-	public function isLockingEnabled() {
109
-		try {
110
-			$this->getLockingProvider();
111
-			return new DataResponse();
112
-		} catch (\RuntimeException $e) {
113
-			throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e);
114
-		}
115
-	}
116
-
117
-	/**
118
-	 * @param int $type
119
-	 * @param string $user
120
-	 * @param string $path
121
-	 * @return DataResponse
122
-	 * @throws OCSException
123
-	 */
124
-	public function acquireLock($type, $user, $path) {
125
-		try {
126
-			$path = $this->getPath($user, $path);
127
-		} catch (NoUserException $e) {
128
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
129
-		} catch (NotFoundException $e) {
130
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
131
-		}
132
-
133
-		$lockingProvider = $this->getLockingProvider();
134
-
135
-		try {
136
-			$lockingProvider->acquireLock($path, $type);
137
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
138
-			return new DataResponse();
139
-		} catch (LockedException $e) {
140
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
141
-		}
142
-	}
143
-
144
-	/**
145
-	 * @param int $type
146
-	 * @param string $user
147
-	 * @param string $path
148
-	 * @return DataResponse
149
-	 * @throws OCSException
150
-	 */
151
-	public function changeLock($type, $user, $path) {
152
-		try {
153
-			$path = $this->getPath($user, $path);
154
-		} catch (NoUserException $e) {
155
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
156
-		} catch (NotFoundException $e) {
157
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
158
-		}
159
-
160
-		$lockingProvider = $this->getLockingProvider();
161
-
162
-		try {
163
-			$lockingProvider->changeLock($path, $type);
164
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
165
-			return new DataResponse();
166
-		} catch (LockedException $e) {
167
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
168
-		}
169
-	}
170
-
171
-	/**
172
-	 * @param int $type
173
-	 * @param string $user
174
-	 * @param string $path
175
-	 * @return DataResponse
176
-	 * @throws OCSException
177
-	 */
178
-	public function releaseLock($type, $user, $path) {
179
-		try {
180
-			$path = $this->getPath($user, $path);
181
-		} catch (NoUserException $e) {
182
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
183
-		} catch (NotFoundException $e) {
184
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
185
-		}
186
-
187
-		$lockingProvider = $this->getLockingProvider();
188
-
189
-		try {
190
-			$lockingProvider->releaseLock($path, $type);
191
-			$this->config->deleteAppValue('testing', 'locking_' . $path);
192
-			return new DataResponse();
193
-		} catch (LockedException $e) {
194
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
195
-		}
196
-	}
197
-
198
-	/**
199
-	 * @param int $type
200
-	 * @param string $user
201
-	 * @param string $path
202
-	 * @return DataResponse
203
-	 * @throws OCSException
204
-	 */
205
-	public function isLocked($type, $user, $path) {
206
-		try {
207
-			$path = $this->getPath($user, $path);
208
-		} catch (NoUserException $e) {
209
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
210
-		} catch (NotFoundException $e) {
211
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
212
-		}
213
-
214
-		$lockingProvider = $this->getLockingProvider();
215
-
216
-		if ($lockingProvider->isLocked($path, $type)) {
217
-			return new DataResponse();
218
-		}
219
-
220
-		throw new OCSException('', Http::STATUS_LOCKED);
221
-	}
222
-
223
-	/**
224
-	 * @param int $type
225
-	 * @return DataResponse
226
-	 */
227
-	public function releaseAll($type = null) {
228
-		$lockingProvider = $this->getLockingProvider();
229
-
230
-		foreach ($this->config->getAppKeys('testing') as $lock) {
231
-			if (strpos($lock, 'locking_') === 0) {
232
-				$path = substr($lock, strlen('locking_'));
233
-
234
-				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
-				} else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238
-				} else {
239
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
240
-				}
241
-			}
242
-		}
243
-
244
-		return new DataResponse();
245
-	}
42
+    /** @var ILockingProvider */
43
+    protected $lockingProvider;
44
+
45
+    /** @var FakeDBLockingProvider */
46
+    protected $fakeDBLockingProvider;
47
+
48
+    /** @var IDBConnection */
49
+    protected $connection;
50
+
51
+    /** @var IConfig */
52
+    protected $config;
53
+
54
+    /** @var IRootFolder */
55
+    protected $rootFolder;
56
+
57
+    /**
58
+     * @param string $appName
59
+     * @param IRequest $request
60
+     * @param ILockingProvider $lockingProvider
61
+     * @param FakeDBLockingProvider $fakeDBLockingProvider
62
+     * @param IDBConnection $connection
63
+     * @param IConfig $config
64
+     * @param IRootFolder $rootFolder
65
+     */
66
+    public function __construct($appName,
67
+                                IRequest $request,
68
+                                ILockingProvider $lockingProvider,
69
+                                FakeDBLockingProvider $fakeDBLockingProvider,
70
+                                IDBConnection $connection,
71
+                                IConfig $config,
72
+                                IRootFolder $rootFolder) {
73
+        parent::__construct($appName, $request);
74
+
75
+        $this->lockingProvider = $lockingProvider;
76
+        $this->fakeDBLockingProvider = $fakeDBLockingProvider;
77
+        $this->connection = $connection;
78
+        $this->config = $config;
79
+        $this->rootFolder = $rootFolder;
80
+    }
81
+
82
+    /**
83
+     * @return ILockingProvider
84
+     * @throws \RuntimeException
85
+     */
86
+    protected function getLockingProvider() {
87
+        if ($this->lockingProvider instanceof DBLockingProvider) {
88
+            return $this->fakeDBLockingProvider;
89
+        }
90
+        throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
91
+    }
92
+
93
+    /**
94
+     * @param string $user
95
+     * @param string $path
96
+     * @return string
97
+     * @throws NotFoundException
98
+     */
99
+    protected function getPath($user, $path) {
100
+        $node = $this->rootFolder->getUserFolder($user)->get($path);
101
+        return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
102
+    }
103
+
104
+    /**
105
+     * @return DataResponse
106
+     * @throws OCSException
107
+     */
108
+    public function isLockingEnabled() {
109
+        try {
110
+            $this->getLockingProvider();
111
+            return new DataResponse();
112
+        } catch (\RuntimeException $e) {
113
+            throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e);
114
+        }
115
+    }
116
+
117
+    /**
118
+     * @param int $type
119
+     * @param string $user
120
+     * @param string $path
121
+     * @return DataResponse
122
+     * @throws OCSException
123
+     */
124
+    public function acquireLock($type, $user, $path) {
125
+        try {
126
+            $path = $this->getPath($user, $path);
127
+        } catch (NoUserException $e) {
128
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
129
+        } catch (NotFoundException $e) {
130
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
131
+        }
132
+
133
+        $lockingProvider = $this->getLockingProvider();
134
+
135
+        try {
136
+            $lockingProvider->acquireLock($path, $type);
137
+            $this->config->setAppValue('testing', 'locking_' . $path, $type);
138
+            return new DataResponse();
139
+        } catch (LockedException $e) {
140
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
141
+        }
142
+    }
143
+
144
+    /**
145
+     * @param int $type
146
+     * @param string $user
147
+     * @param string $path
148
+     * @return DataResponse
149
+     * @throws OCSException
150
+     */
151
+    public function changeLock($type, $user, $path) {
152
+        try {
153
+            $path = $this->getPath($user, $path);
154
+        } catch (NoUserException $e) {
155
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
156
+        } catch (NotFoundException $e) {
157
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
158
+        }
159
+
160
+        $lockingProvider = $this->getLockingProvider();
161
+
162
+        try {
163
+            $lockingProvider->changeLock($path, $type);
164
+            $this->config->setAppValue('testing', 'locking_' . $path, $type);
165
+            return new DataResponse();
166
+        } catch (LockedException $e) {
167
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
168
+        }
169
+    }
170
+
171
+    /**
172
+     * @param int $type
173
+     * @param string $user
174
+     * @param string $path
175
+     * @return DataResponse
176
+     * @throws OCSException
177
+     */
178
+    public function releaseLock($type, $user, $path) {
179
+        try {
180
+            $path = $this->getPath($user, $path);
181
+        } catch (NoUserException $e) {
182
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
183
+        } catch (NotFoundException $e) {
184
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
185
+        }
186
+
187
+        $lockingProvider = $this->getLockingProvider();
188
+
189
+        try {
190
+            $lockingProvider->releaseLock($path, $type);
191
+            $this->config->deleteAppValue('testing', 'locking_' . $path);
192
+            return new DataResponse();
193
+        } catch (LockedException $e) {
194
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
195
+        }
196
+    }
197
+
198
+    /**
199
+     * @param int $type
200
+     * @param string $user
201
+     * @param string $path
202
+     * @return DataResponse
203
+     * @throws OCSException
204
+     */
205
+    public function isLocked($type, $user, $path) {
206
+        try {
207
+            $path = $this->getPath($user, $path);
208
+        } catch (NoUserException $e) {
209
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
210
+        } catch (NotFoundException $e) {
211
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
212
+        }
213
+
214
+        $lockingProvider = $this->getLockingProvider();
215
+
216
+        if ($lockingProvider->isLocked($path, $type)) {
217
+            return new DataResponse();
218
+        }
219
+
220
+        throw new OCSException('', Http::STATUS_LOCKED);
221
+    }
222
+
223
+    /**
224
+     * @param int $type
225
+     * @return DataResponse
226
+     */
227
+    public function releaseAll($type = null) {
228
+        $lockingProvider = $this->getLockingProvider();
229
+
230
+        foreach ($this->config->getAppKeys('testing') as $lock) {
231
+            if (strpos($lock, 'locking_') === 0) {
232
+                $path = substr($lock, strlen('locking_'));
233
+
234
+                if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
+                } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238
+                } else {
239
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
240
+                }
241
+            }
242
+        }
243
+
244
+        return new DataResponse();
245
+    }
246 246
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	protected function getPath($user, $path) {
100 100
 		$node = $this->rootFolder->getUserFolder($user)->get($path);
101
-		return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
101
+		return 'files/'.md5($node->getStorage()->getId().'::'.trim($node->getInternalPath(), '/'));
102 102
 	}
103 103
 
104 104
 	/**
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 		try {
136 136
 			$lockingProvider->acquireLock($path, $type);
137
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
137
+			$this->config->setAppValue('testing', 'locking_'.$path, $type);
138 138
 			return new DataResponse();
139 139
 		} catch (LockedException $e) {
140 140
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 
162 162
 		try {
163 163
 			$lockingProvider->changeLock($path, $type);
164
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
164
+			$this->config->setAppValue('testing', 'locking_'.$path, $type);
165 165
 			return new DataResponse();
166 166
 		} catch (LockedException $e) {
167 167
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		try {
190 190
 			$lockingProvider->releaseLock($path, $type);
191
-			$this->config->deleteAppValue('testing', 'locking_' . $path);
191
+			$this->config->deleteAppValue('testing', 'locking_'.$path);
192 192
 			return new DataResponse();
193 193
 		} catch (LockedException $e) {
194 194
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 			if (strpos($lock, 'locking_') === 0) {
232 232
 				$path = substr($lock, strlen('locking_'));
233 233
 
234
-				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
234
+				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235 235
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
-				} else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
236
+				} else if ($type === ILockingProvider::LOCK_SHARED && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237 237
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238 238
 				} else {
239 239
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/ICallbackResponse.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@
 block discarded – undo
33 33
  */
34 34
 interface ICallbackResponse {
35 35
 
36
-	/**
37
-	 * Outputs the content that should be printed
38
-	 *
39
-	 * @param IOutput $output a small wrapper that handles output
40
-	 * @since 8.1.0
41
-	 */
42
-	public function callback(IOutput $output);
36
+    /**
37
+     * Outputs the content that should be printed
38
+     *
39
+     * @param IOutput $output a small wrapper that handles output
40
+     * @since 8.1.0
41
+     */
42
+    public function callback(IOutput $output);
43 43
 
44 44
 }
Please login to merge, or discard this patch.
lib/private/Security/TrustedDomainHelper.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -32,68 +32,68 @@
 block discarded – undo
32 32
  * @package OC\Security
33 33
  */
34 34
 class TrustedDomainHelper {
35
-	/** @var IConfig */
36
-	private $config;
35
+    /** @var IConfig */
36
+    private $config;
37 37
 
38
-	/**
39
-	 * @param IConfig $config
40
-	 */
41
-	public function __construct(IConfig $config) {
42
-		$this->config = $config;
43
-	}
38
+    /**
39
+     * @param IConfig $config
40
+     */
41
+    public function __construct(IConfig $config) {
42
+        $this->config = $config;
43
+    }
44 44
 
45
-	/**
46
-	 * Strips a potential port from a domain (in format domain:port)
47
-	 * @param string $host
48
-	 * @return string $host without appended port
49
-	 */
50
-	private function getDomainWithoutPort($host) {
51
-		$pos = strrpos($host, ':');
52
-		if ($pos !== false) {
53
-			$port = substr($host, $pos + 1);
54
-			if (is_numeric($port)) {
55
-				$host = substr($host, 0, $pos);
56
-			}
57
-		}
58
-		return $host;
59
-	}
45
+    /**
46
+     * Strips a potential port from a domain (in format domain:port)
47
+     * @param string $host
48
+     * @return string $host without appended port
49
+     */
50
+    private function getDomainWithoutPort($host) {
51
+        $pos = strrpos($host, ':');
52
+        if ($pos !== false) {
53
+            $port = substr($host, $pos + 1);
54
+            if (is_numeric($port)) {
55
+                $host = substr($host, 0, $pos);
56
+            }
57
+        }
58
+        return $host;
59
+    }
60 60
 
61
-	/**
62
-	 * Checks whether a domain is considered as trusted from the list
63
-	 * of trusted domains. If no trusted domains have been configured, returns
64
-	 * true.
65
-	 * This is used to prevent Host Header Poisoning.
66
-	 * @param string $domainWithPort
67
-	 * @return bool true if the given domain is trusted or if no trusted domains
68
-	 * have been configured
69
-	 */
70
-	public function isTrustedDomain($domainWithPort) {
71
-		$domain = $this->getDomainWithoutPort($domainWithPort);
61
+    /**
62
+     * Checks whether a domain is considered as trusted from the list
63
+     * of trusted domains. If no trusted domains have been configured, returns
64
+     * true.
65
+     * This is used to prevent Host Header Poisoning.
66
+     * @param string $domainWithPort
67
+     * @return bool true if the given domain is trusted or if no trusted domains
68
+     * have been configured
69
+     */
70
+    public function isTrustedDomain($domainWithPort) {
71
+        $domain = $this->getDomainWithoutPort($domainWithPort);
72 72
 
73
-		// Read trusted domains from config
74
-		$trustedList = $this->config->getSystemValue('trusted_domains', []);
75
-		if (!is_array($trustedList)) {
76
-			return false;
77
-		}
73
+        // Read trusted domains from config
74
+        $trustedList = $this->config->getSystemValue('trusted_domains', []);
75
+        if (!is_array($trustedList)) {
76
+            return false;
77
+        }
78 78
 
79
-		// Always allow access from localhost
80
-		if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) {
81
-			return true;
82
-		}
83
-		// Reject misformed domains in any case
84
-		if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
85
-			return false;
86
-		}
87
-		// Match, allowing for * wildcards
88
-		foreach ($trustedList as $trusted) {
89
-			if (gettype($trusted) !== 'string') {
90
-				break;
91
-			}
92
-			$regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/';
93
-			if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
94
- 				return true;
95
- 			}
96
- 		}
97
- 		return false;
98
-	}
79
+        // Always allow access from localhost
80
+        if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) {
81
+            return true;
82
+        }
83
+        // Reject misformed domains in any case
84
+        if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
85
+            return false;
86
+        }
87
+        // Match, allowing for * wildcards
88
+        foreach ($trustedList as $trusted) {
89
+            if (gettype($trusted) !== 'string') {
90
+                break;
91
+            }
92
+            $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/';
93
+            if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
94
+                    return true;
95
+                }
96
+            }
97
+            return false;
98
+    }
99 99
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			return true;
82 82
 		}
83 83
 		// Reject misformed domains in any case
84
-		if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
84
+		if (strpos($domain, '-') === 0 || strpos($domain, '..') !== false) {
85 85
 			return false;
86 86
 		}
87 87
 		// Match, allowing for * wildcards
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 			if (gettype($trusted) !== 'string') {
90 90
 				break;
91 91
 			}
92
-			$regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/';
92
+			$regex = '/^'.implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))).'$/';
93 93
 			if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
94 94
  				return true;
95 95
  			}
Please login to merge, or discard this patch.
lib/private/Memcache/Memcached.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -33,193 +33,193 @@
 block discarded – undo
33 33
 use OCP\IMemcache;
34 34
 
35 35
 class Memcached extends Cache implements IMemcache {
36
-	use CASTrait;
37
-
38
-	/**
39
-	 * @var \Memcached $cache
40
-	 */
41
-	private static $cache = null;
42
-
43
-	use CADTrait;
44
-
45
-	public function __construct($prefix = '') {
46
-		parent::__construct($prefix);
47
-		if (is_null(self::$cache)) {
48
-			self::$cache = new \Memcached();
49
-
50
-			$defaultOptions = [
51
-				\Memcached::OPT_CONNECT_TIMEOUT => 50,
52
-				\Memcached::OPT_RETRY_TIMEOUT =>   50,
53
-				\Memcached::OPT_SEND_TIMEOUT =>    50,
54
-				\Memcached::OPT_RECV_TIMEOUT =>    50,
55
-				\Memcached::OPT_POLL_TIMEOUT =>    50,
56
-
57
-				// Enable compression
58
-				\Memcached::OPT_COMPRESSION =>          true,
59
-
60
-				// Turn on consistent hashing
61
-				\Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
62
-
63
-				// Enable Binary Protocol
64
-				//\Memcached::OPT_BINARY_PROTOCOL =>      true,
65
-			];
66
-			// by default enable igbinary serializer if available
67
-			if (\Memcached::HAVE_IGBINARY) {
68
-				$defaultOptions[\Memcached::OPT_SERIALIZER] =
69
-					\Memcached::SERIALIZER_IGBINARY;
70
-			}
71
-			$options = \OC::$server->getConfig()->getSystemValue('memcached_options', []);
72
-			if (is_array($options)) {
73
-				$options = $options + $defaultOptions;
74
-				self::$cache->setOptions($options);
75
-			} else {
76
-				throw new HintException("Expected 'memcached_options' config to be an array, got $options");
77
-			}
78
-
79
-			$servers = \OC::$server->getSystemConfig()->getValue('memcached_servers');
80
-			if (!$servers) {
81
-				$server = \OC::$server->getSystemConfig()->getValue('memcached_server');
82
-				if ($server) {
83
-					$servers = [$server];
84
-				} else {
85
-					$servers = [['localhost', 11211]];
86
-				}
87
-			}
88
-			self::$cache->addServers($servers);
89
-		}
90
-	}
91
-
92
-	/**
93
-	 * entries in XCache gets namespaced to prevent collisions between owncloud instances and users
94
-	 */
95
-	protected function getNameSpace() {
96
-		return $this->prefix;
97
-	}
98
-
99
-	public function get($key) {
100
-		$result = self::$cache->get($this->getNameSpace() . $key);
101
-		if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) {
102
-			return null;
103
-		} else {
104
-			return $result;
105
-		}
106
-	}
107
-
108
-	public function set($key, $value, $ttl = 0) {
109
-		if ($ttl > 0) {
110
-			$result =  self::$cache->set($this->getNameSpace() . $key, $value, $ttl);
111
-		} else {
112
-			$result = self::$cache->set($this->getNameSpace() . $key, $value);
113
-		}
114
-		if ($result !== true) {
115
-			$this->verifyReturnCode();
116
-		}
117
-		return $result;
118
-	}
119
-
120
-	public function hasKey($key) {
121
-		self::$cache->get($this->getNameSpace() . $key);
122
-		return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
123
-	}
124
-
125
-	public function remove($key) {
126
-		$result= self::$cache->delete($this->getNameSpace() . $key);
127
-		if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
128
-			$this->verifyReturnCode();
129
-		}
130
-		return $result;
131
-	}
132
-
133
-	public function clear($prefix = '') {
134
-		$prefix = $this->getNameSpace() . $prefix;
135
-		$allKeys = self::$cache->getAllKeys();
136
-		if ($allKeys === false) {
137
-			// newer Memcached doesn't like getAllKeys(), flush everything
138
-			self::$cache->flush();
139
-			return true;
140
-		}
141
-		$keys = array();
142
-		$prefixLength = strlen($prefix);
143
-		foreach ($allKeys as $key) {
144
-			if (substr($key, 0, $prefixLength) === $prefix) {
145
-				$keys[] = $key;
146
-			}
147
-		}
148
-		if (method_exists(self::$cache, 'deleteMulti')) {
149
-			self::$cache->deleteMulti($keys);
150
-		} else {
151
-			foreach ($keys as $key) {
152
-				self::$cache->delete($key);
153
-			}
154
-		}
155
-		return true;
156
-	}
157
-
158
-	/**
159
-	 * Set a value in the cache if it's not already stored
160
-	 *
161
-	 * @param string $key
162
-	 * @param mixed $value
163
-	 * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
164
-	 * @return bool
165
-	 * @throws \Exception
166
-	 */
167
-	public function add($key, $value, $ttl = 0) {
168
-		$result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
169
-		if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
170
-			$this->verifyReturnCode();
171
-		}
172
-		return $result;
173
-	}
174
-
175
-	/**
176
-	 * Increase a stored number
177
-	 *
178
-	 * @param string $key
179
-	 * @param int $step
180
-	 * @return int | bool
181
-	 */
182
-	public function inc($key, $step = 1) {
183
-		$this->add($key, 0);
184
-		$result = self::$cache->increment($this->getPrefix() . $key, $step);
185
-
186
-		if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
187
-			return false;
188
-		}
189
-
190
-		return $result;
191
-	}
192
-
193
-	/**
194
-	 * Decrease a stored number
195
-	 *
196
-	 * @param string $key
197
-	 * @param int $step
198
-	 * @return int | bool
199
-	 */
200
-	public function dec($key, $step = 1) {
201
-		$result = self::$cache->decrement($this->getPrefix() . $key, $step);
202
-
203
-		if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
204
-			return false;
205
-		}
206
-
207
-		return $result;
208
-	}
209
-
210
-	static public function isAvailable() {
211
-		return extension_loaded('memcached');
212
-	}
213
-
214
-	/**
215
-	 * @throws \Exception
216
-	 */
217
-	private function verifyReturnCode() {
218
-		$code = self::$cache->getResultCode();
219
-		if ($code === \Memcached::RES_SUCCESS) {
220
-			return;
221
-		}
222
-		$message = self::$cache->getResultMessage();
223
-		throw new \Exception("Error $code interacting with memcached : $message");
224
-	}
36
+    use CASTrait;
37
+
38
+    /**
39
+     * @var \Memcached $cache
40
+     */
41
+    private static $cache = null;
42
+
43
+    use CADTrait;
44
+
45
+    public function __construct($prefix = '') {
46
+        parent::__construct($prefix);
47
+        if (is_null(self::$cache)) {
48
+            self::$cache = new \Memcached();
49
+
50
+            $defaultOptions = [
51
+                \Memcached::OPT_CONNECT_TIMEOUT => 50,
52
+                \Memcached::OPT_RETRY_TIMEOUT =>   50,
53
+                \Memcached::OPT_SEND_TIMEOUT =>    50,
54
+                \Memcached::OPT_RECV_TIMEOUT =>    50,
55
+                \Memcached::OPT_POLL_TIMEOUT =>    50,
56
+
57
+                // Enable compression
58
+                \Memcached::OPT_COMPRESSION =>          true,
59
+
60
+                // Turn on consistent hashing
61
+                \Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
62
+
63
+                // Enable Binary Protocol
64
+                //\Memcached::OPT_BINARY_PROTOCOL =>      true,
65
+            ];
66
+            // by default enable igbinary serializer if available
67
+            if (\Memcached::HAVE_IGBINARY) {
68
+                $defaultOptions[\Memcached::OPT_SERIALIZER] =
69
+                    \Memcached::SERIALIZER_IGBINARY;
70
+            }
71
+            $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []);
72
+            if (is_array($options)) {
73
+                $options = $options + $defaultOptions;
74
+                self::$cache->setOptions($options);
75
+            } else {
76
+                throw new HintException("Expected 'memcached_options' config to be an array, got $options");
77
+            }
78
+
79
+            $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers');
80
+            if (!$servers) {
81
+                $server = \OC::$server->getSystemConfig()->getValue('memcached_server');
82
+                if ($server) {
83
+                    $servers = [$server];
84
+                } else {
85
+                    $servers = [['localhost', 11211]];
86
+                }
87
+            }
88
+            self::$cache->addServers($servers);
89
+        }
90
+    }
91
+
92
+    /**
93
+     * entries in XCache gets namespaced to prevent collisions between owncloud instances and users
94
+     */
95
+    protected function getNameSpace() {
96
+        return $this->prefix;
97
+    }
98
+
99
+    public function get($key) {
100
+        $result = self::$cache->get($this->getNameSpace() . $key);
101
+        if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) {
102
+            return null;
103
+        } else {
104
+            return $result;
105
+        }
106
+    }
107
+
108
+    public function set($key, $value, $ttl = 0) {
109
+        if ($ttl > 0) {
110
+            $result =  self::$cache->set($this->getNameSpace() . $key, $value, $ttl);
111
+        } else {
112
+            $result = self::$cache->set($this->getNameSpace() . $key, $value);
113
+        }
114
+        if ($result !== true) {
115
+            $this->verifyReturnCode();
116
+        }
117
+        return $result;
118
+    }
119
+
120
+    public function hasKey($key) {
121
+        self::$cache->get($this->getNameSpace() . $key);
122
+        return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
123
+    }
124
+
125
+    public function remove($key) {
126
+        $result= self::$cache->delete($this->getNameSpace() . $key);
127
+        if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
128
+            $this->verifyReturnCode();
129
+        }
130
+        return $result;
131
+    }
132
+
133
+    public function clear($prefix = '') {
134
+        $prefix = $this->getNameSpace() . $prefix;
135
+        $allKeys = self::$cache->getAllKeys();
136
+        if ($allKeys === false) {
137
+            // newer Memcached doesn't like getAllKeys(), flush everything
138
+            self::$cache->flush();
139
+            return true;
140
+        }
141
+        $keys = array();
142
+        $prefixLength = strlen($prefix);
143
+        foreach ($allKeys as $key) {
144
+            if (substr($key, 0, $prefixLength) === $prefix) {
145
+                $keys[] = $key;
146
+            }
147
+        }
148
+        if (method_exists(self::$cache, 'deleteMulti')) {
149
+            self::$cache->deleteMulti($keys);
150
+        } else {
151
+            foreach ($keys as $key) {
152
+                self::$cache->delete($key);
153
+            }
154
+        }
155
+        return true;
156
+    }
157
+
158
+    /**
159
+     * Set a value in the cache if it's not already stored
160
+     *
161
+     * @param string $key
162
+     * @param mixed $value
163
+     * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
164
+     * @return bool
165
+     * @throws \Exception
166
+     */
167
+    public function add($key, $value, $ttl = 0) {
168
+        $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
169
+        if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
170
+            $this->verifyReturnCode();
171
+        }
172
+        return $result;
173
+    }
174
+
175
+    /**
176
+     * Increase a stored number
177
+     *
178
+     * @param string $key
179
+     * @param int $step
180
+     * @return int | bool
181
+     */
182
+    public function inc($key, $step = 1) {
183
+        $this->add($key, 0);
184
+        $result = self::$cache->increment($this->getPrefix() . $key, $step);
185
+
186
+        if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
187
+            return false;
188
+        }
189
+
190
+        return $result;
191
+    }
192
+
193
+    /**
194
+     * Decrease a stored number
195
+     *
196
+     * @param string $key
197
+     * @param int $step
198
+     * @return int | bool
199
+     */
200
+    public function dec($key, $step = 1) {
201
+        $result = self::$cache->decrement($this->getPrefix() . $key, $step);
202
+
203
+        if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
204
+            return false;
205
+        }
206
+
207
+        return $result;
208
+    }
209
+
210
+    static public function isAvailable() {
211
+        return extension_loaded('memcached');
212
+    }
213
+
214
+    /**
215
+     * @throws \Exception
216
+     */
217
+    private function verifyReturnCode() {
218
+        $code = self::$cache->getResultCode();
219
+        if ($code === \Memcached::RES_SUCCESS) {
220
+            return;
221
+        }
222
+        $message = self::$cache->getResultMessage();
223
+        throw new \Exception("Error $code interacting with memcached : $message");
224
+    }
225 225
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 
99 99
 	public function get($key) {
100
-		$result = self::$cache->get($this->getNameSpace() . $key);
100
+		$result = self::$cache->get($this->getNameSpace().$key);
101 101
 		if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) {
102 102
 			return null;
103 103
 		} else {
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 
108 108
 	public function set($key, $value, $ttl = 0) {
109 109
 		if ($ttl > 0) {
110
-			$result =  self::$cache->set($this->getNameSpace() . $key, $value, $ttl);
110
+			$result = self::$cache->set($this->getNameSpace().$key, $value, $ttl);
111 111
 		} else {
112
-			$result = self::$cache->set($this->getNameSpace() . $key, $value);
112
+			$result = self::$cache->set($this->getNameSpace().$key, $value);
113 113
 		}
114 114
 		if ($result !== true) {
115 115
 			$this->verifyReturnCode();
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 	}
119 119
 
120 120
 	public function hasKey($key) {
121
-		self::$cache->get($this->getNameSpace() . $key);
121
+		self::$cache->get($this->getNameSpace().$key);
122 122
 		return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
123 123
 	}
124 124
 
125 125
 	public function remove($key) {
126
-		$result= self::$cache->delete($this->getNameSpace() . $key);
126
+		$result = self::$cache->delete($this->getNameSpace().$key);
127 127
 		if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
128 128
 			$this->verifyReturnCode();
129 129
 		}
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	}
132 132
 
133 133
 	public function clear($prefix = '') {
134
-		$prefix = $this->getNameSpace() . $prefix;
134
+		$prefix = $this->getNameSpace().$prefix;
135 135
 		$allKeys = self::$cache->getAllKeys();
136 136
 		if ($allKeys === false) {
137 137
 			// newer Memcached doesn't like getAllKeys(), flush everything
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @throws \Exception
166 166
 	 */
167 167
 	public function add($key, $value, $ttl = 0) {
168
-		$result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
168
+		$result = self::$cache->add($this->getPrefix().$key, $value, $ttl);
169 169
 		if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
170 170
 			$this->verifyReturnCode();
171 171
 		}
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 */
182 182
 	public function inc($key, $step = 1) {
183 183
 		$this->add($key, 0);
184
-		$result = self::$cache->increment($this->getPrefix() . $key, $step);
184
+		$result = self::$cache->increment($this->getPrefix().$key, $step);
185 185
 
186 186
 		if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
187 187
 			return false;
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 * @return int | bool
199 199
 	 */
200 200
 	public function dec($key, $step = 1) {
201
-		$result = self::$cache->decrement($this->getPrefix() . $key, $step);
201
+		$result = self::$cache->decrement($this->getPrefix().$key, $step);
202 202
 
203 203
 		if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
204 204
 			return false;
Please login to merge, or discard this patch.