passman/lib/AppInfo/Application.php

151 lines
4.5 KiB
PHP
Raw Normal View History

2016-09-10 00:36:38 +08:00
<?php
/**
* Nextcloud - passman
*
2016-10-19 23:44:19 +08:00
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-09-10 00:36:38 +08:00
*
*/
namespace OCA\Passman\AppInfo;
2016-09-10 00:36:38 +08:00
use OC\Files\View;
2021-03-12 09:50:03 +08:00
use OC\ServerContainer;
2016-09-23 18:02:41 +08:00
use OCA\Passman\Controller\ShareController;
2017-01-19 20:39:01 +08:00
use OCA\Passman\Middleware\APIMiddleware;
use OCA\Passman\Middleware\ShareMiddleware;
2021-03-12 09:50:03 +08:00
use OCA\Passman\Notifier;
use OCA\Passman\Search\Provider;
2016-09-23 22:52:41 +08:00
use OCA\Passman\Service\ActivityService;
use OCA\Passman\Service\CredentialService;
2021-03-12 09:50:03 +08:00
use OCA\Passman\Service\CronService;
2016-10-05 22:58:19 +08:00
use OCA\Passman\Service\FileService;
2021-03-12 09:50:03 +08:00
use OCA\Passman\Service\NotificationService;
use OCA\Passman\Service\SettingsService;
use OCA\Passman\Service\ShareService;
2016-09-27 03:21:02 +08:00
use OCA\Passman\Service\VaultService;
use OCA\Passman\Utility\Utils;
2016-09-10 00:36:38 +08:00
use OCP\AppFramework\App;
2021-03-12 09:50:03 +08:00
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IDBConnection;
2016-09-10 00:36:38 +08:00
use OCP\IL10N;
2021-03-12 09:50:03 +08:00
use OCP\Notification\IManager;
2016-09-10 00:36:38 +08:00
use OCP\Util;
2021-03-12 09:50:03 +08:00
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
2021-03-12 09:50:03 +08:00
class Application extends App implements IBootstrap {
public const APP_ID = 'passman';
public function __construct() {
2021-03-12 09:50:03 +08:00
parent::__construct(self::APP_ID);
}
public function register(IRegistrationContext $context): void {
$this->registerNavigationEntry();
// $this->registerPersonalPage();
2021-03-12 09:50:03 +08:00
$context->registerEventListener(
BeforeUserDeletedEvent::class,
UserDeletedListener::class
);
$context->registerSearchProvider(Provider::class);
2021-03-12 09:50:03 +08:00
$context->registerService(View::class, function () {
2016-09-10 00:36:38 +08:00
return new View('');
}, false);
2021-03-12 09:50:03 +08:00
$context->registerService('isCLI', function () {
2016-09-10 00:36:38 +08:00
return \OC::$CLI;
});
2016-09-23 18:02:41 +08:00
2021-03-12 09:50:03 +08:00
$context->registerMiddleware(ShareMiddleware::class);
$context->registerMiddleware(APIMiddleware::class);
$context->registerService('ShareController', function (ContainerInterface $c) {
$server = $this->getContainer()->getServer();
2016-09-23 18:02:41 +08:00
return new ShareController(
2021-03-12 09:50:03 +08:00
$c->get('AppName'),
$c->get('Request'),
2016-09-23 18:02:41 +08:00
$server->getUserSession()->getUser(),
$server->getGroupManager(),
$server->getUserManager(),
2021-03-12 09:50:03 +08:00
$c->get(ActivityService::class),
$c->get(VaultService::class),
$c->get(ShareService::class),
$c->get(CredentialService::class),
$c->get(NotificationService::class),
$c->get(FileService::class),
$c->get(SettingsService::class),
$c->get(IManager::class)
2016-09-23 18:02:41 +08:00
);
});
2021-03-12 09:50:03 +08:00
$context->registerService('CronService', function (ContainerInterface $c) {
return new CronService(
2021-03-12 09:50:03 +08:00
$c->get(CredentialService::class),
$c->get(LoggerInterface::class),
2021-03-12 09:50:03 +08:00
$c->get(Utils::class),
$c->get(NotificationService::class),
$c->get(ActivityService::class),
$c->get(IDBConnection::class)
);
});
2021-03-12 09:50:03 +08:00
$context->registerService('Logger', function (ContainerInterface $c) {
return $c->get(ServerContainer::class)->getLogger();
});
2021-03-12 09:50:03 +08:00
}
2021-03-12 09:50:03 +08:00
public function boot(IBootContext $context): void {
/** @var IManager $manager */
$manager = $context->getAppContainer()->get(IManager::class);
$manager->registerNotifierService(Notifier::class);
2021-03-12 09:50:03 +08:00
Util::addTranslations(self::APP_ID);
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();
$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');
}
2021-03-12 09:50:03 +08:00
}