Completed
Push — stable9 ( 485cb1...e094cf )
by Lukas
26:41 queued 26:23
created

DIContainer   B

Complexity

Total Complexity 15

Size/Duplication

Total Lines 415
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 17

Importance

Changes 0
Metric Value
wmc 15
c 0
b 0
f 0
lcom 2
cbo 17
dl 0
loc 415
rs 7.8571

10 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 309 2
A getCoreApi() 0 4 1
A getServer() 0 4 1
A registerMiddleWare() 0 3 1
A getAppName() 0 3 1
A isLoggedIn() 0 3 1
A isAdminUser() 0 4 1
A getUserId() 0 3 1
B log() 0 20 5
A registerCapability() 0 6 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bernhard Posselt <[email protected]>
6
 * @author Joas Schilling <[email protected]>
7
 * @author Jörn Friedrich Dreyer <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Morris Jobke <[email protected]>
10
 * @author Robin McCorkell <[email protected]>
11
 * @author Roeland Jago Douma <[email protected]>
12
 * @author Thomas Müller <[email protected]>
13
 * @author Thomas Tanghus <[email protected]>
14
 *
15
 * @license AGPL-3.0
16
 *
17
 * This code is free software: you can redistribute it and/or modify
18
 * it under the terms of the GNU Affero General Public License, version 3,
19
 * as published by the Free Software Foundation.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License, version 3,
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
28
 *
29
 */
30
31
32
namespace OC\AppFramework\DependencyInjection;
33
34
use OC;
35
use OC\AppFramework\Http;
36
use OC\AppFramework\Http\Dispatcher;
37
use OC\AppFramework\Http\Output;
38
use OC\AppFramework\Core\API;
39
use OC\AppFramework\Middleware\MiddlewareDispatcher;
40
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
41
use OC\AppFramework\Middleware\Security\CORSMiddleware;
42
use OC\AppFramework\Middleware\SessionMiddleware;
43
use OC\AppFramework\Utility\SimpleContainer;
44
use OCP\AppFramework\IApi;
45
use OCP\AppFramework\IAppContainer;
46
47
48
class DIContainer extends SimpleContainer implements IAppContainer {
49
50
	/**
51
	 * @var array
52
	 */
53
	private $middleWares = array();
54
55
	/**
56
	 * Put your class dependencies in here
57
	 * @param string $appName the name of the app
58
	 */
59
	public function __construct($appName, $urlParams = array()){
60
		parent::__construct();
61
		$this['AppName'] = $appName;
62
		$this['urlParams'] = $urlParams;
63
64
		/** @var \OC\ServerContainer $server */
65
		$server = $this->getServer();
66
		$server->registerAppContainer($appName, $this);
67
68
		// aliases
69
		$this->registerAlias('appName', 'AppName');
70
		$this->registerAlias('webRoot', 'WebRoot');
71
		$this->registerAlias('userId', 'UserId');
72
73
		/**
74
		 * Core services
75
		 */
76
		$this->registerService('OCP\\IAppConfig', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
			return $this->getServer()->getAppConfig();
78
		});
79
80
		$this->registerService('OCP\\App\\IAppManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
			return $this->getServer()->getAppManager();
82
		});
83
84
		$this->registerService('OCP\\AppFramework\\Http\\IOutput', function($c){
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
			return new Output($this->getServer()->getWebRoot());
86
		});
87
88
		$this->registerService('OCP\\IAvatarManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
			return $this->getServer()->getAvatarManager();
90
		});
91
92
		$this->registerService('OCP\\Activity\\IManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
			return $this->getServer()->getActivityManager();
94
		});
95
96
		$this->registerService('OCP\\ICache', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
			return $this->getServer()->getCache();
98
		});
99
100
		$this->registerService('OCP\\ICacheFactory', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
			return $this->getServer()->getMemCacheFactory();
102
		});
103
104
		$this->registerService('OC\\CapabilitiesManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
			return $this->getServer()->getCapabilitiesManager();
106
		});
107
108
		$this->registerService('OCP\Comments\ICommentsManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
109
			return $this->getServer()->getCommentsManager();
110
		});
