Node.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Notifications;
  4. use Sabre\CalDAV;
  5. use Sabre\CalDAV\Xml\Notification\NotificationInterface;
  6. use Sabre\DAV;
  7. use Sabre\DAVACL;
  8. /**
  9. * This node represents a single notification.
  10. *
  11. * The signature is mostly identical to that of Sabre\DAV\IFile, but the get() method
  12. * MUST return an xml document that matches the requirements of the
  13. * 'caldav-notifications.txt' spec.
  14. *
  15. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  16. * @author Evert Pot (http://evertpot.com/)
  17. * @license http://sabre.io/license/ Modified BSD License
  18. */
  19. class Node extends DAV\File implements INode, DAVACL\IACL
  20. {
  21. use DAVACL\ACLTrait;
  22. /**
  23. * The notification backend.
  24. *
  25. * @var CalDAV\Backend\NotificationSupport
  26. */
  27. protected $caldavBackend;
  28. /**
  29. * The actual notification.
  30. *
  31. * @var NotificationInterface
  32. */
  33. protected $notification;
  34. /**
  35. * Owner principal of the notification.
  36. *
  37. * @var string
  38. */
  39. protected $principalUri;
  40. /**
  41. * Constructor.
  42. *
  43. * @param string $principalUri
  44. */
  45. public function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, NotificationInterface $notification)
  46. {
  47. $this->caldavBackend = $caldavBackend;
  48. $this->principalUri = $principalUri;
  49. $this->notification = $notification;
  50. }
  51. /**
  52. * Returns the path name for this notification.
  53. *
  54. * @return string
  55. */
  56. public function getName()
  57. {
  58. return $this->notification->getId().'.xml';
  59. }
  60. /**
  61. * Returns the etag for the notification.
  62. *
  63. * The etag must be surrounded by litteral double-quotes.
  64. *
  65. * @return string
  66. */
  67. public function getETag()
  68. {
  69. return $this->notification->getETag();
  70. }
  71. /**
  72. * This method must return an xml element, using the
  73. * Sabre\CalDAV\Xml\Notification\NotificationInterface classes.
  74. *
  75. * @return NotificationInterface
  76. */
  77. public function getNotificationType()
  78. {
  79. return $this->notification;
  80. }
  81. /**
  82. * Deletes this notification.
  83. */
  84. public function delete()
  85. {
  86. $this->caldavBackend->deleteNotification($this->getOwner(), $this->notification);
  87. }
  88. /**
  89. * Returns the owner principal.
  90. *
  91. * This must be a url to a principal, or null if there's no owner
  92. *
  93. * @return string|null
  94. */
  95. public function getOwner()
  96. {
  97. return $this->principalUri;
  98. }
  99. }