Application.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\LookupServerConnector\AppInfo;
  8. use Closure;
  9. use OCA\LookupServerConnector\UpdateLookupServer;
  10. use OCP\Accounts\UserUpdatedEvent;
  11. use OCP\AppFramework\App;
  12. use OCP\AppFramework\Bootstrap\IBootContext;
  13. use OCP\AppFramework\Bootstrap\IBootstrap;
  14. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  15. use OCP\EventDispatcher\IEventDispatcher;
  16. use Psr\Container\ContainerInterface;
  17. class Application extends App implements IBootstrap {
  18. public const APP_ID = 'lookup_server_connector';
  19. public function __construct() {
  20. parent::__construct(self::APP_ID);
  21. }
  22. public function register(IRegistrationContext $context): void {
  23. }
  24. public function boot(IBootContext $context): void {
  25. $context->injectFn(Closure::fromCallable([$this, 'registerEventListeners']));
  26. }
  27. /**
  28. * @todo move the OCP events and then move the registration to `register`
  29. */
  30. private function registerEventListeners(IEventDispatcher $dispatcher,
  31. ContainerInterface $appContainer): void {
  32. $dispatcher->addListener(UserUpdatedEvent::class, function (UserUpdatedEvent $event) use ($appContainer): void {
  33. /** @var UpdateLookupServer $updateLookupServer */
  34. $updateLookupServer = $appContainer->get(UpdateLookupServer::class);
  35. $updateLookupServer->userUpdated($event->getUser());
  36. });
  37. }
  38. }