111
112
		$this->registerService('OCP\\IConfig', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
113
			return $this->getServer()->getConfig();
114
		});
115
116
		$this->registerService('OCP\\Contacts\\IManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
117
			return $this->getServer()->getContactsManager();
118
		});
119
120
		$this->registerService('OCP\\IDateTimeZone', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
121
			return $this->getServer()->getDateTimeZone();
122
		});
123
124
		$this->registerService('OCP\\IDb', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
125
			return $this->getServer()->getDb();
0 ignored issues
show
Deprecated Code introduced by
The method OCP\IServerContainer::getDb() has been deprecated with message: 8.1.0 use getDatabaseConnection, will be removed in ownCloud 10

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
126
		});
127
128
		$this->registerService('OCP\\IDBConnection', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
129
			return $this->getServer()->getDatabaseConnection();
130
		});
131
132
		$this->registerService('OCP\\Diagnostics\\IEventLogger', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
133
			return $this->getServer()->getEventLogger();
134
		});
135
136
		$this->registerService('OCP\\Diagnostics\\IQueryLogger', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
137
			return $this->getServer()->getQueryLogger();
138
		});
139
140
		$this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
141
			return $this->getServer()->getMimeTypeDetector();
142
		});
143
144
		$this->registerService('OCP\\Files\\Config\\IMountProviderCollection', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
145
			return $this->getServer()->getMountProviderCollection();
146
		});
147
148
		$this->registerService('OCP\\Files\\IRootFolder', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
			return $this->getServer()->getRootFolder();
150
		});
151
152
		$this->registerService('OCP\\IGroupManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
153
			return $this->getServer()->getGroupManager();
154
		});
155
156
		$this->registerService('OCP\\IL10N', function($c) {
157
			return $this->getServer()->getL10N($c->query('AppName'));
158
		});
159
160
		$this->registerService('OCP\\L10N\\IFactory', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
161
			return $this->getServer()->getL10NFactory();
162
		});
163
164
		$this->registerService('OCP\\ILogger', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
165
			return $this->getServer()->getLogger();
166
		});
167
168
		$this->registerService('OCP\\BackgroundJob\\IJobList', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
169
			return $this->getServer()->getJobList();
170
		});
171
172
		$this->registerAlias('OCP\\AppFramework\\Utility\\IControllerMethodReflector', 'OC\AppFramework\Utility\ControllerMethodReflector');
173
		$this->registerAlias('ControllerMethodReflector', 'OCP\\AppFramework\\Utility\\IControllerMethodReflector');
174
175
		$this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
176
			return $this->getServer()->getMimeTypeDetector();
177
		});
178
179
		$this->registerService('OCP\\INavigationManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
180
			return $this->getServer()->getNavigationManager();
181
		});
182
183
		$this->registerService('OCP\\Notification\IManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
184
			return $this->getServer()->getNotificationManager();
185
		});
186
187
		$this->registerService('OCP\\IPreview', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
188
			return $this->getServer()->getPreviewManager();
189
		});
190
191
		$this->registerService('OCP\\IRequest', function () {
192
			return $this->getServer()->getRequest();
193
		});
194
		$this->registerAlias('Request', 'OCP\\IRequest');
195
196
		$this->registerService('OCP\\ITagManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
197
			return $this->getServer()->getTagManager();
198
		});
199
200
		$this->registerService('OCP\\ITempManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
201
			return $this->getServer()->getTempManager();
202
		});
203
204
		$this->registerAlias('OCP\\AppFramework\\Utility\\ITimeFactory', 'OC\AppFramework\Utility\TimeFactory');
205
		$this->registerAlias('TimeFactory', 'OCP\\AppFramework\\Utility\\ITimeFactory');
206
207
208
		$this->registerService('OCP\\Route\\IRouter', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
209
			return $this->getServer()->getRouter();
210
		});
211
212
		$this->registerService('OCP\\ISearch', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
213
			return $this->getServer()->getSearch();
214
		});
215
216
		$this->registerService('OCP\\ISearch', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
217
			return $this->getServer()->getSearch();
218
		});
219
220
		$this->registerService('OCP\\Security\\ICrypto', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
221
			return $this->getServer()->getCrypto();
222
		});
