ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\CardDAV\Backend\Mock Class Reference
+ Inheritance diagram for Sabre\CardDAV\Backend\Mock:
+ Collaboration diagram for Sabre\CardDAV\Backend\Mock:

Public Member Functions

 __construct ($addressBooks=null, $cards=null)
 
 getAddressBooksForUser ($principalUri)
 Returns the list of addressbooks for a specific user. More...
 
 updateAddressBook ($addressBookId, \Sabre\DAV\PropPatch $propPatch)
 Updates properties for an address book. More...
 
 createAddressBook ($principalUri, $url, array $properties)
 Creates a new address book. More...
 
 deleteAddressBook ($addressBookId)
 Deletes an entire addressbook and all its contents. More...
 
 getCards ($addressBookId)
 Returns all cards for a specific addressbook id. More...
 
 getCard ($addressBookId, $cardUri)
 Returns a specfic card. More...
 
 createCard ($addressBookId, $cardUri, $cardData)
 Creates a new card. More...
 
 updateCard ($addressBookId, $cardUri, $cardData)
 Updates a card. More...
 
 deleteCard ($addressBookId, $cardUri)
 Deletes a card. More...
 
- Public Member Functions inherited from Sabre\CardDAV\Backend\AbstractBackend
 getMultipleCards ($addressBookId, array $uris)
 Returns a list of cards. More...
 

Data Fields

 $addressBooks
 
 $cards
 

Detailed Description

Definition at line 5 of file Mock.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\CardDAV\Backend\Mock::__construct (   $addressBooks = null,
  $cards = null 
)

Definition at line 10 of file Mock.php.

References Sabre\CardDAV\Backend\Mock\$addressBooks, and Sabre\CardDAV\Backend\Mock\$cards.

10  {
11 
12  $this->addressBooks = $addressBooks;
13  $this->cards = $cards;
14 
15  if (is_null($this->addressBooks)) {
16  $this->addressBooks = [
17  [
18  'id' => 'foo',
19  'uri' => 'book1',
20  'principaluri' => 'principals/user1',
21  '{DAV:}displayname' => 'd-name',
22  ],
23  [
24  'id' => 'bar',
25  'uri' => 'book3',
26  'principaluri' => 'principals/user1',
27  '{DAV:}displayname' => 'd-name',
28  ],
29  ];
30 
31  $card2 = fopen('php://memory', 'r+');
32  fwrite($card2, "BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD");
33  rewind($card2);
34  $this->cards = [
35  'foo' => [
36  'card1' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
37  'card2' => $card2,
38  ],
39  'bar' => [
40  'card3' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nFN:Test-Card\nEMAIL;TYPE=home:bar@example.org\nEND:VCARD",
41  ],
42  ];
43  }
44 
45  }

Member Function Documentation

◆ createAddressBook()

Sabre\CardDAV\Backend\Mock::createAddressBook (   $principalUri,
  $url,
array  $properties 
)

Creates a new address book.

This method should return the id of the new address book. The id can be in any format, including ints, strings, arrays or objects.

Parameters
string$principalUri
string$urlJust the 'basename' of the url.
array$properties
Returns
mixed

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 93 of file Mock.php.

References $url.

93  {
94 
95  $this->addressBooks[] = array_merge($properties, [
96  'id' => $url,
97  'uri' => $url,
98  'principaluri' => $principalUri,
99  ]);
100 
101  }
$url

◆ createCard()

Sabre\CardDAV\Backend\Mock::createCard (   $addressBookId,
  $cardUri,
  $cardData 
)

Creates a new card.

The addressbook id will be passed as the first argument. This is the same id as it is returned from the getAddressBooksForUser method.

The cardUri is a base uri, and doesn't include the full path. The cardData argument is the vcard body, and is passed as a string.

It is possible to return an ETag from this method. This ETag is for the newly created resource, and must be enclosed with double quotes (that is, the string itself must contain the double quotes).

You should only return the ETag if you store the carddata as-is. If a subsequent GET request on the same card does not have the same body, byte-by-byte and you did return an ETag here, clients tend to get confused.

If you don't return an ETag, you can just return null.

Parameters
mixed$addressBookId
string$cardUri
string$cardData
Returns
string|null

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 207 of file Mock.php.

207  {
208 
209  if (is_resource($cardData)) {
210  $cardData = stream_get_contents($cardData);
211  }
212  $this->cards[$addressBookId][$cardUri] = $cardData;
213  return '"' . md5($cardData) . '"';
214 
215  }

◆ deleteAddressBook()

Sabre\CardDAV\Backend\Mock::deleteAddressBook (   $addressBookId)

Deletes an entire addressbook and all its contents.

Parameters
mixed$addressBookId
Returns
void

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 103 of file Mock.php.

References $key.

103  {
104 
105  foreach ($this->addressBooks as $key => $value) {
106  if ($value['id'] === $addressBookId)
107  unset($this->addressBooks[$key]);
108  }
109  unset($this->cards[$addressBookId]);
110 
111  }
$key
Definition: croninfo.php:18

◆ deleteCard()

Sabre\CardDAV\Backend\Mock::deleteCard (   $addressBookId,
  $cardUri 
)

Deletes a card.

Parameters
mixed$addressBookId
string$cardUri
Returns
bool

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 252 of file Mock.php.

252  {
253 
254  unset($this->cards[$addressBookId][$cardUri]);
255 
256  }

