passman/lib/AppInfo/Application.php

118 lines
3.5 KiB
PHP
Raw Normal View History

2016-09-10 00:36:38 +08:00
<?php
/**
* Nextcloud - passman
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <brantje@gmail.com>
* @copyright Sander Brand 2016
*/
namespace OCA\Passman\AppInfo;
use OC\Files\View;
use OCA\Passman\Controller\CredentialController;
use OCA\Passman\Controller\PageController;
2016-09-23 18:02:41 +08:00
use OCA\Passman\Controller\ShareController;
2016-09-10 00:36:38 +08:00
use OCA\Passman\Controller\VaultController;
2016-09-23 22:52:41 +08:00
use OCA\Passman\Service\ActivityService;
use OCA\Passman\Service\CronService;
use OCA\Passman\Service\CredentialService;
2016-09-27 03:21:02 +08:00
use OCA\Passman\Service\VaultService;
use OCA\Passman\Utility\Utils;
use OCA\Passman\Service\NotificationService;
2016-09-10 00:36:38 +08:00
use OCP\AppFramework\App;
use OCP\IL10N;
use OCP\Util;
class Application extends App {
public function __construct () {
parent::__construct('passman');
$container = $this->getContainer();
2016-09-23 18:02:41 +08:00
$server = $container->getServer();
2016-09-10 00:36:38 +08:00
// Allow automatic DI for the View, until we migrated to Nodes API
$container->registerService(View::class, function() {
return new View('');
}, false);
$container->registerService('isCLI', function() {
return \OC::$CLI;
});
2016-09-23 18:02:41 +08:00
/**
* Controllers
*/
$container->registerService('ShareController', function($c) {
$container = $this->getContainer();
$server = $container->getServer();
return new ShareController(
$c->query('AppName'),
$c->query('Request'),
$server->getUserSession()->getUser(),
$server->getGroupManager(),
$server->getUserManager(),
2016-09-27 03:21:02 +08:00
$c->query('ActivityService'),
$c->query('VaultService')
2016-09-23 18:02:41 +08:00
);
});
/** Cron **/
$container->registerService('CronService', function ($c) {
return new CronService(
$c->query('CredentialService'),
$c->query('Logger'),
$c->query('Utils'),
2016-09-23 22:52:41 +08:00
$c->query('NotificationService'),
$c->query('ActivityService'),
$c->query('ServerContainer')->getDb()
);
});
$container->registerService('Db', function () {
return new Db();
});
$container->registerService('Logger', function($c) {
return $c->query('ServerContainer')->getLogger();
});
2016-09-10 00:36:38 +08:00
// Aliases for the controllers so we can use the automatic DI
$container->registerAlias('CredentialController', CredentialController::class);
$container->registerAlias('PageController', PageController::class);
$container->registerAlias('VaultController', VaultController::class);
2016-09-27 03:21:02 +08:00
$container->registerAlias('VaultController', VaultController::class);
$container->registerAlias('CredentialService', CredentialService::class);
$container->registerAlias('NotificationService', NotificationService::class);
2016-09-27 03:23:24 +08:00
$container->registerAlias('ActivityService', ActivityService::class);
2016-09-27 03:21:02 +08:00
$container->registerAlias('VaultService', VaultService::class);
$container->registerAlias('Utils', Utils::class);
2016-09-10 00:36:38 +08:00
}
2016-09-23 18:02:41 +08:00
2016-09-10 00:36:38 +08:00
/**
* Register the navigation entry
*/
public function registerNavigationEntry() {
$c = $this->getContainer();
/** @var \OCP\IServerContainer $server */
$server = $c->getServer();
$navigationEntry = function () use ($c, $server) {
return [
'id' => $c->getAppName(),
'order' => 10,
2016-09-11 05:30:17 +08:00
'name' => $c->query(IL10N::class)->t('Passwords'),
'href' => $server->getURLGenerator()->linkToRoute('passman.page.index'),
2016-09-10 00:36:38 +08:00
'icon' => $server->getURLGenerator()->imagePath($c->getAppName(), 'app.svg'),
];
};
$server->getNavigationManager()->add($navigationEntry);
}
/**
* Register personal settings for notifications and emails
*/
public function registerPersonalPage() {
\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
}
}