223
224
		$this->registerService('OCP\\Security\\IHasher', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
225
			return $this->getServer()->getHasher();
226
		});
227
228
		$this->registerService('OCP\\Security\\ICredentialsManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
229
			return $this->getServer()->getCredentialsManager();
230
		});
231
232
		$this->registerService('OCP\\Security\\ISecureRandom', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
233
			return $this->getServer()->getSecureRandom();
234
		});
235
236
		$this->registerService('OCP\\Share\\IManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
237
			return $this->getServer()->getShareManager();
238
		});
239
240
		$this->registerService('OCP\\SystemTag\\ISystemTagManager', function() {
241
			return $this->getServer()->getSystemTagManager();
242
		});
243
244
		$this->registerService('OCP\\SystemTag\\ISystemTagObjectMapper', function() {
245
			return $this->getServer()->getSystemTagObjectMapper();
246
		});
247
248
		$this->registerService('OCP\\IURLGenerator', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
249
			return $this->getServer()->getURLGenerator();
250
		});
251
252
		$this->registerService('OCP\\IUserManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
253
			return $this->getServer()->getUserManager();
254
		});
255
256
		$this->registerService('OCP\\IUserSession', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
257
			return $this->getServer()->getUserSession();
258
		});
259
260
		$this->registerService('OCP\\ISession', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
261
			return $this->getServer()->getSession();
262
		});
263
264
		$this->registerService('OCP\\Security\\IContentSecurityPolicyManager', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
265
			return $this->getServer()->getContentSecurityPolicyManager();
266
		});
267
268
		$this->registerService('ServerContainer', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
269
			return $this->getServer();
270
		});
271
		$this->registerAlias('OCP\\IServerContainer', 'ServerContainer');
272
273
		$this->registerService('Symfony\Component\EventDispatcher\EventDispatcherInterface', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
274
			return $this->getServer()->getEventDispatcher();
275
		});
276
277
		$this->registerService('OCP\\AppFramework\\IAppContainer', function ($c) {
278
			return $c;
279
		});
280
281
		// commonly used attributes
282
		$this->registerService('UserId', function ($c) {
283
			return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
284
		});
285
286
		$this->registerService('WebRoot', function ($c) {
287
			return $c->query('ServerContainer')->getWebRoot();
288
		});
289
290
291
		/**
292
		 * App Framework APIs
293
		 */
294
		$this->registerService('API', function($c){
295
			$c->query('OCP\\ILogger')->debug(
296
				'Accessing the API class is deprecated! Use the appropriate ' .
297
				'services instead!'
298
			);
299
			return new API($c['AppName']);
0 ignored issues
show
Deprecated Code introduced by
The class OC\AppFramework\Core\API has been deprecated.

This class, trait or interface has been deprecated.

Loading history...
300
		});
301
302
		$this->registerService('Protocol', function($c){
303
			/** @var \OC\Server $server */
304
			$server = $c->query('ServerContainer');
305
			$protocol = $server->getRequest()->getHttpProtocol();
306
			return new Http($_SERVER, $protocol);
307
		});
308
309
		$this->registerService('Dispatcher', function($c) {
310
			return new Dispatcher(
311
				$c['Protocol'],
312
				$c['MiddlewareDispatcher'],
313
				$c['ControllerMethodReflector'],
314
				$c['Request']
315
			);
316
		});
317
318
319
		/**
320
		 * Middleware
321
		 */
322
		$app = $this;
323
		$this->registerService('SecurityMiddleware', function($c) use ($app){
324
			return new SecurityMiddleware(
325
				$c['Request'],
326
				$c['ControllerMethodReflector'],
327
				$app->getServer()->getNavigationManager(),
328
				$app->getServer()->getURLGenerator(),
329
				$app->getServer()->getLogger(),
330
				$c['AppName'],
331
				$app->isLoggedIn(),
0 ignored issues
show
Deprecated Code introduced by
The method OC\AppFramework\Dependen...Container::isLoggedIn() has been deprecated with message: use IUserSession->isLoggedIn()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
332
				$app->isAdminUser(),
0 ignored issues
show
Deprecated Code introduced by
The method OC\AppFramework\Dependen...ontainer::isAdminUser() has been deprecated with message: use IGroupManager->isAdmin($userId)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
333
				$app->getServer()->getContentSecurityPolicyManager()
0 ignored issues
show
Compatibility introduced by
$app->getServer()->getCo...SecurityPolicyManager() of type object<OCP\Security\ICon...tSecurityPolicyManager> is not a sub-type of object<OC\Security\CSP\C...tSecurityPolicyManager>. It seems like you assume a concrete implementation of the interface OCP\Security\IContentSecurityPolicyManager to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
334
			);
335
		});
