Skip to content

Commit a4d8572

Browse files
committed
better load of libs
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 3ae1816 commit a4d8572

File tree

12 files changed

+46
-41
lines changed

12 files changed

+46
-41
lines changed

lib/AppInfo/Application.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
use OCP\FullTextSearch\IFullTextSearchManager;
4747
use OCP\INavigationManager;
4848
use OCP\IServerContainer;
49+
use OCP\IURLGenerator;
50+
use Symfony\Component\Routing\Exception\RouteNotFoundException;
4951
use Throwable;
5052

5153
require_once __DIR__ . '/../../vendor/autoload.php';
@@ -54,7 +56,8 @@
5456
class Application extends App implements IBootstrap {
5557

5658

57-
const APP_NAME = 'fulltextsearch';
59+
const APP_ID = 'fulltextsearch';
60+
const APP_NAME = 'FullTextSearch';
5861

5962

6063
/**
@@ -63,7 +66,7 @@ class Application extends App implements IBootstrap {
6366
* @param array $params
6467
*/
6568
public function __construct(array $params = []) {
66-
parent::__construct(self::APP_NAME, $params);
69+
parent::__construct(self::APP_ID, $params);
6770
}
6871

6972

@@ -117,25 +120,27 @@ protected function registerNavigation(IServerContainer $container) {
117120
return;
118121
}
119122

120-
$container->get(INavigationManager::class)
121-
->add($this->fullTextSearchNavigation());
123+
try {
124+
$container->get(INavigationManager::class)
125+
->add($this->fullTextSearchNavigation());
126+
} catch (RouteNotFoundException $e) {
127+
}
122128
}
123129

124130

125131
/**
126132
* @return array
127133
*/
128134
private function fullTextSearchNavigation(): array {
129-
$urlGen = OC::$server->getURLGenerator();
130-
$navName = OC::$server->getL10N(self::APP_NAME)
131-
->t('Search');
135+
/** @var IURLGenerator $urlGen */
136+
$urlGen = OC::$server->get(IURLGenerator::class);
132137

133138
return [
134-
'id' => self::APP_NAME,
139+
'id' => self::APP_ID,
135140
'order' => 5,
136-
'href' => $urlGen->linkToRoute('fulltextsearch.Navigation.navigate'),
137-
'icon' => $urlGen->imagePath(self::APP_NAME, 'fulltextsearch.svg'),
138-
'name' => $navName
141+
'href' => $urlGen->linkToRoute(self::APP_ID . '.Navigation.navigate'),
142+
'icon' => $urlGen->imagePath(self::APP_ID, 'fulltextsearch.svg'),
143+
'name' => 'Search'
139144
];
140145
}
141146

lib/Controller/ApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __construct(
7676
IRequest $request, ConfigService $configService, SearchService $searchService,
7777
MiscService $miscService
7878
) {
79-
parent::__construct(Application::APP_NAME, $request);
79+
parent::__construct(Application::APP_ID, $request);
8080
$this->searchService = $searchService;
8181
$this->configService = $configService;
8282
$this->miscService = $miscService;

lib/Controller/NavigationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(
7575
IRequest $request, IConfig $config, IFullTextSearchManager $fullTextSearchManager,
7676
ConfigService $configService, MiscService $miscService
7777
) {
78-
parent::__construct(Application::APP_NAME, $request);
78+
parent::__construct(Application::APP_ID, $request);
7979
$this->config = $config;
8080
$this->fullTextSearchManager = $fullTextSearchManager;
8181
$this->configService = $configService;
@@ -96,7 +96,7 @@ public function navigate(): TemplateResponse {
9696

9797
$this->fullTextSearchManager->addJavascriptAPI();
9898

99-
return new TemplateResponse(Application::APP_NAME, 'navigate', $data);
99+
return new TemplateResponse(Application::APP_ID, 'navigate', $data);
100100
}
101101

102102
}

lib/Controller/SettingsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(
7171
IRequest $request, ConfigService $configService, SettingsService $settingsService,
7272
MiscService $miscService
7373
) {
74-
parent::__construct(Application::APP_NAME, $request);
74+
parent::__construct(Application::APP_ID, $request);
7575
$this->configService = $configService;
7676
$this->settingsService = $settingsService;
7777
$this->miscService = $miscService;

lib/Controller/TemplatesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
IRequest $request, IConfig $config, ConfigService $configService,
8080
ProviderService $providerService, MiscService $miscService
8181
) {
82-
parent::__construct(Application::APP_NAME, $request);
82+
parent::__construct(Application::APP_ID, $request);
8383
$this->config = $config;
8484
$this->configService = $configService;
8585
$this->providerService = $providerService;

lib/Service/ConfigService.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getAppValue(string $key): string {
140140
$defaultValue = $this->defaults[$key];
141141
}
142142

143-
return $this->config->getAppValue(Application::APP_NAME, $key, $defaultValue);
143+
return $this->config->getAppValue(Application::APP_ID, $key, $defaultValue);
144144
}
145145

146146
/**
@@ -150,7 +150,7 @@ public function getAppValue(string $key): string {
150150
* @param string $value
151151
*/
152152
public function setAppValue(string $key, string $value) {
153-
$this->config->setAppValue(Application::APP_NAME, $key, $value);
153+
$this->config->setAppValue(Application::APP_ID, $key, $value);
154154
}
155155

156156
/**
@@ -159,7 +159,7 @@ public function setAppValue(string $key, string $value) {
159159
* @param string $key
160160
*/
161161
public function deleteAppValue(string $key) {
162-
$this->config->deleteAppValue(Application::APP_NAME, $key);
162+
$this->config->deleteAppValue(Application::APP_ID, $key);
163163
}
164164

165165
/**
@@ -176,7 +176,7 @@ public function getUserValue(string $key): string {
176176
}
177177

178178
return $this->config->getUserValue(
179-
$this->userId, Application::APP_NAME, $key, $defaultValue
179+
$this->userId, Application::APP_ID, $key, $defaultValue
180180
);
181181
}
182182

@@ -189,7 +189,7 @@ public function getUserValue(string $key): string {
189189
* @throws PreConditionNotMetException
190190
*/
191191
public function setUserValue(string $key, string $value) {
192-
$this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value);
192+
$this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
193193
}
194194

