Completed
Pull Request — master (#59)
by Joas
06:26
created

Application::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.0019

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 7
cts 8
cp 0.875
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 1.0019
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2016, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Notifications\AppInfo;
23
24
use OC\Authentication\Token\IProvider;
25
use OCA\Notifications\App;
26
use OCA\Notifications\Capabilities;
27
use OCA\Notifications\Controller\EndpointController;
28
use OCP\AppFramework\IAppContainer;
29
use OCP\Util;
30
31
class Application extends \OCP\AppFramework\App {
32 15
	public function __construct() {
33 15
		parent::__construct('notifications');
34 15
		$container = $this->getContainer();
35
36 15
		$container->registerAlias('EndpointController', EndpointController::class);
37 15
		$container->registerCapability(Capabilities::class);
38
39
		// FIXME this is for automatic DI because it is not in DIContainer
40
		$container->registerService(IProvider::class, function(IAppContainer $c) {
41
			return $c->getServer()->query(IProvider::class);
42 15
		});
43 15
	}
44
45 6
	public function register() {
46 6
		$this->registerNotificationApp();
47 6
		$this->registerUserInterface();
48 6
	}
49
50 6
	protected function registerNotificationApp() {
51 6
		$container = $this->getContainer();
52 6
		$container->getServer()->getNotificationManager()->registerApp(function() use($container) {
53 1
			return $container->query(App::class);
54 6
		});
55 6
	}
56
57 6
	protected function registerUserInterface() {
58
		// Only display the app on index.php except for public shares
59 6
		$server = $this->getContainer()->getServer();
60 6
		$request = $server->getRequest();
61
62 6
		if ($server->getUserSession()->getUser() !== null
63 6
			&& substr($request->getScriptName(), 0 - strlen('/index.php')) === '/index.php'
64 6
			&& substr($request->getPathInfo(), 0, strlen('/s/')) !== '/s/'
65 6
			&& substr($request->getPathInfo(), 0, strlen('/login/')) !== '/login/') {
66 1
			Util::addScript('notifications', 'app');
67 1
			Util::addScript('notifications', 'notification');
68 1
			Util::addScript('notifications', 'richObjectStringParser');
69 1
			Util::addStyle('notifications', 'styles');
70 1
		}
71
72 6
	}
73
}
74