◆ getAddressBooksForUser()

Sabre\CardDAV\Backend\Mock::getAddressBooksForUser (   $principalUri)

Returns the list of addressbooks for a specific user.

Every addressbook should have the following properties: id - an arbitrary unique id uri - the 'basename' part of the url principaluri - Same as the passed parameter

Any additional clark-notation property may be passed besides this. Some common ones are : {DAV:}displayname {urn:ietf:params:xml:ns:carddav}addressbook-description {http://calendarserver.org/ns/}getctag

Parameters
string$principalUri
Returns
array

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 48 of file Mock.php.

48  {
49 
50  $books = [];
51  foreach ($this->addressBooks as $book) {
52  if ($book['principaluri'] === $principalUri) {
53  $books[] = $book;
54  }
55  }
56  return $books;
57 
58  }

◆ getCard()

Sabre\CardDAV\Backend\Mock::getCard (   $addressBookId,
  $cardUri 
)

Returns a specfic card.

The same set of properties must be returned as with getCards. The only exception is that 'carddata' is absolutely required.

If the card does not exist, you must return false.

Parameters
mixed$addressBookId
string$cardUri
Returns
array

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 166 of file Mock.php.

References $data.

166  {
167 
168  if (!isset($this->cards[$addressBookId][$cardUri])) {
169  return false;
170  }
171 
172  $data = $this->cards[$addressBookId][$cardUri];
173  return [
174  'uri' => $cardUri,
175  'carddata' => $data,
176  'etag' => '"' . md5($data) . '"',
177  'size' => strlen($data)
178  ];
179 
180  }
$data
Definition: bench.php:6

◆ getCards()

Sabre\CardDAV\Backend\Mock::getCards (   $addressBookId)

Returns all cards for a specific addressbook id.

This method should return the following properties for each card:

  • carddata - raw vcard data
  • uri - Some unique url
  • lastmodified - A unix timestamp

It's recommended to also return the following properties:

  • etag - A unique etag. This must change every time the card changes.
  • size - The size of the card in bytes.

If these last two properties are provided, less time will be spent calculating them. If they are specified, you can also ommit carddata. This may speed up certain requests, especially with large cards.

Parameters
mixed$addressBookId
Returns
array

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 132 of file Mock.php.

References Sabre\CardDAV\Backend\Mock\$cards, and $data.

132  {
133 
134  $cards = [];
135  foreach ($this->cards[$addressBookId] as $uri => $data) {
136  if (is_resource($data)) {
137  $cards[] = [
138  'uri' => $uri,
139  'carddata' => $data,
140  ];
141  } else {
142  $cards[] = [
143  'uri' => $uri,
144  'carddata' => $data,
145  'etag' => '"' . md5($data) . '"',
146  'size' => strlen($data)
147  ];
148  }
149  }
150  return $cards;
151 
152  }
$data
Definition: bench.php:6

◆ updateAddressBook()

Sabre\CardDAV\Backend\Mock::updateAddressBook (   $addressBookId,
\Sabre\DAV\PropPatch  $propPatch 
)

Updates properties for an address book.

The list of mutations is stored in a Sabre object. To do the actual updates, you must tell this object which properties you're going to process with the handle() method.

Calling the handle method is like telling the PropPatch object "I promise I can handle updating this property".

Read the PropPatch documentation for more info and examples.

Parameters
string$addressBookId
\Sabre\DAV\PropPatch$propPatch
Returns
void

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 76 of file Mock.php.

References $key.

76  {
77 
78  foreach ($this->addressBooks as &$book) {
79  if ($book['id'] !== $addressBookId)
80  continue;
81 
82  $propPatch->handleRemaining(function($mutations) use (&$book) {
83  foreach ($mutations as $key => $value) {
84  $book[$key] = $value;
85  }
86  return true;
87  });
88 
89  }
90 
91  }
$key
Definition: croninfo.php:18

◆ updateCard()

Sabre\CardDAV\Backend\Mock::updateCard (   $addressBookId,
  $cardUri,
  $cardData 
)

Updates a card.

The addressbook id will be passed as the first argument. This is the same id as it is returned from the getAddressBooksForUser method.

The cardUri is a base uri, and doesn't include the full path. The cardData argument is the vcard body, and is passed as a string.

It is possible to return an ETag from this method. This ETag should match that of the updated resource, and must be enclosed with double quotes (that is: the string itself must contain the actual quotes).

You should only return the ETag if you store the carddata as-is. If a subsequent GET request on the same card does not have the same body, byte-by-byte and you did return an ETag here, clients tend to get confused.

If you don't return an ETag, you can just return null.

Parameters
mixed$addressBookId
string$cardUri
string$cardData
Returns
string|null

Implements Sabre\CardDAV\Backend\BackendInterface.

Definition at line 242 of file Mock.php.

242  {
243 
244  if (is_resource($cardData)) {
245  $cardData = stream_get_contents($cardData);
246  }
247  $this->cards[$addressBookId][$cardUri] = $cardData;
248  return '"' . md5($cardData) . '"';
249 
250  }

Field Documentation

◆ $addressBooks

Sabre\CardDAV\Backend\Mock::$addressBooks

Definition at line 7 of file Mock.php.

Referenced by Sabre\CardDAV\Backend\Mock\__construct().

◆ $cards

Sabre\CardDAV\Backend\Mock::$cards

The documentation for this class was generated from the following file: