1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Calendar App |
4
|
|
|
* |
5
|
|
|
* @author Georg Ehrke |
6
|
|
|
* @copyright 2017 Georg Ehrke <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public |
19
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
namespace OCA\Calendar\AppInfo; |
23
|
|
|
|
24
|
|
|
use OCA\Calendar\Controller; |
25
|
|
|
|
26
|
|
|
use OCP\AppFramework\App; |
27
|
|
|
use OCP\AppFramework\IAppContainer; |
28
|
|
|
|
29
|
|
|
class Application extends App { |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array $params |
33
|
|
|
*/ |
34
|
|
|
public function __construct($params=[]) { |
35
|
|
|
parent::__construct('calendar', $params); |
36
|
|
|
$container = $this->getContainer(); |
37
|
|
|
|
38
|
|
|
$container->registerService('ContactController', function(IAppContainer $c) { |
39
|
|
|
$request = $c->query('Request'); |
40
|
|
|
$contacts = $c->getServer()->getContactsManager(); |
41
|
|
|
|
42
|
|
|
return new Controller\ContactController($c->getAppName(), $request, $contacts); |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
$container->registerService('EmailController', function(IAppContainer $c) { |
46
|
|
|
$request = $c->query('Request'); |
47
|
|
|
$userSession = $c->getServer()->getUserSession(); |
48
|
|
|
$config = $c->getServer()->getConfig(); |
49
|
|
|
$mailer = $c->getServer()->getMailer(); |
50
|
|
|
$l10n = $c->getServer()->getL10N($c->query('AppName')); |
51
|
|
|
$defaults = new \OCP\Defaults(); |
52
|
|
|
|
53
|
|
|
return new Controller\EmailController($c->getAppName(), $request, $userSession, $config, $mailer, $l10n, $defaults); |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
View Code Duplication |
$container->registerService('ProxyController', function(IAppContainer $c) { |
|
|
|
|
57
|
|
|
$request = $c->query('Request'); |
58
|
|
|
$client = $c->getServer()->getHTTPClientService(); |
59
|
|
|
$l10n = $c->getServer()->getL10N($c->query('AppName')); |
60
|
|
|
$logger = $c->getServer()->getLogger(); |
61
|
|
|
|
62
|
|
|
return new Controller\ProxyController($c->getAppName(), $request, $client, $l10n, $logger); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
$container->registerService('SettingsController', function(IAppContainer $c) { |
66
|
|
|
$request = $c->query('Request'); |
67
|
|
|
$config = $c->getServer()->getConfig(); |
68
|
|
|
$userSession = $c->getServer()->getUserSession(); |
69
|
|
|
|
70
|
|
|
return new Controller\SettingsController($c->getAppName(), $request, $userSession, $config); |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
$container->registerService('TimezoneController', function(IAppContainer $c) { |
74
|
|
|
$request = $c->query('Request'); |
75
|
|
|
|
76
|
|
|
return new Controller\TimezoneController($c->getAppName(), $request); |
77
|
|
|
}); |
78
|
|
|
|
79
|
|
View Code Duplication |
$container->registerService('ViewController', function(IAppContainer $c) { |
|
|
|
|
80
|
|
|
$request = $c->query('Request'); |
81
|
|
|
$userSession = $c->getServer()->getUserSession(); |
82
|
|
|
$config = $c->getServer()->getConfig(); |
83
|
|
|
$urlGenerator = $c->getServer()->getURLGenerator(); |
84
|
|
|
|
85
|
|
|
return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $urlGenerator); |
86
|
|
|
}); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* register navigation entry |
91
|
|
|
*/ |
92
|
|
|
public function registerNavigation() { |
93
|
|
|
$appName = $this->getContainer()->getAppName(); |
94
|
|
|
$server = $this->getContainer()->getServer(); |
95
|
|
|
|
96
|
|
|
$server->getNavigationManager()->add(function() use ($appName, $server) { |
97
|
|
|
return [ |
98
|
|
|
'id' => $appName, |
99
|
|
|
'order' => 5, |
100
|
|
|
'href' => $server->getURLGenerator() |
101
|
|
|
->linkToRoute('calendar.view.index'), |
102
|
|
|
'icon' => $server->getURLGenerator() |
103
|
|
|
->imagePath($appName, 'calendar.svg'), |
104
|
|
|
'name' => $server->getL10N($appName)->t('Calendar'), |
105
|
|
|
]; |
106
|
|
|
}); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.