Completed
Push — master ( f21795...e63d25 )
by Janis
02:34
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 95.08%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 130
ccs 58
cts 61
cp 0.9508
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 114 2
A registerPersonal() 0 3 1
1
<?php
2
/**
3
 * nextCloud - ocr
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Janis Koehr <[email protected]>
9
 * @copyright Janis Koehr 2016
10
 */
11
12
namespace OCA\Ocr\AppInfo;
13
14
15
use OC\Files\View;
16
use OCA\Ocr\Controller\OcrController;
17
use OCA\Ocr\Controller\PersonalSettingsController;
18
use OCA\Ocr\Db\FileMapper;
19
use OCA\Ocr\Db\OcrStatusMapper;
20
use OCA\Ocr\Db\ShareMapper;
21
use OCA\Ocr\Service\OcrService;
22
use OCA\Ocr\Service\QueueService;
23
use OCP\AppFramework\App;
24
use OCP\AppFramework\IAppContainer;
25
use OCP\IContainer;
26
27
/**
28
 * Class Application
29
 *
30
 * @package OCA\Ocr\AppInfo
31
 */
32
class Application extends App {
33
	/**
34
	 * Application constructor.
35
	 *
36
	 * @param array $urlParams
37
	 */
38 8
	public function __construct(array $urlParams = array()) {
39 8
		parent::__construct('ocr', $urlParams);
40 8
		$container = $this->getContainer();
41
42
		/**
43
		 * Add the js and style if OCA\Files app is loaded
44
		 */
45 8
		$eventDispatcher = \OC::$server->getEventDispatcher();
46
		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
47
			$scripts = array('ocrapp', 'ocrocr', 'ocrview');
48
			script('ocr', $scripts);
49
			style('ocr', 'ocrstyle');
50 8
		});
51
52
		/**
53
		 * Register core services
54
		 */
55
		$container->registerService('CurrentUID', function(IContainer $c) {
56
			/** @var \OC\Server $server */
57 2
			$server = $c->query('ServerContainer');
58 2
			$user = $server->getUserSession()->getUser();
59 2
			return ($user) ? $user->getUID() : '';
60 8
		});
61
62
		// Allow automatic DI for the View, until they migrated to Nodes API
63
		$container->registerService(View::class, function() {
64 1
			return new View('');
65 8
		}, false);
66
67
		/**
68
		 * Register the Ocr Status mapper
69
		 */
70
		$container->registerService('OcrStatusMapper', function(IContainer $c) {
71
			/** @var \OC\Server $server */
72 4
			$server = $c->query('ServerContainer');
73 4
			return new OcrStatusMapper(
74 4
				$server->getDatabaseConnection()
75 4
			);
76 8
		});
77
78
		/**
79
		 * Register the File mapper
80
		 */
81
		$container->registerService('FileMapper', function(IContainer $c) {
82
			/** @var \OC\Server $server */
83 3
			$server = $c->query('ServerContainer');
84 3
			return new FileMapper(
85 3
				$server->getDatabaseConnection()
86 3
			);
87 8
		});
88
89
		/**
90
		 * Register the Share mapper
91
		 */
92
		$container->registerService('ShareMapper', function(IContainer $c) {
93
			/** @var \OC\Server $server */
94 3
			$server = $c->query('ServerContainer');
95 3
			return new ShareMapper(
96 3
				$server->getDatabaseConnection()
97 3
			);
98 8
		});
99
100
		/**
101
		 * Register the Queue Service
102
		 */
103
		$container->registerService('QueueService', function(IAppContainer $c) {
104
			/** @var \OC\Server $server */
105 3
			$server = $c->query('ServerContainer');
106 3
			return new QueueService(
107 3
				$c->query('OcrStatusMapper'),
108 3
				$server->getConfig(),
109 3
				$server->getL10N('ocr'),
110 3
				$server->getLogger()
111 3
			);
112 8
		});
113
114
		/**
115
		 * Register the Ocr Services
116
		 */
117
		$container->registerService('OcrService', function(IAppContainer $c) {
118
			/** @var \OC\Server $server */
119 2
			$server = $c->query('ServerContainer');
120 2
			return new OcrService(
121 2
				$server->getTempManager(),
122 2
				$c->query('QueueService'),
123 2
				$c->query('OcrStatusMapper'),
124 2
				$c->query('FileMapper'),
125 2
				$c->query('ShareMapper'),
126 2
				new View('/' . $c->query('CurrentUID') . '/files'),
127 2
				$c->query('CurrentUID'),
128 2
				$server->getL10N('ocr'),
129 2
				$server->getLogger()
130 2
			);
131 8
		});
132
133
		/**
134
		 * Controller
135
		 */
136 8
		$container->registerService('OcrController', function(IAppContainer $c) {
137
			/** @var \OC\Server $server */
138 1
			$server = $c->query('ServerContainer');
139 1
			return new OcrController(
140 1
				$c->getAppName(),
141 1
				$server->getRequest(),
142 1
				$c->query('OcrService'),
143 1
				$c->query('CurrentUID')
144 8
			);
145 8
		});
146
147
		/**
148
		 * Controller
149
		 */
150 8
		$container->registerAlias('PersonalSettingsController', PersonalSettingsController::class);
151 8
	}
152
153
	/**
154
	 * Registers the Personal Settings Page for deletion of status objects and such things.
155
	 * @codeCoverageIgnore
156
	 */
157
	public function registerPersonal() {
158
		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
159
	}
160
161
}