Completed
Pull Request — master (#6921)
by Morris
32:09 queued 19:08
created
lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
 	 * @param bool $isLoggedIn
103 103
 	 * @param bool $isAdminUser
104 104
 	 * @param ContentSecurityPolicyManager $contentSecurityPolicyManager
105
-	 * @param CSRFTokenManager $csrfTokenManager
105
+	 * @param CsrfTokenManager $csrfTokenManager
106 106
 	 * @param ContentSecurityPolicyNonceManager $cspNonceManager
107 107
 	 * @param IAppManager $appManager
108 108
 	 */
Please login to merge, or discard this patch.
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -64,211 +64,211 @@
 block discarded – undo
64 64
  * check fails
65 65
  */
66 66
 class SecurityMiddleware extends Middleware {
67
-	/** @var INavigationManager */
68
-	private $navigationManager;
69
-	/** @var IRequest */
70
-	private $request;
71
-	/** @var ControllerMethodReflector */
72
-	private $reflector;
73
-	/** @var string */
74
-	private $appName;
75
-	/** @var IURLGenerator */
76
-	private $urlGenerator;
77
-	/** @var ILogger */
78
-	private $logger;
79
-	/** @var ISession */
80
-	private $session;
81
-	/** @var bool */
82
-	private $isLoggedIn;
83
-	/** @var bool */
84
-	private $isAdminUser;
85
-	/** @var ContentSecurityPolicyManager */
86
-	private $contentSecurityPolicyManager;
87
-	/** @var CsrfTokenManager */
88
-	private $csrfTokenManager;
89
-	/** @var ContentSecurityPolicyNonceManager */
90
-	private $cspNonceManager;
91
-	/** @var IAppManager */
92
-	private $appManager;
67
+    /** @var INavigationManager */
68
+    private $navigationManager;
69
+    /** @var IRequest */
70
+    private $request;
71
+    /** @var ControllerMethodReflector */
72
+    private $reflector;
73
+    /** @var string */
74
+    private $appName;
75
+    /** @var IURLGenerator */
76
+    private $urlGenerator;
77
+    /** @var ILogger */
78
+    private $logger;
79
+    /** @var ISession */
80
+    private $session;
81
+    /** @var bool */
82
+    private $isLoggedIn;
83
+    /** @var bool */
84
+    private $isAdminUser;
85
+    /** @var ContentSecurityPolicyManager */
86
+    private $contentSecurityPolicyManager;
87
+    /** @var CsrfTokenManager */
88
+    private $csrfTokenManager;
89
+    /** @var ContentSecurityPolicyNonceManager */
90
+    private $cspNonceManager;
91
+    /** @var IAppManager */
92
+    private $appManager;
93 93
 
94
-	/**
95
-	 * @param IRequest $request
96
-	 * @param ControllerMethodReflector $reflector
97
-	 * @param INavigationManager $navigationManager
98
-	 * @param IURLGenerator $urlGenerator
99
-	 * @param ILogger $logger
100
-	 * @param ISession $session
101
-	 * @param string $appName
102
-	 * @param bool $isLoggedIn
103
-	 * @param bool $isAdminUser
104
-	 * @param ContentSecurityPolicyManager $contentSecurityPolicyManager
105
-	 * @param CSRFTokenManager $csrfTokenManager
106
-	 * @param ContentSecurityPolicyNonceManager $cspNonceManager
107
-	 * @param IAppManager $appManager
108
-	 */
109
-	public function __construct(IRequest $request,
110
-								ControllerMethodReflector $reflector,
111
-								INavigationManager $navigationManager,
112
-								IURLGenerator $urlGenerator,
113
-								ILogger $logger,
114
-								ISession $session,
115
-								$appName,
116
-								$isLoggedIn,
117
-								$isAdminUser,
118
-								ContentSecurityPolicyManager $contentSecurityPolicyManager,
119
-								CsrfTokenManager $csrfTokenManager,
120
-								ContentSecurityPolicyNonceManager $cspNonceManager,
121
-								IAppManager $appManager) {
122
-		$this->navigationManager = $navigationManager;
123
-		$this->request = $request;
124
-		$this->reflector = $reflector;
125
-		$this->appName = $appName;
126
-		$this->urlGenerator = $urlGenerator;
127
-		$this->logger = $logger;
128
-		$this->session = $session;
129
-		$this->isLoggedIn = $isLoggedIn;
130
-		$this->isAdminUser = $isAdminUser;
131
-		$this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
132
-		$this->csrfTokenManager = $csrfTokenManager;
133
-		$this->cspNonceManager = $cspNonceManager;
134
-		$this->appManager = $appManager;
135
-	}
94
+    /**
95
+     * @param IRequest $request
96
+     * @param ControllerMethodReflector $reflector
97
+     * @param INavigationManager $navigationManager
98
+     * @param IURLGenerator $urlGenerator
99
+     * @param ILogger $logger
100
+     * @param ISession $session
101
+     * @param string $appName
102
+     * @param bool $isLoggedIn
103
+     * @param bool $isAdminUser
104
+     * @param ContentSecurityPolicyManager $contentSecurityPolicyManager
105
+     * @param CSRFTokenManager $csrfTokenManager
106
+     * @param ContentSecurityPolicyNonceManager $cspNonceManager
107
+     * @param IAppManager $appManager
108
+     */
109
+    public function __construct(IRequest $request,
110
+                                ControllerMethodReflector $reflector,
111
+                                INavigationManager $navigationManager,
112
+                                IURLGenerator $urlGenerator,
113
+                                ILogger $logger,
114
+                                ISession $session,
115
+                                $appName,
116
+                                $isLoggedIn,
117
+                                $isAdminUser,
118
+                                ContentSecurityPolicyManager $contentSecurityPolicyManager,
119
+                                CsrfTokenManager $csrfTokenManager,
120
+                                ContentSecurityPolicyNonceManager $cspNonceManager,
121
+                                IAppManager $appManager) {
122
+        $this->navigationManager = $navigationManager;
123
+        $this->request = $request;
124
+        $this->reflector = $reflector;
125
+        $this->appName = $appName;
126
+        $this->urlGenerator = $urlGenerator;
127
+        $this->logger = $logger;
128
+        $this->session = $session;
129
+        $this->isLoggedIn = $isLoggedIn;
130
+        $this->isAdminUser = $isAdminUser;
131
+        $this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
132
+        $this->csrfTokenManager = $csrfTokenManager;
133
+        $this->cspNonceManager = $cspNonceManager;
134
+        $this->appManager = $appManager;
135
+    }
136 136
 
137
-	/**
138
-	 * This runs all the security checks before a method call. The
139
-	 * security checks are determined by inspecting the controller method
140
-	 * annotations
141
-	 * @param Controller $controller the controller
142
-	 * @param string $methodName the name of the method
143
-	 * @throws SecurityException when a security check fails
144
-	 */
145
-	public function beforeController($controller, $methodName) {
137
+    /**
138
+     * This runs all the security checks before a method call. The
139
+     * security checks are determined by inspecting the controller method
140
+     * annotations
141
+     * @param Controller $controller the controller
142
+     * @param string $methodName the name of the method
143
+     * @throws SecurityException when a security check fails
144
+     */
145
+    public function beforeController($controller, $methodName) {
146 146
 
147
-		// this will set the current navigation entry of the app, use this only
148
-		// for normal HTML requests and not for AJAX requests
149
-		$this->navigationManager->setActiveEntry($this->appName);
147
+        // this will set the current navigation entry of the app, use this only
148
+        // for normal HTML requests and not for AJAX requests
149
+        $this->navigationManager->setActiveEntry($this->appName);
150 150
 
151
-		// security checks
152
-		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
153
-		if(!$isPublicPage) {
154
-			if(!$this->isLoggedIn) {
155
-				throw new NotLoggedInException();
156
-			}
151
+        // security checks
152
+        $isPublicPage = $this->reflector->hasAnnotation('PublicPage');
153
+        if(!$isPublicPage) {
154
+            if(!$this->isLoggedIn) {
155
+                throw new NotLoggedInException();
156
+            }
157 157
 
158
-			if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
159
-				if(!$this->isAdminUser) {
160
-					throw new NotAdminException();
161
-				}
162
-			}
163
-		}
158
+            if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
159
+                if(!$this->isAdminUser) {
160
+                    throw new NotAdminException();
161
+                }
162
+            }
163
+        }
164 164
 
165
-		if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) {
166
-			$lastConfirm = (int) $this->session->get('last-password-confirm');
167
-			if ($lastConfirm < (time() - (30 * 60 + 15))) { // allow 15 seconds delay
168
-				throw new NotConfirmedException();
169
-			}
170
-		}
165
+        if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) {
166
+            $lastConfirm = (int) $this->session->get('last-password-confirm');
167
+            if ($lastConfirm < (time() - (30 * 60 + 15))) { // allow 15 seconds delay
168
+                throw new NotConfirmedException();
169
+            }
170
+        }
171 171
 
