Application::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.9332
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Mood
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 *
26
 */
27
28
namespace OCA\Mood\AppInfo;
29
30
use OCA\Circles\Api\v1\Circles;
31
use OCA\Mood\Controller\MoodController;
32
use OCA\Mood\Controller\ToolsController;
33
use OCA\Mood\Service\HttpService;
34
use OCP\AppFramework\App;
35
use OCP\AppFramework\IAppContainer;
36
use OCP\Notification\IApp;
37
use OCP\Util;
38
39
class Application extends App {
40
41
	/** @var string */
42
	private $appName;
43
44
	/**
45
	 * @param array $params
46
	 */
47
	public function __construct(array $params = array()) {
48
		parent::__construct('mood', $params);
49
50
		$container = $this->getContainer();
51
		$this->appName = $container->query('AppName');
52
53
		$this->registerCore($container);
54
		$this->registerServices($container);
55
		$this->registerControllers($container);
56
	}
57
58
59
	/**
60
	 * @param IAppContainer $container
61
	 */
62
	public function registerServices(IAppContainer $container) {
63
64
		$container->registerService(
65
			'HttpService', function() {
66
			return new HttpService();
67
		}
68
		);
69
	}
70
71
72
	/**
73
	 * @param IAppContainer $container
74
	 */
75
	public function registerControllers(IAppContainer $container) {
76
77
		$container->registerService(
78
			'MoodController', function(IAppContainer $c) {
79
			return new MoodController($c->query('AppName'), $c->query('Request'));
80
		}
81
		);
82
83
84
		$container->registerService(
85
			'ToolsController', function(IAppContainer $c) {
86
			return new ToolsController(
87
				$c->query('AppName'), $c->query('Request'), $c->query('HttpService')
88
			);
89
		}
90
		);
91
92
	}
93
94
95
	/**
96
	 * @param IAppContainer $container
97
	 */
98
	public function registerCore(IAppContainer $container) {
99
100
		$container->registerService(
101
			'L10N', function(IAppContainer $c) {
102
			return $c->query('ServerContainer')
103
					 ->getL10N($c->query('AppName'));
104
		}
105
		);
106
107
		$container->registerService(
108
			'ActivityManager', function(IAppContainer $c) {
109
			return $c->query('ServerContainer')
110
					 ->getActivityManager();
111
		}
112
		);
113
	}
114
115
116
	/**
117
	 *
118
	 */
119
	public function registerToActivity() {
120
		if (!\OCP\App::isEnabled('circles')) {
121
			\OC::$server->getLogger()
122
						->log(2, 'mood needs circles');
123
124
			return;
125
		}
126
127
		\OC::$server->getEventDispatcher()
128
					->addListener(
129
						'OCA\Activity::loadAdditionalScripts', function() {
130
						Circles::addJavascriptAPI();
131
						Util::addScript('mood', 'mood');
132
						Util::addScript('mood', 'mood.app');
133
						Util::addScript('mood', 'mood.app.elements');
134
						Util::addScript('mood', 'mood.app.actions');
135
						Util::addScript('mood', 'mood.app.navigation');
136
137
						Util::addStyle('mood', 'navigate');
138
					}
139
					);
140
	}
141
}
142
143