ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MockSubscriptionSupport.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CalDAV\Backend;
4 
5 use Sabre\CalDAV;
6 use Sabre\DAV;
7 
19 
25  protected $subs = [];
26 
54  function getSubscriptionsForUser($principalUri) {
55 
56  if (isset($this->subs[$principalUri])) {
57  return $this->subs[$principalUri];
58  }
59  return [];
60 
61  }
62 
74  function createSubscription($principalUri, $uri, array $properties) {
75 
76  $properties['uri'] = $uri;
77  $properties['principaluri'] = $principalUri;
78  $properties['source'] = $properties['{http://calendarserver.org/ns/}source']->getHref();
79 
80  if (!isset($this->subs[$principalUri])) {
81  $this->subs[$principalUri] = [];
82  }
83 
84  $id = [$principalUri, count($this->subs[$principalUri]) + 1];
85 
86  $properties['id'] = $id;
87 
88  $this->subs[$principalUri][] = array_merge($properties, [
89  'id' => $id,
90  ]);
91 
92  return $id;
93 
94  }
95 
112  function updateSubscription($subscriptionId, DAV\PropPatch $propPatch) {
113 
114  $found = null;
115  foreach ($this->subs[$subscriptionId[0]] as &$sub) {
116 
117  if ($sub['id'][1] === $subscriptionId[1]) {
118  $found = & $sub;
119  break;
120  }
121 
122  }
123 
124  if (!$found) return;
125 
126  $propPatch->handleRemaining(function($mutations) use (&$found) {
127  foreach ($mutations as $k => $v) {
128  $found[$k] = $v;
129  }
130  return true;
131  });
132 
133  }
134 
141  function deleteSubscription($subscriptionId) {
142 
143  foreach ($this->subs[$subscriptionId[0]] as $index => $sub) {
144 
145  if ($sub['id'][1] === $subscriptionId[1]) {
146  unset($this->subs[$subscriptionId[0]][$index]);
147  return true;
148  }
149 
150  }
151 
152  return false;
153 
154  }
155 
156 }
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20
if(!array_key_exists('StateId', $_REQUEST)) $id
$index
Definition: metadata.php:60
deleteSubscription($subscriptionId)
Deletes a subscription.
getSubscriptionsForUser($principalUri)
Returns a list of subscriptions for a principal.
Every CalDAV backend must at least implement this interface.
updateSubscription($subscriptionId, DAV\PropPatch $propPatch)
Updates a subscription.
createSubscription($principalUri, $uri, array $properties)
Creates a new subscription for a principal.
This is a mock CalDAV backend that supports subscriptions.