172
-		// Check for strict cookie requirement
173
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
174
-			if(!$this->request->passesStrictCookieCheck()) {
175
-				throw new StrictCookieMissingException();
176
-			}
177
-		}
178
-		// CSRF check - also registers the CSRF token since the session may be closed later
179
-		Util::callRegister();
180
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
181
-			/*
172
+        // Check for strict cookie requirement
173
+        if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
174
+            if(!$this->request->passesStrictCookieCheck()) {
175
+                throw new StrictCookieMissingException();
176
+            }
177
+        }
178
+        // CSRF check - also registers the CSRF token since the session may be closed later
179
+        Util::callRegister();
180
+        if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
181
+            /*
182 182
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
183 183
 			 * hacks around that we have no full token auth in place yet and we
184 184
 			 * do want to offer CSRF checks for web requests.
185 185
 			 */
186
-			if(!$this->request->passesCSRFCheck() && !(
187
-					$controller instanceof OCSController &&
188
-					$this->request->getHeader('OCS-APIREQUEST') === 'true')) {
189
-				throw new CrossSiteRequestForgeryException();
190
-			}
191
-		}
186
+            if(!$this->request->passesCSRFCheck() && !(
187
+                    $controller instanceof OCSController &&
188
+                    $this->request->getHeader('OCS-APIREQUEST') === 'true')) {
189
+                throw new CrossSiteRequestForgeryException();
190
+            }
191
+        }
192 192
 
193
-		/**
194
-		 * FIXME: Use DI once available
195
-		 * Checks if app is enabled (also includes a check whether user is allowed to access the resource)
196
-		 * The getAppPath() check is here since components such as settings also use the AppFramework and
197
-		 * therefore won't pass this check.
198
-		 */
199
-		if(\OC_App::getAppPath($this->appName) !== false && !$this->appManager->isEnabledForUser($this->appName)) {
200
-			throw new AppNotEnabledException();
201
-		}
193
+        /**
194
+         * FIXME: Use DI once available
195
+         * Checks if app is enabled (also includes a check whether user is allowed to access the resource)
196
+         * The getAppPath() check is here since components such as settings also use the AppFramework and
197
+         * therefore won't pass this check.
198
+         */
199
+        if(\OC_App::getAppPath($this->appName) !== false && !$this->appManager->isEnabledForUser($this->appName)) {
200
+            throw new AppNotEnabledException();
201
+        }
202 202
 
