1
0

AddressBookProvider.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\ContactsInteraction;
  8. use OCA\ContactsInteraction\AppInfo\Application;
  9. use OCA\ContactsInteraction\Db\RecentContactMapper;
  10. use OCA\DAV\CardDAV\Integration\ExternalAddressBook;
  11. use OCA\DAV\CardDAV\Integration\IAddressBookProvider;
  12. use OCP\IL10N;
  13. class AddressBookProvider implements IAddressBookProvider {
  14. public function __construct(
  15. private RecentContactMapper $mapper,
  16. private IL10N $l10n,
  17. ) {
  18. }
  19. /**
  20. * @inheritDoc
  21. */
  22. public function getAppId(): string {
  23. return Application::APP_ID;
  24. }
  25. /**
  26. * @inheritDoc
  27. */
  28. public function fetchAllForAddressBookHome(string $principalUri): array {
  29. return [
  30. new AddressBook($this->mapper, $this->l10n, $principalUri)
  31. ];
  32. }
  33. /**
  34. * @inheritDoc
  35. */
  36. public function hasAddressBookInAddressBookHome(string $principalUri, string $uri): bool {
  37. return $uri === AddressBook::URI;
  38. }
  39. /**
  40. * @inheritDoc
  41. */
  42. public function getAddressBookInAddressBookHome(string $principalUri, string $uri): ?ExternalAddressBook {
  43. if ($uri === AddressBook::URI) {
  44. return new AddressBook($this->mapper, $this->l10n, $principalUri);
  45. }
  46. return null;
  47. }
  48. }