195195
/**
@@ -201,7 +201,7 @@ public function setUserValue(string $key, string $value) {
201201
* @return string
202202
*/
203203
public function getValueForUser(string $userId, string $key) {
204-
return $this->config->getUserValue($userId, Application::APP_NAME, $key);
204+
return $this->config->getUserValue($userId, Application::APP_ID, $key);
205205
}
206206

207207
/**
@@ -214,7 +214,7 @@ public function getValueForUser(string $userId, string $key) {
214214
* @throws PreConditionNotMetException
215215
*/
216216
public function setValueForUser(string $userId, string $key, string $value) {
217-
$this->config->setUserValue($userId, Application::APP_NAME, $key, $value);
217+
$this->config->setUserValue($userId, Application::APP_ID, $key, $value);
218218
}
219219

220220

lib/Service/MiscService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct(ILogger $logger) {
6262
*/
6363
public function log(string $message, int $level = 2) {
6464
$data = array(
65-
'app' => Application::APP_NAME,
65+
'app' => Application::APP_ID,
6666
'level' => $level
6767
);
6868

lib/Service/ProviderService.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,13 @@ public function serialize(array $providers): array {
359359
*
360360
*/
361361
public function addJavascriptAPI() {
362-
Util::addStyle(Application::APP_NAME, 'fulltextsearch');
363-
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.api');
364-
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.settings');
365-
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.searchbox');
366-
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.result');
367-
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.navigation');
368-
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1');
362+
Util::addStyle(Application::APP_ID, 'fulltextsearch');
363+
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.api');
364+
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.settings');
365+
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.searchbox');
366+
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.result');
367+
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.navigation');
368+
Util::addScript(Application::APP_ID, 'fulltextsearch.v1');
369369
}
370370

371371

lib/Settings/Admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public function __construct(
8383
* @throws Exception
8484
*/
8585
public function getForm(): TemplateResponse {
86-
return new TemplateResponse(Application::APP_NAME, 'settings.admin', []);
86+
return new TemplateResponse(Application::APP_ID, 'settings.admin', []);
8787
}
8888

8989

9090
/**
9191
* @return string the section ID, e.g. 'sharing'
9292
*/
9393
public function getSection(): string {
94-
return Application::APP_NAME;
94+
return Application::APP_ID;
9595
}
9696

9797

lib/Settings/AdminSection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(IL10N $l10n, IURLGenerator $urlGenerator) {
6565
* {@inheritdoc}
6666
*/
6767
public function getID(): string {
68-
return Application::APP_NAME;
68+
return Application::APP_ID;
6969
}
7070

7171
/**
@@ -86,6 +86,6 @@ public function getPriority(): int {
8686
* {@inheritdoc}
8787
*/
8888
public function getIcon(): string {
89-
return $this->urlGenerator->imagePath(Application::APP_NAME, 'fulltextsearch_black.svg');
89+
return $this->urlGenerator->imagePath(Application::APP_ID, 'fulltextsearch_black.svg');
9090
}
9191
}

0 commit comments

Comments
 (0)