passman/lib/AppInfo/Application.php

160 lines
4.8 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;
use OCA\UserStatus\Listener\UserDeletedListener;
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;
use OCP\IGroupManager;
2016-09-10 00:36:38 +08:00
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
2021-03-12 09:50:03 +08:00
use OCP\Notification\IManager;
use OCP\User\Events\BeforeUserDeletedEvent;
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();
$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) {
/** @var IUserManager $userManager */
$userManager = $c->get(IUserManager::class);
/** @var IGroupManager $groupManager */
$groupManager = $c->get(IGroupManager::class);
/** @var IUserSession $userSession */
$userSession = $c->get(IUserSession::class);
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'),
$userSession->getUser(),
$groupManager,
$userManager,
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();
/** @var INavigationManager $navigationManager */
$navigationManager = $c->get(INavigationManager::class);
$navigationEntry = function () use ($c) {
/** @var IURLGenerator $urlGenerator */
$urlGenerator = $c->get(IURLGenerator::class);
2016-09-10 00:36:38 +08:00
return [
'id' => $c->getAppName(),
'order' => 10,
'name' => $c->get(IL10N::class)->t('Passwords'),
'href' => $urlGenerator->linkToRoute('passman.page.index'),
'icon' => $urlGenerator->imagePath($c->getAppName(), 'app.svg'),
2016-09-10 00:36:38 +08:00
];
};
$navigationManager->add($navigationEntry);
2016-09-10 00:36:38 +08:00
}
2021-03-12 09:50:03 +08:00
}