203
-	}
203
+    }
204 204
 
205
-	/**
206
-	 * Performs the default CSP modifications that may be injected by other
207
-	 * applications
208
-	 *
209
-	 * @param Controller $controller
210
-	 * @param string $methodName
211
-	 * @param Response $response
212
-	 * @return Response
213
-	 */
214
-	public function afterController($controller, $methodName, Response $response) {
215
-		$policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
205
+    /**
206
+     * Performs the default CSP modifications that may be injected by other
207
+     * applications
208
+     *
209
+     * @param Controller $controller
210
+     * @param string $methodName
211
+     * @param Response $response
212
+     * @return Response
213
+     */
214
+    public function afterController($controller, $methodName, Response $response) {
215
+        $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
216 216
 
217
-		if (get_class($policy) === EmptyContentSecurityPolicy::class) {
218
-			return $response;
219
-		}
217
+        if (get_class($policy) === EmptyContentSecurityPolicy::class) {
218
+            return $response;
219
+        }
220 220
 
221
-		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
222
-		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
221
+        $defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
222
+        $defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
223 223
 
224
-		if($this->cspNonceManager->browserSupportsCspV3()) {
225
-			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
226
-		}
224
+        if($this->cspNonceManager->browserSupportsCspV3()) {
225
+            $defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
226
+        }
227 227
 
228
-		$response->setContentSecurityPolicy($defaultPolicy);
228
+        $response->setContentSecurityPolicy($defaultPolicy);
229 229
 
230
-		return $response;
231
-	}
230
+        return $response;
231
+    }
232 232
 
233
-	/**
234
-	 * If an SecurityException is being caught, ajax requests return a JSON error
235
-	 * response and non ajax requests redirect to the index
236
-	 * @param Controller $controller the controller that is being called
237
-	 * @param string $methodName the name of the method that will be called on
238
-	 *                           the controller
239
-	 * @param \Exception $exception the thrown exception
240
-	 * @throws \Exception the passed in exception if it can't handle it
241
-	 * @return Response a Response object or null in case that the exception could not be handled
242
-	 */
243
-	public function afterException($controller, $methodName, \Exception $exception) {
244
-		if($exception instanceof SecurityException) {
245
-			if($exception instanceof StrictCookieMissingException) {
246
-				return new RedirectResponse(\OC::$WEBROOT);
247
- 			}
248
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
249
-				$response = new JSONResponse(
250
-					array('message' => $exception->getMessage()),
251
-					$exception->getCode()
252
-				);
253
-			} else {
254
-				if($exception instanceof NotLoggedInException) {
255
-					$params = [];
256
-					if (isset($this->request->server['REQUEST_URI'])) {
257
-						$params['redirect_url'] = $this->request->server['REQUEST_URI'];
258
-					}
259
-					$url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params);
260
-					$response = new RedirectResponse($url);
261
-				} else {
262
-					$response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest');
263
-					$response->setStatus($exception->getCode());
264
-				}
265
-			}
233
+    /**
234
+     * If an SecurityException is being caught, ajax requests return a JSON error
235
+     * response and non ajax requests redirect to the index
236
+     * @param Controller $controller the controller that is being called
237
+     * @param string $methodName the name of the method that will be called on
238
+     *                           the controller
239
+     * @param \Exception $exception the thrown exception
240
+     * @throws \Exception the passed in exception if it can't handle it
241
+     * @return Response a Response object or null in case that the exception could not be handled
242
+     */
243
+    public function afterException($controller, $methodName, \Exception $exception) {
244
+        if($exception instanceof SecurityException) {
245
+            if($exception instanceof StrictCookieMissingException) {
246
+                return new RedirectResponse(\OC::$WEBROOT);
247
+                }
248
+            if (stripos($this->request->getHeader('Accept'),'html') === false) {
249
+                $response = new JSONResponse(
250
+                    array('message' => $exception->getMessage()),
251
+                    $exception->getCode()
252
+                );
253
+            } else {
254
+                if($exception instanceof NotLoggedInException) {
255
+                    $params = [];
256
+                    if (isset($this->request->server['REQUEST_URI'])) {
257
+                        $params['redirect_url'] = $this->request->server['REQUEST_URI'];
258
+                    }
259
+                    $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params);
260
+                    $response = new RedirectResponse($url);
261
+                } else {
262
+                    $response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest');
263
+                    $response->setStatus($exception->getCode());
264
+                }
265
+            }
266 266
 
267
-			$this->logger->debug($exception->getMessage());
268
-			return $response;
269
-		}
267
+            $this->logger->debug($exception->getMessage());
268
+            return $response;
269
+        }
270 270
 
271
-		throw $exception;
272
-	}
271
+        throw $exception;
272
+    }
273 273
 
274 274
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 
151 151
 		// security checks
152 152
 		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
