Completed
Pull Request — master (#40)
by Janis
123:40 queued 121:18
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 93.88%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 106
ccs 46
cts 49
cp 0.9388
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 90 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\OcrStatusMapper;
19
use OCA\Ocr\Service\OcrService;
20
use OCA\Ocr\Service\QueueService;
21
use OCP\AppFramework\App;
22
use OCP\AppFramework\IAppContainer;
23
use OCP\IContainer;
24
25
/**
26
 * Class Application
27
 *
28
 * @package OCA\Ocr\AppInfo
29
 */
30
class Application extends App {
31
	/**
32
	 * Application constructor.
33
	 *
34
	 * @param array $urlParams
35
	 */
36 6
	public function __construct(array $urlParams = array()) {
37 6
		parent::__construct('ocr', $urlParams);
38 6
		$container = $this->getContainer();
39
40
		/**
41
		 * Add the js and style if OCA\Files app is loaded
42
		 */
43 6
		$eventDispatcher = \OC::$server->getEventDispatcher();
44
		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
45
			$scripts = array('ocrapp', 'ocrocr', 'ocrview');
46
			script('ocr', $scripts);
47
			style('ocr', 'ocrstyle');
48 6
		});
49
50
		/**
51
		 * Register core services
52
		 */
53
		$container->registerService('CurrentUID', function(IContainer $c) {
54
			/** @var \OC\Server $server */
55 2
			$server = $c->query('ServerContainer');
56 2
			$user = $server->getUserSession()->getUser();
57 2
			return ($user) ? $user->getUID() : '';
58 6
		});
59
60
		// Allow automatic DI for the View, until they migrated to Nodes API
61
		$container->registerService(View::class, function() {
62 1
			return new View('');
63 6
		}, false);
64
65
		/**
66
		 * Register the Ocr Status mapper
67
		 */
68
		$container->registerService('OcrStatusMapper', function(IContainer $c) {
69
			/** @var \OC\Server $server */
70 4
			$server = $c->query('ServerContainer');
71 4
			return new OcrStatusMapper(
72 4
				$server->getDatabaseConnection()
73 4
			);
74 6
		});
75
76
		/**
77
		 * Register the Queue Service
78
		 */
79
		$container->registerService('QueueService', function(IAppContainer $c) {
80
			/** @var \OC\Server $server */
81 3
			$server = $c->query('ServerContainer');
82 3
			return new QueueService(
83 3
				$c->query('OcrStatusMapper'),
84 3
				$server->getL10N('ocr'),
85 3
				$server->getLogger()
86 3
			);
87 6
		});
88
89
		/**
90
		 * Register the Ocr Services
91
		 */
92
		$container->registerService('OcrService', function(IAppContainer $c) {
93
			/** @var \OC\Server $server */
94 2
			$server = $c->query('ServerContainer');
95 2
			return new OcrService(
96 2
				$server->getTempManager(),
97 2
				$server->getConfig(),
98 2
				$c->query('QueueService'),
99 2
				$c->query('OcrStatusMapper'),
100 2
				new View('/' . $c->query('CurrentUID') . '/files'),
101 2
				$c->query('CurrentUID'),
102 2
				$server->getL10N('ocr'),
103 2
				$server->getLogger()
104 2
			);
105 6
		});
106
107
		/**
108
		 * Controller
109
		 */
110 6
		$container->registerService('OcrController', function(IAppContainer $c) {
111
			/** @var \OC\Server $server */
112 1
			$server = $c->query('ServerContainer');
113 1
			return new OcrController(
114 1
				$c->getAppName(),
115 1
				$server->getRequest(),
116 1
				$c->query('OcrService'),
117 1
				$c->query('CurrentUID')
118 1
			);
119 6
		});
120
121
		/**
122
		 * Controller
123
		 */
124 6
		$container->registerAlias('PersonalSettingsController', PersonalSettingsController::class);
125 6
	}
126
127
	/**
128
	 * Registers the Personal Settings Page for deletion of status objects and such things.
129
	 * @codeCoverageIgnore
130
	 */
131
	public function registerPersonal(){
132
		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
133
	}
134
135
}