BackendInterface.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Backend;
  4. /**
  5. * Every CalDAV backend must at least implement this interface.
  6. *
  7. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  8. * @author Evert Pot (http://evertpot.com/)
  9. * @license http://sabre.io/license/ Modified BSD License
  10. */
  11. interface BackendInterface
  12. {
  13. /**
  14. * Returns a list of calendars for a principal.
  15. *
  16. * Every project is an array with the following keys:
  17. * * id, a unique id that will be used by other functions to modify the
  18. * calendar. This can be the same as the uri or a database key.
  19. * * uri, which is the basename of the uri with which the calendar is
  20. * accessed.
  21. * * principaluri. The owner of the calendar. Almost always the same as
  22. * principalUri passed to this method.
  23. *
  24. * Furthermore it can contain webdav properties in clark notation. A very
  25. * common one is '{DAV:}displayname'.
  26. *
  27. * Many clients also require:
  28. * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set
  29. * For this property, you can just return an instance of
  30. * Sabre\CalDAV\Property\SupportedCalendarComponentSet.
  31. *
  32. * If you return {http://sabredav.org/ns}read-only and set the value to 1,
  33. * ACL will automatically be put in read-only mode.
  34. *
  35. * @param string $principalUri
  36. *
  37. * @return array
  38. */
  39. public function getCalendarsForUser($principalUri);
  40. /**
  41. * Creates a new calendar for a principal.
  42. *
  43. * If the creation was a success, an id must be returned that can be used to
  44. * reference this calendar in other methods, such as updateCalendar.
  45. *
  46. * The id can be any type, including ints, strings, objects or array.
  47. *
  48. * @param string $principalUri
  49. * @param string $calendarUri
  50. *
  51. * @return mixed
  52. */
  53. public function createCalendar($principalUri, $calendarUri, array $properties);
  54. /**
  55. * Updates properties for a calendar.
  56. *
  57. * The list of mutations is stored in a Sabre\DAV\PropPatch object.
  58. * To do the actual updates, you must tell this object which properties
  59. * you're going to process with the handle() method.
  60. *
  61. * Calling the handle method is like telling the PropPatch object "I
  62. * promise I can handle updating this property".
  63. *
  64. * Read the PropPatch documentation for more info and examples.
  65. *
  66. * @param mixed $calendarId
  67. */
  68. public function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch);
  69. /**
  70. * Delete a calendar and all its objects.
  71. *
  72. * @param mixed $calendarId
  73. */
  74. public function deleteCalendar($calendarId);
  75. /**
  76. * Returns all calendar objects within a calendar.
  77. *
  78. * Every item contains an array with the following keys:
  79. * * calendardata - The iCalendar-compatible calendar data
  80. * * uri - a unique key which will be used to construct the uri. This can
  81. * be any arbitrary string, but making sure it ends with '.ics' is a
  82. * good idea. This is only the basename, or filename, not the full
  83. * path.
  84. * * lastmodified - a timestamp of the last modification time
  85. * * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
  86. * '"abcdef"')
  87. * * size - The size of the calendar objects, in bytes.
  88. * * component - optional, a string containing the type of object, such
  89. * as 'vevent' or 'vtodo'. If specified, this will be used to populate
  90. * the Content-Type header.
  91. *
  92. * Note that the etag is optional, but it's highly encouraged to return for
  93. * speed reasons.
  94. *
  95. * The calendardata is also optional. If it's not returned
  96. * 'getCalendarObject' will be called later, which *is* expected to return
  97. * calendardata.
  98. *
  99. * If neither etag or size are specified, the calendardata will be
  100. * used/fetched to determine these numbers. If both are specified the
  101. * amount of times this is needed is reduced by a great degree.
  102. *
  103. * @param mixed $calendarId
  104. *
  105. * @return array
  106. */
  107. public function getCalendarObjects($calendarId);
  108. /**
  109. * Returns information from a single calendar object, based on it's object
  110. * uri.
  111. *
  112. * The object uri is only the basename, or filename and not a full path.
  113. *
  114. * The returned array must have the same keys as getCalendarObjects. The
  115. * 'calendardata' object is required here though, while it's not required
  116. * for getCalendarObjects.
  117. *
  118. * This method must return null if the object did not exist.
  119. *
  120. * @param mixed $calendarId
  121. * @param string $objectUri
  122. *
  123. * @return array|null
  124. */
  125. public function getCalendarObject($calendarId, $objectUri);
  126. /**
  127. * Returns a list of calendar objects.
  128. *
  129. * This method should work identical to getCalendarObject, but instead
  130. * return all the calendar objects in the list as an array.
  131. *
  132. * If the backend supports this, it may allow for some speed-ups.
  133. *
  134. * @param mixed $calendarId
  135. *
  136. * @return array
  137. */
  138. public function getMultipleCalendarObjects($calendarId, array $uris);
  139. /**
  140. * Creates a new calendar object.
  141. *
  142. * The object uri is only the basename, or filename and not a full path.
  143. *
  144. * It is possible to return an etag from this function, which will be used
  145. * in the response to this PUT request. Note that the ETag must be
  146. * surrounded by double-quotes.
  147. *
  148. * However, you should only really return this ETag if you don't mangle the
  149. * calendar-data. If the result of a subsequent GET to this object is not
  150. * the exact same as this request body, you should omit the ETag.
  151. *
  152. * @param mixed $calendarId
  153. * @param string $objectUri
  154. * @param string $calendarData
  155. *
  156. * @return string|null
  157. */
  158. public function createCalendarObject($calendarId, $objectUri, $calendarData);
  159. /**
  160. * Updates an existing calendarobject, based on it's uri.
  161. *
  162. * The object uri is only the basename, or filename and not a full path.
  163. *
  164. * It is possible return an etag from this function, which will be used in
  165. * the response to this PUT request. Note that the ETag must be surrounded
  166. * by double-quotes.
  167. *
  168. * However, you should only really return this ETag if you don't mangle the
  169. * calendar-data. If the result of a subsequent GET to this object is not
  170. * the exact same as this request body, you should omit the ETag.
  171. *
  172. * @param mixed $calendarId
  173. * @param string $objectUri
  174. * @param string $calendarData
  175. *
  176. * @return string|null
  177. */
  178. public function updateCalendarObject($calendarId, $objectUri, $calendarData);
  179. /**
  180. * Deletes an existing calendar object.
  181. *
  182. * The object uri is only the basename, or filename and not a full path.
  183. *
  184. * @param mixed $calendarId
  185. * @param string $objectUri
  186. */
  187. public function deleteCalendarObject($calendarId, $objectUri);
  188. /**
  189. * Performs a calendar-query on the contents of this calendar.
  190. *
  191. * The calendar-query is defined in RFC4791 : CalDAV. Using the
  192. * calendar-query it is possible for a client to request a specific set of
  193. * object, based on contents of iCalendar properties, date-ranges and
  194. * iCalendar component types (VTODO, VEVENT).
  195. *
  196. * This method should just return a list of (relative) urls that match this
  197. * query.
  198. *
  199. * The list of filters are specified as an array. The exact array is
  200. * documented by Sabre\CalDAV\CalendarQueryParser.
  201. *
  202. * Note that it is extremely likely that getCalendarObject for every path
  203. * returned from this method will be called almost immediately after. You
  204. * may want to anticipate this to speed up these requests.
  205. *
  206. * This method provides a default implementation, which parses *all* the
  207. * iCalendar objects in the specified calendar.
  208. *
  209. * This default may well be good enough for personal use, and calendars
  210. * that aren't very large. But if you anticipate high usage, big calendars
  211. * or high loads, you are strongly adviced to optimize certain paths.
  212. *
  213. * The best way to do so is override this method and to optimize
  214. * specifically for 'common filters'.
  215. *
  216. * Requests that are extremely common are:
  217. * * requests for just VEVENTS
  218. * * requests for just VTODO
  219. * * requests with a time-range-filter on either VEVENT or VTODO.
  220. *
  221. * ..and combinations of these requests. It may not be worth it to try to
  222. * handle every possible situation and just rely on the (relatively
  223. * easy to use) CalendarQueryValidator to handle the rest.
  224. *
  225. * Note that especially time-range-filters may be difficult to parse. A
  226. * time-range filter specified on a VEVENT must for instance also handle
  227. * recurrence rules correctly.
  228. * A good example of how to interprete all these filters can also simply
  229. * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct
  230. * as possible, so it gives you a good idea on what type of stuff you need
  231. * to think of.
  232. *
  233. * @param mixed $calendarId
  234. *
  235. * @return array
  236. */
  237. public function calendarQuery($calendarId, array $filters);
  238. /**
  239. * Searches through all of a users calendars and calendar objects to find
  240. * an object with a specific UID.
  241. *
  242. * This method should return the path to this object, relative to the
  243. * calendar home, so this path usually only contains two parts:
  244. *
  245. * calendarpath/objectpath.ics
  246. *
  247. * If the uid is not found, return null.
  248. *
  249. * This method should only consider * objects that the principal owns, so
  250. * any calendars owned by other principals that also appear in this
  251. * collection should be ignored.
  252. *
  253. * @param string $principalUri
  254. * @param string $uid
  255. *
  256. * @return string|null
  257. */
  258. public function getCalendarObjectByUID($principalUri, $uid);
  259. }