AddressBookRoot.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CardDAV;
  4. use Sabre\DAVACL;
  5. /**
  6. * AddressBook rootnode.
  7. *
  8. * This object lists a collection of users, which can contain addressbooks.
  9. *
  10. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://sabre.io/license/ Modified BSD License
  13. */
  14. class AddressBookRoot extends DAVACL\AbstractPrincipalCollection
  15. {
  16. /**
  17. * Principal Backend.
  18. *
  19. * @var DAVACL\PrincipalBackend\BackendInterface
  20. */
  21. protected $principalBackend;
  22. /**
  23. * CardDAV backend.
  24. *
  25. * @var Backend\BackendInterface
  26. */
  27. protected $carddavBackend;
  28. /**
  29. * Constructor.
  30. *
  31. * This constructor needs both a principal and a carddav backend.
  32. *
  33. * By default this class will show a list of addressbook collections for
  34. * principals in the 'principals' collection. If your main principals are
  35. * actually located in a different path, use the $principalPrefix argument
  36. * to override this.
  37. *
  38. * @param string $principalPrefix
  39. */
  40. public function __construct(DAVACL\PrincipalBackend\BackendInterface $principalBackend, Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals')
  41. {
  42. $this->carddavBackend = $carddavBackend;
  43. parent::__construct($principalBackend, $principalPrefix);
  44. }
  45. /**
  46. * Returns the name of the node.
  47. *
  48. * @return string
  49. */
  50. public function getName()
  51. {
  52. return Plugin::ADDRESSBOOK_ROOT;
  53. }
  54. /**
  55. * This method returns a node for a principal.
  56. *
  57. * The passed array contains principal information, and is guaranteed to
  58. * at least contain a uri item. Other properties may or may not be
  59. * supplied by the authentication backend.
  60. *
  61. * @return \Sabre\DAV\INode
  62. */
  63. public function getChildForPrincipal(array $principal)
  64. {
  65. return new AddressBookHome($this->carddavBackend, $principal['uri']);
  66. }
  67. }