153
-		if(!$isPublicPage) {
154
-			if(!$this->isLoggedIn) {
153
+		if (!$isPublicPage) {
154
+			if (!$this->isLoggedIn) {
155 155
 				throw new NotLoggedInException();
156 156
 			}
157 157
 
158
-			if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
159
-				if(!$this->isAdminUser) {
158
+			if (!$this->reflector->hasAnnotation('NoAdminRequired')) {
159
+				if (!$this->isAdminUser) {
160 160
 					throw new NotAdminException();
161 161
 				}
162 162
 			}
@@ -170,20 +170,20 @@  discard block
 block discarded – undo
170 170
 		}
171 171
 
172 172
 		// Check for strict cookie requirement
173
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
174
-			if(!$this->request->passesStrictCookieCheck()) {
173
+		if ($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
174
+			if (!$this->request->passesStrictCookieCheck()) {
175 175
 				throw new StrictCookieMissingException();
176 176
 			}
177 177
 		}
178 178
 		// CSRF check - also registers the CSRF token since the session may be closed later
179 179
 		Util::callRegister();
180
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
180
+		if (!$this->reflector->hasAnnotation('NoCSRFRequired')) {
181 181
 			/*
182 182
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
183 183
 			 * hacks around that we have no full token auth in place yet and we
184 184
 			 * do want to offer CSRF checks for web requests.
185 185
 			 */
186
-			if(!$this->request->passesCSRFCheck() && !(
186
+			if (!$this->request->passesCSRFCheck() && !(
187 187
 					$controller instanceof OCSController &&
188 188
 					$this->request->getHeader('OCS-APIREQUEST') === 'true')) {
189 189
 				throw new CrossSiteRequestForgeryException();
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		 * The getAppPath() check is here since components such as settings also use the AppFramework and
197 197
 		 * therefore won't pass this check.
198 198
 		 */
199
-		if(\OC_App::getAppPath($this->appName) !== false && !$this->appManager->isEnabledForUser($this->appName)) {
199
+		if (\OC_App::getAppPath($this->appName) !== false && !$this->appManager->isEnabledForUser($this->appName)) {
200 200
 			throw new AppNotEnabledException();
201 201
 		}
202 202
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
222 222
 		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
223 223
 
224
-		if($this->cspNonceManager->browserSupportsCspV3()) {
224
+		if ($this->cspNonceManager->browserSupportsCspV3()) {
225 225
 			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
226 226
 		}
227 227
 
@@ -241,17 +241,17 @@  discard block
 block discarded – undo
241 241
 	 * @return Response a Response object or null in case that the exception could not be handled
242 242
 	 */
243 243
 	public function afterException($controller, $methodName, \Exception $exception) {
244
-		if($exception instanceof SecurityException) {
245
-			if($exception instanceof StrictCookieMissingException) {
244
+		if ($exception instanceof SecurityException) {
245
+			if ($exception instanceof StrictCookieMissingException) {
246 246
 				return new RedirectResponse(\OC::$WEBROOT);
247 247
  			}
248
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
248
+			if (stripos($this->request->getHeader('Accept'), 'html') === false) {
249 249
 				$response = new JSONResponse(
250 250
 					array('message' => $exception->getMessage()),
251 251
 					$exception->getCode()
252 252
 				);
253 253
 			} else {
254
-				if($exception instanceof NotLoggedInException) {
254
+				if ($exception instanceof NotLoggedInException) {
255 255
 					$params = [];
256 256
 					if (isset($this->request->server['REQUEST_URI'])) {
257 257
 						$params['redirect_url'] = $this->request->server['REQUEST_URI'];
Please login to merge, or discard this patch.
lib/private/AppFramework/DependencyInjection/DIContainer.php 1 patch
Indentation   +393 added lines, -393 removed lines patch added patch discarded remove patch
@@ -63,397 +63,397 @@
 block discarded – undo
63 63
 
64 64
 class DIContainer extends SimpleContainer implements IAppContainer {
65 65
 
66
-	/**
67
-	 * @var array
68
-	 */
69
-	private $middleWares = array();
70
-
71
-	/** @var ServerContainer */
72
-	private $server;
73
-
74
-	/**
75
-	 * Put your class dependencies in here
76
-	 * @param string $appName the name of the app
77
-	 * @param array $urlParams
78
-	 * @param ServerContainer|null $server
79
-	 */
80
-	public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
81
-		parent::__construct();
82
-		$this['AppName'] = $appName;
83
-		$this['urlParams'] = $urlParams;
84
-
85
-		/** @var \OC\ServerContainer $server */
86
-		if ($server === null) {
87
-			$server = \OC::$server;
88
-		}
89
-		$this->server = $server;
90
-		$this->server->registerAppContainer($appName, $this);
91
-
92
-		// aliases
93
-		$this->registerAlias('appName', 'AppName');
94
-		$this->registerAlias('webRoot', 'WebRoot');
95
-		$this->registerAlias('userId', 'UserId');
96
-
97
-		/**
98
-		 * Core services
99
-		 */
100
-		$this->registerService(IOutput::class, function($c){
101
-			return new Output($this->getServer()->getWebRoot());
102
-		});
103
-
104
-		$this->registerService(Folder::class, function() {
105
-			return $this->getServer()->getUserFolder();
106
-		});
107
-
108
-		$this->registerService(IAppData::class, function (SimpleContainer $c) {
109
-			return $this->getServer()->getAppDataDir($c->query('AppName'));
110
-		});
111
-
112
-		$this->registerService(IL10N::class, function($c) {
113
-			return $this->getServer()->getL10N($c->query('AppName'));
114
-		});
115
-
116
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
117
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
118
-
119
-		$this->registerService(IRequest::class, function() {
120
-			return $this->getServer()->query(IRequest::class);
121
-		});
122
-		$this->registerAlias('Request', IRequest::class);
123
-
124
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
125
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
126
-
127
-		$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
128
-
129
-		$this->registerService(IServerContainer::class, function ($c) {
130
-			return $this->getServer();
131
-		});
132
-		$this->registerAlias('ServerContainer', IServerContainer::class);
133
-
134
-		$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
135
-			return $c->query('OCA\WorkflowEngine\Manager');
136
-		});
137
-
138
-		$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
139
-			return $c;
140
-		});
141
-
142
-		// commonly used attributes
143
-		$this->registerService('UserId', function ($c) {
144
-			return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
145
-		});
146
-
147
-		$this->registerService('WebRoot', function ($c) {
148
-			return $c->query('ServerContainer')->getWebRoot();
149
-		});
150
-
151
-		$this->registerService('fromMailAddress', function() {
152
-			return Util::getDefaultEmailAddress('no-reply');
153
-		});
154
-
155
-		$this->registerService('OC_Defaults', function ($c) {
156
-			return $c->getServer()->getThemingDefaults();
157
-		});
158
-
159
-		$this->registerService('OCP\Encryption\IManager', function ($c) {
160
-			return $this->getServer()->getEncryptionManager();
161
-		});
162
-
163
-		$this->registerService(IConfig::class, function ($c) {
164
-			return $c->query(OC\GlobalScale\Config::class);
165
-		});
166
-
167
-		$this->registerService(IValidator::class, function($c) {
168
-			return $c->query(Validator::class);
169
-		});
170
-
171
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
172
-			return new \OC\Security\IdentityProof\Manager(
173
-				$this->getServer()->query(\OC\Files\AppData\Factory::class),
174
-				$this->getServer()->getCrypto(),
175
-				$this->getServer()->getConfig()
176
-			);
177
-		});
178
-
179
-		/**
180
-		 * App Framework APIs
181
-		 */
182
-		$this->registerService('API', function($c){
183
-			$c->query('OCP\\ILogger')->debug(
184
-				'Accessing the API class is deprecated! Use the appropriate ' .
185
-				'services instead!'
186
-			);
187
-			return new API($c['AppName']);
188
-		});
189
-
190
-		$this->registerService('Protocol', function($c){
191
-			/** @var \OC\Server $server */
192
-			$server = $c->query('ServerContainer');
193
-			$protocol = $server->getRequest()->getHttpProtocol();
194
-			return new Http($_SERVER, $protocol);
195
-		});
196
-
197
-		$this->registerService('Dispatcher', function($c) {
198
-			return new Dispatcher(
199
-				$c['Protocol'],
200
-				$c['MiddlewareDispatcher'],
201
-				$c['ControllerMethodReflector'],
202
-				$c['Request']
203
-			);
204
-		});
205
-
206
-		/**
207
-		 * App Framework default arguments
208
-		 */
209
-		$this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
210
-		$this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
211
-		$this->registerParameter('corsMaxAge', 1728000);
212
-
213
-		/**
214
-		 * Middleware
215
-		 */
216
-		$app = $this;
217
-		$this->registerService('SecurityMiddleware', function($c) use ($app){
218
-			/** @var \OC\Server $server */
219
-			$server = $app->getServer();
220
-
221
-			return new SecurityMiddleware(
222
-				$c['Request'],
223
-				$c['ControllerMethodReflector'],
224
-				$server->getNavigationManager(),
225
-				$server->getURLGenerator(),
226
-				$server->getLogger(),
227
-				$server->getSession(),
228
-				$c['AppName'],
229
-				$app->isLoggedIn(),
230
-				$app->isAdminUser(),
231
-				$server->getContentSecurityPolicyManager(),
232
-				$server->getCsrfTokenManager(),
233
-				$server->getContentSecurityPolicyNonceManager(),
234
-				$server->getAppManager()
235
-			);
236
-
237
-		});
238
-
239
-		$this->registerService('BruteForceMiddleware', function($c) use ($app) {
240
-			/** @var \OC\Server $server */
241
-			$server = $app->getServer();
242
-
243
-			return new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
244
-				$c['ControllerMethodReflector'],
245
-				$server->getBruteForceThrottler(),
246
-				$server->getRequest()
247
-			);
248
-		});
249
-
250
-		$this->registerService('RateLimitingMiddleware', function($c) use ($app) {
251
-			/** @var \OC\Server $server */
252
-			$server = $app->getServer();
253
-
254
-			return new RateLimitingMiddleware(
255
-				$server->getRequest(),
256
-				$server->getUserSession(),
257
-				$c['ControllerMethodReflector'],
258
-				$c->query(OC\Security\RateLimiting\Limiter::class)
259
-			);
260
-		});
261
-
262
-		$this->registerService('CORSMiddleware', function($c) {
263
-			return new CORSMiddleware(
264
-				$c['Request'],
265
-				$c['ControllerMethodReflector'],
266
-				$c->query(IUserSession::class),
267
-				$c->getServer()->getBruteForceThrottler()
268
-			);
269
-		});
270
-
271
-		$this->registerService('SessionMiddleware', function($c) use ($app) {
272
-			return new SessionMiddleware(
273
-				$c['Request'],
274
-				$c['ControllerMethodReflector'],
275
-				$app->getServer()->getSession()
276
-			);
277
-		});
278
-
279
-		$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
280
-			$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
281
-			$userSession = $app->getServer()->getUserSession();
282
-			$session = $app->getServer()->getSession();
283
-			$urlGenerator = $app->getServer()->getURLGenerator();
284
-			$reflector = $c['ControllerMethodReflector'];
285
-			$request = $app->getServer()->getRequest();
286
-			return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
287
-		});
288
-
289
-		$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
290
-			return new OCSMiddleware(
291
-				$c['Request']
292
-			);
293
-		});
294
-
295
-		$this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) {
296
-			return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
297
-				$c['Request'],
298
-				$c['ControllerMethodReflector']
299
-			);
300
-		});
301
-
302
-		$middleWares = &$this->middleWares;
303
-		$this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
304
-			$dispatcher = new MiddlewareDispatcher();
305
-			$dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]);
306
-			$dispatcher->registerMiddleware($c['CORSMiddleware']);
307
-			$dispatcher->registerMiddleware($c['OCSMiddleware']);
308
-			$dispatcher->registerMiddleware($c['SecurityMiddleware']);
309
-			$dispatcher->registerMiddleware($c['TwoFactorMiddleware']);
310
-			$dispatcher->registerMiddleware($c['BruteForceMiddleware']);
311
-			$dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
312
-
313
-			foreach($middleWares as $middleWare) {
314
-				$dispatcher->registerMiddleware($c[$middleWare]);
315
-			}
316
-
317
-			$dispatcher->registerMiddleware($c['SessionMiddleware']);
318
-			return $dispatcher;
319
-		});
320
-
321
-	}
322
-
323
-
324
-	/**
325
-	 * @deprecated implements only deprecated methods
326
-	 * @return IApi
327
-	 */
328
-	public function getCoreApi()
329
-	{
330
-		return $this->query('API');
331
-	}
332
-
333
-	/**
334
-	 * @return \OCP\IServerContainer
335
-	 */
336
-	public function getServer()
337
-	{
338
-		return $this->server;
339
-	}
340
-
341
-	/**
342
-	 * @param string $middleWare
343
-	 * @return boolean|null
344
-	 */
345
-	public function registerMiddleWare($middleWare) {
346
-		array_push($this->middleWares, $middleWare);
347
-	}
348
-
349
-	/**
350
-	 * used to return the appname of the set application
351
-	 * @return string the name of your application
352
-	 */
353
-	public function getAppName() {
354
-		return $this->query('AppName');
355
-	}
356
-
357
-	/**
358
-	 * @deprecated use IUserSession->isLoggedIn()
359
-	 * @return boolean
360
-	 */
361
-	public function isLoggedIn() {
362
-		return \OC::$server->getUserSession()->isLoggedIn();
363
-	}
364
-
365
-	/**
366
-	 * @deprecated use IGroupManager->isAdmin($userId)
367
-	 * @return boolean
368
-	 */
369
-	public function isAdminUser() {
370
-		$uid = $this->getUserId();
371
-		return \OC_User::isAdminUser($uid);
372
-	}
373
-
374
-	private function getUserId() {
375
-		return $this->getServer()->getSession()->get('user_id');
376
-	}
377
-
378
-	/**
379
-	 * @deprecated use the ILogger instead
380
-	 * @param string $message
381
-	 * @param string $level
382
-	 * @return mixed
383
-	 */
384
-	public function log($message, $level) {
385
-		switch($level){
386
-			case 'debug':
387
-				$level = \OCP\Util::DEBUG;
388
-				break;
389
-			case 'info':
390
-				$level = \OCP\Util::INFO;
391
-				break;
392
-			case 'warn':
393
-				$level = \OCP\Util::WARN;
394
-				break;
395
-			case 'fatal':
396
-				$level = \OCP\Util::FATAL;
397
-				break;
398
-			default:
399
-				$level = \OCP\Util::ERROR;
400
-				break;
401
-		}
402
-		\OCP\Util::writeLog($this->getAppName(), $message, $level);
403
-	}
404
-
405
-	/**
406
-	 * Register a capability
407
-	 *
408
-	 * @param string $serviceName e.g. 'OCA\Files\Capabilities'
409
-	 */
410
-	public function registerCapability($serviceName) {
411
-		$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
412
-			return $this->query($serviceName);
413
-		});
414
-	}
415
-
416
-	/**
417
-	 * @param string $name
418
-	 * @return mixed
419
-	 * @throws QueryException if the query could not be resolved
420
-	 */
421
-	public function query($name) {
422
-		try {
423
-			return $this->queryNoFallback($name);
424
-		} catch (QueryException $firstException) {
425
-			try {
426
-				return $this->getServer()->query($name);
427
-			} catch (QueryException $secondException) {
428
-				if ($firstException->getCode() === 1) {
429
-					throw $secondException;
430
-				}
431
-				throw $firstException;
432
-			}
433
-		}
434
-	}
435
-
436
-	/**
437
-	 * @param string $name
438
-	 * @return mixed
439
-	 * @throws QueryException if the query could not be resolved
440
-	 */
441
-	public function queryNoFallback($name) {
442
-		$name = $this->sanitizeName($name);
443
-
444
-		if ($this->offsetExists($name)) {
445
-			return parent::query($name);
446
-		} else {
447
-			if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
448
-				return parent::query($name);
449
-			} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
450
-				return parent::query($name);
451
-			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
452
-				return parent::query($name);
453
-			}
454
-		}
455
-
456
-		throw new QueryException('Could not resolve ' . $name . '!' .
457
-			' Class can not be instantiated', 1);
458
-	}
66
+    /**
67
+     * @var array
68
+     */
69
+    private $middleWares = array();
70
+
71
+    /** @var ServerContainer */
72
+    private $server;
73
+
74
+    /**
75
+     * Put your class dependencies in here
76
+     * @param string $appName the name of the app
77
+     * @param array $urlParams
78
+     * @param ServerContainer|null $server
79
+     */
80
+    public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
81
+        parent::__construct();
82
+        $this['AppName'] = $appName;
83
+        $this['urlParams'] = $urlParams;
84
+
85
+        /** @var \OC\ServerContainer $server */
86
+        if ($server === null) {
87
+            $server = \OC::$server;
88
+        }
89
+        $this->server = $server;
90
+        $this->server->registerAppContainer($appName, $this);
91
+
92
+        // aliases
93
+        $this->registerAlias('appName', 'AppName');
94
+        $this->registerAlias('webRoot', 'WebRoot');
95
+        $this->registerAlias('userId', 'UserId');
96
+
97
+        /**
98
+         * Core services
99
+         */
100
+        $this->registerService(IOutput::class, function($c){
101
+            return new Output($this->getServer()->getWebRoot());
102
+        });
103
+
104
+        $this->registerService(Folder::class, function() {
105
+            return $this->getServer()->getUserFolder();
106
+        });
107
+
108
+        $this->registerService(IAppData::class, function (SimpleContainer $c) {
109
+            return $this->getServer()->getAppDataDir($c->query('AppName'));
110
+        });
111
+
112
+        $this->registerService(IL10N::class, function($c) {
113
+            return $this->getServer()->getL10N($c->query('AppName'));
114
+        });
115
+
116
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
117
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
118
+
119
+        $this->registerService(IRequest::class, function() {
120
+            return $this->getServer()->query(IRequest::class);
121
+        });
122
+        $this->registerAlias('Request', IRequest::class);
123
+
124
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
125
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
126
+
127
+        $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
128
+
129
+        $this->registerService(IServerContainer::class, function ($c) {
130
+            return $this->getServer();
131
+        });
132
+        $this->registerAlias('ServerContainer', IServerContainer::class);
133
+
134
+        $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
135
+            return $c->query('OCA\WorkflowEngine\Manager');
136
+        });
137
+
138
+        $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
139
+            return $c;
140
+        });
141
+
142
+        // commonly used attributes
143
+        $this->registerService('UserId', function ($c) {
144
+            return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
145
+        });
146
+
147
+        $this->registerService('WebRoot', function ($c) {
148
+            return $c->query('ServerContainer')->getWebRoot();
149
+        });
150
+
151
+        $this->registerService('fromMailAddress', function() {
152
+            return Util::getDefaultEmailAddress('no-reply');
153
+        });
154
+
155
+        $this->registerService('OC_Defaults', function ($c) {
156
+            return $c->getServer()->getThemingDefaults();
157
+        });
158
+
159
+        $this->registerService('OCP\Encryption\IManager', function ($c) {
160
+            return $this->getServer()->getEncryptionManager();
161
+        });
162
+
163
+        $this->registerService(IConfig::class, function ($c) {
164
+            return $c->query(OC\GlobalScale\Config::class);
165
+        });
166
+
167
+        $this->registerService(IValidator::class, function($c) {
168
+            return $c->query(Validator::class);
169
+        });
170
+
171
+        $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
172
+            return new \OC\Security\IdentityProof\Manager(
173
+                $this->getServer()->query(\OC\Files\AppData\Factory::class),
174
+                $this->getServer()->getCrypto(),
175
+                $this->getServer()->getConfig()
176
+            );
177
+        });
178
+
179
+        /**
180
+         * App Framework APIs
181
+         */
182
+        $this->registerService('API', function($c){
183
+            $c->query('OCP\\ILogger')->debug(
184
+                'Accessing the API class is deprecated! Use the appropriate ' .
185
+                'services instead!'
186
+            );
187
+            return new API($c['AppName']);
188
+        });
189
+
190
+        $this->registerService('Protocol', function($c){
191
+            /** @var \OC\Server $server */
192
+            $server = $c->query('ServerContainer');
193
+            $protocol = $server->getRequest()->getHttpProtocol();
194
+            return new Http($_SERVER, $protocol);
195
+        });
196
+
197
+        $this->registerService('Dispatcher', function($c) {
198
+            return new Dispatcher(
199
+                $c['Protocol'],
200
+                $c['MiddlewareDispatcher'],
201
+                $c['ControllerMethodReflector'],
202
+                $c['Request']
203
+            );
204
+        });
205
+
206
+        /**
207
+         * App Framework default arguments
208
+         */
209
+        $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
210
+        $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
211
+        $this->registerParameter('corsMaxAge', 1728000);
212
+
213
+        /**
214
+         * Middleware
215
+         */
216
+        $app = $this;
217
+        $this->registerService('SecurityMiddleware', function($c) use ($app){
218
+            /** @var \OC\Server $server */
219
+            $server = $app->getServer();
220
+
221
+            return new SecurityMiddleware(
222
+                $c['Request'],
223
+                $c['ControllerMethodReflector'],
224
+                $server->getNavigationManager(),
225
+                $server->getURLGenerator(),
226
+                $server->getLogger(),
227
+                $server->getSession(),
228
+                $c['AppName'],
229
+                $app->isLoggedIn(),
230
+                $app->isAdminUser(),
231
+                $server->getContentSecurityPolicyManager(),
232
+                $server->getCsrfTokenManager(),
233
+                $server->getContentSecurityPolicyNonceManager(),
234
+                $server->getAppManager()
235
+            );
236
+
237
+        });
238
+
239
+        $this->registerService('BruteForceMiddleware', function($c) use ($app) {
240
+            /** @var \OC\Server $server */
241
+            $server = $app->getServer();
242
+
243
+            return new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
244
+                $c['ControllerMethodReflector'],
245
+                $server->getBruteForceThrottler(),
246
+                $server->getRequest()
247
+            );
248
+        });
249
+
250
+        $this->registerService('RateLimitingMiddleware', function($c) use ($app) {
251
+            /** @var \OC\Server $server */
252
+            $server = $app->getServer();
253
+
254
+            return new RateLimitingMiddleware(
255
+                $server->getRequest(),
256
+                $server->getUserSession(),
257
+                $c['ControllerMethodReflector'],
258
+                $c->query(OC\Security\RateLimiting\Limiter::class)
259
+            );
260
+        });
261
+
262
+        $this->registerService('CORSMiddleware', function($c) {
263
+            return new CORSMiddleware(
264
+                $c['Request'],
265
+                $c['ControllerMethodReflector'],
266
+                $c->query(IUserSession::class),
267
+                $c->getServer()->getBruteForceThrottler()
268
+            );
269
+        });
270
+
271
+        $this->registerService('SessionMiddleware', function($c) use ($app) {
272
+            return new SessionMiddleware(
273
+                $c['Request'],
274
+                $c['ControllerMethodReflector'],
275
+                $app->getServer()->getSession()
276
+            );
277
+        });
278
+
279
+        $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
280
+            $twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
281
+            $userSession = $app->getServer()->getUserSession();
282
+            $session = $app->getServer()->getSession();
283
+            $urlGenerator = $app->getServer()->getURLGenerator();
284
+            $reflector = $c['ControllerMethodReflector'];
285
+            $request = $app->getServer()->getRequest();
286
+            return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
287
+        });
288
+
289
+        $this->registerService('OCSMiddleware', function (SimpleContainer $c) {
290
+            return new OCSMiddleware(
291
+                $c['Request']
292
+            );
293
+        });
294
+
295
+        $this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) {
296
+            return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
297
+                $c['Request'],
298
+                $c['ControllerMethodReflector']
299
+            );
300
+        });
301
+
302
+        $middleWares = &$this->middleWares;
303
+        $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
304
+            $dispatcher = new MiddlewareDispatcher();
305
+            $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]);
306
+            $dispatcher->registerMiddleware($c['CORSMiddleware']);
307
+            $dispatcher->registerMiddleware($c['OCSMiddleware']);
308
+            $dispatcher->registerMiddleware($c['SecurityMiddleware']);
309
+            $dispatcher->registerMiddleware($c['TwoFactorMiddleware']);
310
+            $dispatcher->registerMiddleware($c['BruteForceMiddleware']);
311
+            $dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
312
+
313
+            foreach($middleWares as $middleWare) {
314
+                $dispatcher->registerMiddleware($c[$middleWare]);
315
+            }
316
+
317
+            $dispatcher->registerMiddleware($c['SessionMiddleware']);
318
+            return $dispatcher;
319
+        });
320
+
321
+    }
322
+
323
+
324
+    /**
325
+     * @deprecated implements only deprecated methods
326
+     * @return IApi
327
+     */
328
+    public function getCoreApi()
329
+    {
330
+        return $this->query('API');
331
+    }
332
+
333
+    /**
334
+     * @return \OCP\IServerContainer
335
+     */
336
+    public function getServer()
337
+    {
338
+        return $this->server;
339
+    }
340
+
341
+    /**
342
+     * @param string $middleWare
343
+     * @return boolean|null
344
+     */
345
+    public function registerMiddleWare($middleWare) {
346
+        array_push($this->middleWares, $middleWare);
347
+    }
348
+
349
+    /**
350
+     * used to return the appname of the set application
351
+     * @return string the name of your application
352
+     */
353
+    public function getAppName() {
354
+        return $this->query('AppName');
355
+    }
356
+
357
+    /**
358
+     * @deprecated use IUserSession->isLoggedIn()
359
+     * @return boolean
360
+     */
361
+    public function isLoggedIn() {
362
+        return \OC::$server->getUserSession()->isLoggedIn();
363
+    }
364
+
365
+    /**
366
+     * @deprecated use IGroupManager->isAdmin($userId)
367
+     * @return boolean
368
+     */
369
+    public function isAdminUser() {
370
+        $uid = $this->getUserId();
371
+        return \OC_User::isAdminUser($uid);
372
+    }
373
+
374
+    private function getUserId() {
375
+        return $this->getServer()->getSession()->get('user_id');
376
+    }
377
+
378
+    /**
379
+     * @deprecated use the ILogger instead
380
+     * @param string $message
381
+     * @param string $level
382
+     * @return mixed
383
+     */
384
+    public function log($message, $level) {
385
+        switch($level){
386
+            case 'debug':
387
+                $level = \OCP\Util::DEBUG;
388
+                break;
389
+            case 'info':
390
+                $level = \OCP\Util::INFO;
391
+                break;
392
+            case 'warn':
393
+                $level = \OCP\Util::WARN;
394
+                break;
395
+            case 'fatal':
396
+                $level = \OCP\Util::FATAL;
397
+                break;
398
+            default:
399
+                $level = \OCP\Util::ERROR;
400
+                break;
401
+        }
402
+        \OCP\Util::writeLog($this->getAppName(), $message, $level);
403
+    }
404
+
405
+    /**
406
+     * Register a capability
407
+     *
408
+     * @param string $serviceName e.g. 'OCA\Files\Capabilities'
409
+     */
410
+    public function registerCapability($serviceName) {
411
+        $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
412
+            return $this->query($serviceName);
413
+        });
414
+    }
415
+
416
+    /**
417
+     * @param string $name
418
+     * @return mixed
419
+     * @throws QueryException if the query could not be resolved
420
+     */
421
+    public function query($name) {
422
+        try {
423
+            return $this->queryNoFallback($name);
424
+        } catch (QueryException $firstException) {
425
+            try {
426
+                return $this->getServer()->query($name);
427
+            } catch (QueryException $secondException) {
428
+                if ($firstException->getCode() === 1) {
429
+                    throw $secondException;
430
+                }
431
+                throw $firstException;
432
+            }
433
+        }
434
+    }
435
+
436
+    /**
437
+     * @param string $name
438
+     * @return mixed
439
+     * @throws QueryException if the query could not be resolved
440
+     */
441
+    public function queryNoFallback($name) {
442
+        $name = $this->sanitizeName($name);
443
+
444
+        if ($this->offsetExists($name)) {
445
+            return parent::query($name);
446
+        } else {
447
+            if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
448
+                return parent::query($name);
449
+            } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
450
+                return parent::query($name);
451
+            } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
452
+                return parent::query($name);
453
+            }
454
+        }
455
+
456
+        throw new QueryException('Could not resolve ' . $name . '!' .
457
+            ' Class can not be instantiated', 1);
458
+    }
459 459
 }
Please login to merge, or discard this patch.