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