Passed
Push — master ( 8ec1b8...284ca3 )
by Christoph
13:12 queued 12s
created

Application::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2016, ownCloud, Inc.
7
 *
8
 * @author Christoph Wurst <[email protected]>
9
 * @author Daniel Kesselberg <[email protected]>
10
 * @author Joas Schilling <[email protected]>
11
 * @author John Molakvoæ (skjnldsv) <[email protected]>
12
 * @author Julius Härtl <[email protected]>
13
 * @author Morris Jobke <[email protected]>
14
 * @author Robin Appelman <[email protected]>
15
 * @author Roeland Jago Douma <[email protected]>
16
 * @author Tobias Kaminsky <[email protected]>
17
 * @author Vincent Petry <[email protected]>
18
 *
19
 * @license AGPL-3.0
20
 *
21
 * This code is free software: you can redistribute it and/or modify
22
 * it under the terms of the GNU Affero General Public License, version 3,
23
 * as published by the Free Software Foundation.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
 * GNU Affero General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU Affero General Public License, version 3,
31
 * along with this program. If not, see <http://www.gnu.org/licenses/>
32
 *
33
 */
34
35
namespace OCA\Files\AppInfo;
36
37
use OC\Search\Provider\File;
38
use OCA\Files\Capabilities;
39
use OCA\Files\Collaboration\Resources\Listener;
40
use OCA\Files\Collaboration\Resources\ResourceProvider;
41
use OCA\Files\Controller\ApiController;
42
use OCA\Files\Event\LoadAdditionalScriptsEvent;
43
use OCA\Files\Event\LoadSidebar;
44
use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
45
use OCA\Files\Listener\LoadSidebarListener;
46
use OCA\Files\Notification\Notifier;
47
use OCA\Files\Service\TagService;
48
use OCP\AppFramework\App;
49
use OCP\AppFramework\Bootstrap\IBootContext;
50
use OCP\AppFramework\Bootstrap\IBootstrap;
51
use OCP\AppFramework\Bootstrap\IRegistrationContext;
52
use OCP\Collaboration\Resources\IProviderManager;
53
use OCP\IContainer;
54
use OCP\IL10N;
55
use OCP\IServerContainer;
56
use OCP\Notification\IManager;
57
use OCP\Util;
58
59
class Application extends App implements IBootstrap {
60
	public const APP_ID = 'files';
61
62
	public function __construct(array $urlParams=[]) {
63
		parent::__construct(self::APP_ID, $urlParams);
64
	}
65
66
	public function register(IRegistrationContext $context): void {
67
		/**
68
		 * Controllers
69
		 */
70
		$context->registerService('APIController', function (IContainer $c) {
71
			/** @var IServerContainer $server */
72
			$server = $c->query(IServerContainer::class);
73
74
			return new ApiController(
75
				$c->query('AppName'),
76
				$c->query('Request'),
77
				$server->getUserSession(),
78
				$c->query('TagService'),
79
				$server->getPreviewManager(),
80
				$server->getShareManager(),
81
				$server->getConfig(),
82
				$server->getUserFolder()
83
			);
84
		});
85
86
		/**
87
		 * Services
88
		 */
89
		$context->registerService('TagService', function (IContainer $c) {
90
			/** @var IServerContainer $server */
91
			$server = $c->query(IServerContainer::class);
92
93
			return new TagService(
94
				$server->getUserSession(),
95
				$server->getActivityManager(),
96
				$server->getTagManager()->load(self::APP_ID),
97
				$server->getUserFolder(),
98
				$server->getEventDispatcher()
0 ignored issues
show
Deprecated Code introduced by
The function OCP\IServerContainer::getEventDispatcher() has been deprecated: 20.0.0 use \OCP\EventDispatcher\IEventDispatcher ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

98
				/** @scrutinizer ignore-deprecated */ $server->getEventDispatcher()

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

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

Loading history...
99
			);
100
		});
101
102
		/*
103
		 * Register capabilities
104
		 */
105
		$context->registerCapability(Capabilities::class);
106
107
		$context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
108
		$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
109
	}
110
111
	public function boot(IBootContext $context): void {
112
		$this->registerCollaboration($context);
113
		Listener::register($context->getServerContainer()->getEventDispatcher());
0 ignored issues
show
Deprecated Code introduced by
The function OCP\IServerContainer::getEventDispatcher() has been deprecated: 20.0.0 use \OCP\EventDispatcher\IEventDispatcher ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

113
		Listener::register(/** @scrutinizer ignore-deprecated */ $context->getServerContainer()->getEventDispatcher());

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

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

Loading history...
114
		$this->registerNotification($context);
115
		$this->registerSearchProvider($context);
116
		$this->registerTemplates();
117
		$this->registerNavigation($context);
118
		$this->registerHooks();
119
	}
120
121
	/**
122
	 * Register Collaboration ResourceProvider
123
	 */
124
	private function registerCollaboration(IBootContext $context): void {
125
		/** @var IProviderManager $providerManager */
126
		$providerManager = $context->getAppContainer()->query(IProviderManager::class);
127
		$providerManager->registerResourceProvider(ResourceProvider::class);
128
	}
129
130
	private function registerNotification(IBootContext $context): void {
131
		/** @var IManager $notifications */
132
		$notifications = $context->getAppContainer()->query(IManager::class);
133
		$notifications->registerNotifierService(Notifier::class);
134
	}
135
136
	/**
137
	 * @param IBootContext $context
138
	 */
139
	private function registerSearchProvider(IBootContext $context): void {
140
		$context->getServerContainer()->getSearch()->registerProvider(File::class, ['apps' => ['files']]);
141
	}
142
143
	private function registerTemplates(): void {
144
		$templateManager = \OC_Helper::getFileTemplateManager();
0 ignored issues
show
Deprecated Code introduced by
The function OC_Helper::getFileTemplateManager() has been deprecated: 18.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

144
		$templateManager = /** @scrutinizer ignore-deprecated */ \OC_Helper::getFileTemplateManager();

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

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

Loading history...
145
		$templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp');
146
		$templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
147
		$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
148
	}
149
150
	private function registerNavigation(IBootContext $context): void {
151
		/** @var IL10N $l10n */
152
		$l10n = $context->getAppContainer()->query(IL10N::class);
153
		\OCA\Files\App::getNavigationManager()->add([
154
			'id' => 'files',
155
			'appname' => 'files',
156
			'script' => 'list.php',
157
			'order' => 0,
158
			'name' => $l10n->t('All files')
159
		]);
160
		\OCA\Files\App::getNavigationManager()->add([
161
			'id' => 'recent',
162
			'appname' => 'files',
163
			'script' => 'recentlist.php',
164
			'order' => 2,
165
			'name' => $l10n->t('Recent')
166
		]);
167
		\OCA\Files\App::getNavigationManager()->add([
168
			'id' => 'favorites',
169
			'appname' => 'files',
170
			'script' => 'simplelist.php',
171
			'order' => 5,
172
			'name' => $l10n->t('Favorites'),
173
			'expandedState' => 'show_Quick_Access'
174
		]);
175
	}
176
177
	private function registerHooks(): void {
178
		Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
179
	}
180
}
181