AddressBookRoot.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\CardDAV;
  8. use OCA\DAV\AppInfo\PluginManager;
  9. use OCP\IGroupManager;
  10. use OCP\IUser;
  11. class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
  12. /**
  13. * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
  14. * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
  15. * @param string $principalPrefix
  16. */
  17. public function __construct(
  18. \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend,
  19. \Sabre\CardDAV\Backend\BackendInterface $carddavBackend,
  20. private PluginManager $pluginManager,
  21. private ?IUser $user,
  22. private ?IGroupManager $groupManager,
  23. string $principalPrefix = 'principals',
  24. ) {
  25. parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
  26. }
  27. /**
  28. * This method returns a node for a principal.
  29. *
  30. * The passed array contains principal information, and is guaranteed to
  31. * at least contain a uri item. Other properties may or may not be
  32. * supplied by the authentication backend.
  33. *
  34. * @param array $principal
  35. *
  36. * @return \Sabre\DAV\INode
  37. */
  38. public function getChildForPrincipal(array $principal) {
  39. return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager, $this->user, $this->groupManager);
  40. }
  41. public function getName() {
  42. if ($this->principalPrefix === 'principals') {
  43. return parent::getName();
  44. }
  45. // Grabbing all the components of the principal path.
  46. $parts = explode('/', $this->principalPrefix);
  47. // We are only interested in the second part.
  48. return $parts[1];
  49. }
  50. }