Application.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Accounts\UserUpdatedEvent;
  31. use OCP\AppFramework\App;
  32. use OCP\AppFramework\Bootstrap\IBootContext;
  33. use OCP\AppFramework\Bootstrap\IBootstrap;
  34. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  35. use OCP\EventDispatcher\IEventDispatcher;
  36. use Psr\Container\ContainerInterface;
  37. class Application extends App implements IBootstrap {
  38. public const APP_ID = 'lookup_server_connector';
  39. public function __construct() {
  40. parent::__construct(self::APP_ID);
  41. }
  42. public function register(IRegistrationContext $context): void {
  43. }
  44. public function boot(IBootContext $context): void {
  45. $context->injectFn(Closure::fromCallable([$this, 'registerEventListeners']));
  46. }
  47. /**
  48. * @todo move the OCP events and then move the registration to `register`
  49. */
  50. private function registerEventListeners(IEventDispatcher $dispatcher,
  51. ContainerInterface $appContainer): void {
  52. $dispatcher->addListener(UserUpdatedEvent::class, function (UserUpdatedEvent $event) use ($appContainer) {
  53. /** @var UpdateLookupServer $updateLookupServer */
  54. $updateLookupServer = $appContainer->get(UpdateLookupServer::class);
  55. $updateLookupServer->userUpdated($event->getUser());
  56. });
  57. }
  58. }