Application.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\LookupServerConnector\AppInfo;
  28. use Closure;
  29. use OCA\LookupServerConnector\UpdateLookupServer;
  30. use OCP\AppFramework\App;
  31. use OCP\AppFramework\Bootstrap\IBootContext;
  32. use OCP\AppFramework\Bootstrap\IBootstrap;
  33. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  34. use OCP\EventDispatcher\IEventDispatcher;
  35. use OCP\IUser;
  36. use Psr\Container\ContainerInterface;
  37. use Symfony\Component\EventDispatcher\GenericEvent;
  38. class Application extends App implements IBootstrap {
  39. public const APP_ID = 'lookup_server_connector';
  40. public function __construct() {
  41. parent::__construct(self::APP_ID);
  42. }
  43. public function register(IRegistrationContext $context): void {
  44. }
  45. public function boot(IBootContext $context): void {
  46. $context->injectFn(Closure::fromCallable([$this, 'registerEventListeners']));
  47. }
  48. /**
  49. * @todo move the OCP events and then move the registration to `register`
  50. */
  51. private function registerEventListeners(IEventDispatcher $dispatcher,
  52. ContainerInterface $appContainer): void {
  53. $dispatcher->addListener('OC\AccountManager::userUpdated', function ($event) use ($appContainer) {
  54. if ($event instanceof GenericEvent) {
  55. /** @var IUser $user */
  56. $user = $event->getSubject();
  57. /** @var UpdateLookupServer $updateLookupServer */
  58. $updateLookupServer = $appContainer->get(UpdateLookupServer::class);
  59. $updateLookupServer->userUpdated($user);
  60. }
  61. });
  62. }
  63. }