CalendarRoot.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV;
  4. use Sabre\DAVACL\PrincipalBackend;
  5. /**
  6. * Calendars collection.
  7. *
  8. * This object is responsible for generating a list of calendar-homes for each
  9. * user.
  10. *
  11. * This is the top-most node for the calendars tree. In most servers this class
  12. * represents the "/calendars" path.
  13. *
  14. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  15. * @author Evert Pot (http://evertpot.com/)
  16. * @license http://sabre.io/license/ Modified BSD License
  17. */
  18. class CalendarRoot extends \Sabre\DAVACL\AbstractPrincipalCollection
  19. {
  20. /**
  21. * CalDAV backend.
  22. *
  23. * @var Backend\BackendInterface
  24. */
  25. protected $caldavBackend;
  26. /**
  27. * Constructor.
  28. *
  29. * This constructor needs both an authentication and a caldav backend.
  30. *
  31. * By default this class will show a list of calendar collections for
  32. * principals in the 'principals' collection. If your main principals are
  33. * actually located in a different path, use the $principalPrefix argument
  34. * to override this.
  35. *
  36. * @param string $principalPrefix
  37. */
  38. public function __construct(PrincipalBackend\BackendInterface $principalBackend, Backend\BackendInterface $caldavBackend, $principalPrefix = 'principals')
  39. {
  40. parent::__construct($principalBackend, $principalPrefix);
  41. $this->caldavBackend = $caldavBackend;
  42. }
  43. /**
  44. * Returns the nodename.
  45. *
  46. * We're overriding this, because the default will be the 'principalPrefix',
  47. * and we want it to be Sabre\CalDAV\Plugin::CALENDAR_ROOT
  48. *
  49. * @return string
  50. */
  51. public function getName()
  52. {
  53. return Plugin::CALENDAR_ROOT;
  54. }
  55. /**
  56. * This method returns a node for a principal.
  57. *
  58. * The passed array contains principal information, and is guaranteed to
  59. * at least contain a uri item. Other properties may or may not be
  60. * supplied by the authentication backend.
  61. *
  62. * @return \Sabre\DAV\INode
  63. */
  64. public function getChildForPrincipal(array $principal)
  65. {
  66. return new CalendarHome($this->caldavBackend, $principal);
  67. }
  68. }