Application.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\AppFramework\IAppContainer;
  35. use OCP\IUser;
  36. use Symfony\Component\EventDispatcher\EventDispatcher;
  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(EventDispatcher $dispatcher,
  52. IAppContainer $appContainer): void {
  53. $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($appContainer) {
  54. /** @var IUser $user */
  55. $user = $event->getSubject();
  56. /** @var UpdateLookupServer $updateLookupServer */
  57. $updateLookupServer = $appContainer->get(UpdateLookupServer::class);
  58. $updateLookupServer->userUpdated($user);
  59. });
  60. }
  61. }