subs[$principalUri])) { return $this->subs[$principalUri]; } return []; } /** * Creates a new subscription for a principal. * * If the creation was a success, an id must be returned that can be used to reference * this subscription in other methods, such as updateSubscription. * * @param string $principalUri * @param string $uri * @param array $properties * @return mixed */ public function createSubscription($principalUri, $uri, array $properties) { $properties['uri'] = $uri; $properties['principaluri'] = $principalUri; $properties['source'] = $properties['{http://calendarserver.org/ns/}source']->getHref(); if (!isset($this->subs[$principalUri])) { $this->subs[$principalUri] = []; } $id = [$principalUri, count($this->subs[$principalUri])+1]; $properties['id'] = $id; $this->subs[$principalUri][] = array_merge($properties, [ 'id' => $id, ]); return $id; } /** * Updates a subscription * * The list of mutations is stored in a Sabre\DAV\PropPatch 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 documenation for more info and examples. * * @param mixed $subscriptionId * @param \Sabre\DAV\PropPatch $propPatch * @return void */ public function updateSubscription($subscriptionId, DAV\PropPatch $propPatch) { $found = null; foreach($this->subs[$subscriptionId[0]] as &$sub) { if ($sub['id'][1] === $subscriptionId[1]) { $found =& $sub; break; } } if (!$found) return; $propPatch->handleRemaining(function($mutations) use (&$found) { foreach($mutations as $k=>$v) { $found[$k] = $v; } return true; }); } /** * Deletes a subscription * * @param mixed $subscriptionId * @return void */ public function deleteSubscription($subscriptionId) { $found = null; foreach($this->subs[$subscriptionId[0]] as $index=>$sub) { if ($sub['id'][1] === $subscriptionId[1]) { unset($this->subs[$subscriptionId[0]][$index]); return true; } } return false; } }