BackendInterface.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CardDAV\Backend;
  4. /**
  5. * CardDAV Backend Interface.
  6. *
  7. * Any CardDAV backend must implement this interface.
  8. *
  9. * Note that there are references to 'addressBookId' scattered throughout the
  10. * class. The value of the addressBookId is completely up to you, it can be any
  11. * arbitrary value you can use as an unique identifier.
  12. *
  13. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  14. * @author Evert Pot (http://evertpot.com/)
  15. * @license http://sabre.io/license/ Modified BSD License
  16. */
  17. interface BackendInterface
  18. {
  19. /**
  20. * Returns the list of addressbooks for a specific user.
  21. *
  22. * Every addressbook should have the following properties:
  23. * id - an arbitrary unique id
  24. * uri - the 'basename' part of the url
  25. * principaluri - Same as the passed parameter
  26. *
  27. * Any additional clark-notation property may be passed besides this. Some
  28. * common ones are :
  29. * {DAV:}displayname
  30. * {urn:ietf:params:xml:ns:carddav}addressbook-description
  31. * {http://calendarserver.org/ns/}getctag
  32. *
  33. * @param string $principalUri
  34. *
  35. * @return array
  36. */
  37. public function getAddressBooksForUser($principalUri);
  38. /**
  39. * Updates properties for an address book.
  40. *
  41. * The list of mutations is stored in a Sabre\DAV\PropPatch object.
  42. * To do the actual updates, you must tell this object which properties
  43. * you're going to process with the handle() method.
  44. *
  45. * Calling the handle method is like telling the PropPatch object "I
  46. * promise I can handle updating this property".
  47. *
  48. * Read the PropPatch documentation for more info and examples.
  49. *
  50. * @param string $addressBookId
  51. */
  52. public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch);
  53. /**
  54. * Creates a new address book.
  55. *
  56. * This method should return the id of the new address book. The id can be
  57. * in any format, including ints, strings, arrays or objects.
  58. *
  59. * @param string $principalUri
  60. * @param string $url just the 'basename' of the url
  61. *
  62. * @return mixed
  63. */
  64. public function createAddressBook($principalUri, $url, array $properties);
  65. /**
  66. * Deletes an entire addressbook and all its contents.
  67. *
  68. * @param mixed $addressBookId
  69. */
  70. public function deleteAddressBook($addressBookId);
  71. /**
  72. * Returns all cards for a specific addressbook id.
  73. *
  74. * This method should return the following properties for each card:
  75. * * carddata - raw vcard data
  76. * * uri - Some unique url
  77. * * lastmodified - A unix timestamp
  78. *
  79. * It's recommended to also return the following properties:
  80. * * etag - A unique etag. This must change every time the card changes.
  81. * * size - The size of the card in bytes.
  82. *
  83. * If these last two properties are provided, less time will be spent
  84. * calculating them. If they are specified, you can also ommit carddata.
  85. * This may speed up certain requests, especially with large cards.
  86. *
  87. * @param mixed $addressbookId
  88. *
  89. * @return array
  90. */
  91. public function getCards($addressbookId);
  92. /**
  93. * Returns a specfic card.
  94. *
  95. * The same set of properties must be returned as with getCards. The only
  96. * exception is that 'carddata' is absolutely required.
  97. *
  98. * If the card does not exist, you must return false.
  99. *
  100. * @param mixed $addressBookId
  101. * @param string $cardUri
  102. *
  103. * @return array
  104. */
  105. public function getCard($addressBookId, $cardUri);
  106. /**
  107. * Returns a list of cards.
  108. *
  109. * This method should work identical to getCard, but instead return all the
  110. * cards in the list as an array.
  111. *
  112. * If the backend supports this, it may allow for some speed-ups.
  113. *
  114. * @param mixed $addressBookId
  115. *
  116. * @return array
  117. */
  118. public function getMultipleCards($addressBookId, array $uris);
  119. /**
  120. * Creates a new card.
  121. *
  122. * The addressbook id will be passed as the first argument. This is the
  123. * same id as it is returned from the getAddressBooksForUser method.
  124. *
  125. * The cardUri is a base uri, and doesn't include the full path. The
  126. * cardData argument is the vcard body, and is passed as a string.
  127. *
  128. * It is possible to return an ETag from this method. This ETag is for the
  129. * newly created resource, and must be enclosed with double quotes (that
  130. * is, the string itself must contain the double quotes).
  131. *
  132. * You should only return the ETag if you store the carddata as-is. If a
  133. * subsequent GET request on the same card does not have the same body,
  134. * byte-by-byte and you did return an ETag here, clients tend to get
  135. * confused.
  136. *
  137. * If you don't return an ETag, you can just return null.
  138. *
  139. * @param mixed $addressBookId
  140. * @param string $cardUri
  141. * @param string $cardData
  142. *
  143. * @return string|null
  144. */
  145. public function createCard($addressBookId, $cardUri, $cardData);
  146. /**
  147. * Updates a card.
  148. *
  149. * The addressbook id will be passed as the first argument. This is the
  150. * same id as it is returned from the getAddressBooksForUser method.
  151. *
  152. * The cardUri is a base uri, and doesn't include the full path. The
  153. * cardData argument is the vcard body, and is passed as a string.
  154. *
  155. * It is possible to return an ETag from this method. This ETag should
  156. * match that of the updated resource, and must be enclosed with double
  157. * quotes (that is: the string itself must contain the actual quotes).
  158. *
  159. * You should only return the ETag if you store the carddata as-is. If a
  160. * subsequent GET request on the same card does not have the same body,
  161. * byte-by-byte and you did return an ETag here, clients tend to get
  162. * confused.
  163. *
  164. * If you don't return an ETag, you can just return null.
  165. *
  166. * @param mixed $addressBookId
  167. * @param string $cardUri
  168. * @param string $cardData
  169. *
  170. * @return string|null
  171. */
  172. public function updateCard($addressBookId, $cardUri, $cardData);
  173. /**
  174. * Deletes a card.
  175. *
  176. * @param mixed $addressBookId
  177. * @param string $cardUri
  178. *
  179. * @return bool
  180. */
  181. public function deleteCard($addressBookId, $cardUri);
  182. }