3 class Sabre_DAVACL_MockPrincipalBackend implements Sabre_DAVACL_IPrincipalBackend {
5 public $groupMembers = array();
8 function __construct() {
10 $this->principals = array(
12 'uri' => 'principals/user1',
13 '{DAV:}displayname' => 'User 1',
14 '{http://sabredav.org/ns}email-address' => 'user1.sabredav@sabredav.org',
15 '{http://sabredav.org/ns}vcard-url' => 'addressbooks/user1/book1/vcard1.vcf',
18 'uri' => 'principals/admin',
19 '{DAV:}displayname' => 'Admin',
22 'uri' => 'principals/user2',
23 '{DAV:}displayname' => 'User 2',
24 '{http://sabredav.org/ns}email-address' => 'user2.sabredav@sabredav.org',
31 function getPrincipalsByPrefix($prefix) {
33 $prefix = trim($prefix,'/') . '/';
36 foreach($this->principals as $principal) {
38 if (strpos($principal['uri'], $prefix)!==0) continue;
40 $return[] = $principal;
48 function addPrincipal(array $principal) {
50 $this->principals[] = $principal;
54 function getPrincipalByPath($path) {
56 foreach($this->getPrincipalsByPrefix('principals') as $principal) {
57 if ($principal['uri'] === $path) return $principal;
62 function searchPrincipals($prefixPath, array $searchProperties) {
65 foreach($this->getPrincipalsByPrefix($prefixPath) as $principal) {
67 foreach($searchProperties as $key=>$value) {
69 if (!isset($principal[$key])) {
72 if (mb_stripos($principal[$key],$value, 0, 'UTF-8')===false) {
77 $matches[] = $principal['uri'];
84 function getGroupMemberSet($path) {
86 return isset($this->groupMembers[$path]) ? $this->groupMembers[$path] : array();
90 function getGroupMembership($path) {
92 $membership = array();
93 foreach($this->groupMembers as $group=>$members) {
94 if (in_array($path, $members)) $membership[] = $group;
100 function setGroupMemberSet($path, array $members) {
102 $this->groupMembers[$path] = $members;
107 * Updates one ore more webdav properties on a principal.
109 * The list of mutations is supplied as an array. Each key in the array is
110 * a propertyname, such as {DAV:}displayname.
112 * Each value is the actual value to be updated. If a value is null, it
115 * This method should be atomic. It must either completely succeed, or
116 * completely fail. Success and failure can simply be returned as 'true' or
119 * It is also possible to return detailed failure information. In that case
120 * an array such as this should be returned:
124 * '{DAV:}prop1' => null,
127 * '{DAV:}prop2' => null,
130 * '{DAV:}prop3' => null,
133 * '{DAV:}prop4' => null,
137 * In this previous example prop1 was successfully updated or deleted, and
138 * prop2 was succesfully created.
140 * prop3 failed to update due to '403 Forbidden' and because of this prop4
141 * also could not be updated with '424 Failed dependency'.
143 * This last example was actually incorrect. While 200 and 201 could appear
144 * in 1 response, if there's any error (403) the other properties should
145 * always fail with 423 (failed dependency).
147 * But anyway, if you don't want to scratch your head over this, just
148 * return true or false.
150 * @param string $path
151 * @param array $mutations
154 public function updatePrincipal($path, $mutations) {
157 foreach($this->principals as $principalIndex=>$value) {
158 if ($value['uri'] === $path) {
163 if (!$principal) return false;
165 foreach($mutations as $prop=>$value) {
167 if (is_null($value) && isset($principal[$prop])) {
168 unset($principal[$prop]);
170 $principal[$prop] = $value;
175 $this->principals[$principalIndex] = $principal;