336
337
		$this->registerService('CORSMiddleware', function($c) {
338
			return new CORSMiddleware(
339
				$c['Request'],
340
				$c['ControllerMethodReflector'],
341
				$c['OCP\IUserSession']
342
			);
343
		});
344
345
		$this->registerService('SessionMiddleware', function($c) use ($app) {
346
			return new SessionMiddleware(
347
				$c['Request'],
348
				$c['ControllerMethodReflector'],
349
				$app->getServer()->getSession()
350
			);
351
		});
352
353
		$middleWares = &$this->middleWares;
354
		$this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
355
			$dispatcher = new MiddlewareDispatcher();
356
			$dispatcher->registerMiddleware($c['CORSMiddleware']);
357
			$dispatcher->registerMiddleware($c['SecurityMiddleware']);
358
359
			foreach($middleWares as $middleWare) {
360
				$dispatcher->registerMiddleware($c[$middleWare]);
361
			}
362
363
			$dispatcher->registerMiddleware($c['SessionMiddleware']);
364
			return $dispatcher;
365
		});
366
367
	}
368
369
370
	/**
371
	 * @deprecated implements only deprecated methods
372
	 * @return IApi
373
	 */
374
	function getCoreApi()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
375
	{
376
		return $this->query('API');
377
	}
378
379
	/**
380
	 * @return \OCP\IServerContainer
381
	 */
382
	function getServer()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
383
	{
384
		return OC::$server;
385
	}
386
387
	/**
388
	 * @param string $middleWare
389
	 * @return boolean|null
390
	 */
391
	function registerMiddleWare($middleWare) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
392
		array_push($this->middleWares, $middleWare);
393
	}
394
395
	/**
396
	 * used to return the appname of the set application
397
	 * @return string the name of your application
398
	 */
399
	function getAppName() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
400
		return $this->query('AppName');
401
	}
402
403
	/**
404
	 * @deprecated use IUserSession->isLoggedIn()
405
	 * @return boolean
406
	 */
407
	function isLoggedIn() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
408
		return \OC_User::isLoggedIn();
409
	}
410
411
	/**
412
	 * @deprecated use IGroupManager->isAdmin($userId)
413
	 * @return boolean
414
	 */
415
	function isAdminUser() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
416
		$uid = $this->getUserId();
417
		return \OC_User::isAdminUser($uid);
418
	}
419
420
	private function getUserId() {
421
		return $this->getServer()->getSession()->get('user_id');
422
	}
423
424
	/**
425
	 * @deprecated use the ILogger instead
426
	 * @param string $message
427
	 * @param string $level
428
	 * @return mixed
429
	 */
430
	function log($message, $level) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
431
		switch($level){
432
			case 'debug':
433
				$level = \OCP\Util::DEBUG;
434
				break;
435
			case 'info':
436
				$level = \OCP\Util::INFO;
437
				break;
438
			case 'warn':
439
				$level = \OCP\Util::WARN;
440
				break;
441
			case 'fatal':
442
				$level = \OCP\Util::FATAL;
443
				break;
444
			default:
445
				$level = \OCP\Util::ERROR;
446
				break;
447
		}
448
		\OCP\Util::writeLog($this->getAppName(), $message, $level);
449
	}
450
451
	/**
452
	 * Register a capability
453
	 *
454
	 * @param string $serviceName e.g. 'OCA\Files\Capabilities'
455
	 */
456
	public function registerCapability($serviceName) {
457
		$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
458
			return $this->query($serviceName);
459
		});
460
461
	}
462
}
463