1<?php 2 3namespace Sabre\DAV\Mock; 4 5use Sabre\DAV\Sharing\ISharedNode; 6use Sabre\DAV\Sharing\Sharee; 7 8class SharedNode extends \Sabre\DAV\Node implements ISharedNode { 9 10 protected $name; 11 protected $access; 12 protected $invites = []; 13 14 function __construct($name, $access) { 15 16 $this->name = $name; 17 $this->access = $access; 18 19 } 20 21 function getName() { 22 23 return $this->name; 24 25 } 26 27 /** 28 * Returns the 'access level' for the instance of this shared resource. 29 * 30 * The value should be one of the Sabre\DAV\Sharing\Plugin::ACCESS_ 31 * constants. 32 * 33 * @return int 34 */ 35 function getShareAccess() { 36 37 return $this->access; 38 39 } 40 41 /** 42 * This function must return a URI that uniquely identifies the shared 43 * resource. This URI should be identical across instances, and is 44 * also used in several other XML bodies to connect invites to 45 * resources. 46 * 47 * This may simply be a relative reference to the original shared instance, 48 * but it could also be a urn. As long as it's a valid URI and unique. 49 * 50 * @return string 51 */ 52 function getShareResourceUri() { 53 54 return 'urn:example:bar'; 55 56 } 57 58 /** 59 * Updates the list of sharees. 60 * 61 * Every item must be a Sharee object. 62 * 63 * @param Sharee[] $sharees 64 * @return void 65 */ 66 function updateInvites(array $sharees) { 67 68 foreach ($sharees as $sharee) { 69 70 if ($sharee->access === \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS) { 71 // Removal 72 foreach ($this->invites as $k => $invitee) { 73 74 if ($invitee->href = $sharee->href) { 75 unset($this->invites[$k]); 76 } 77 78 } 79 80 } else { 81 foreach ($this->invites as $k => $invitee) { 82 83 if ($invitee->href = $sharee->href) { 84 if (!$sharee->inviteStatus) { 85 $sharee->inviteStatus = $invitee->inviteStatus; 86 } 87 // Overwriting an existing invitee 88 $this->invites[$k] = $sharee; 89 continue 2; 90 } 91 92 } 93 if (!$sharee->inviteStatus) { 94 $sharee->inviteStatus = \Sabre\DAV\Sharing\Plugin::INVITE_NORESPONSE; 95 } 96 // Adding a new invitee 97 $this->invites[] = $sharee; 98 } 99 100 } 101 102 } 103 104 /** 105 * Returns the list of people whom this resource is shared with. 106 * 107 * Every item in the returned array must be a Sharee object with 108 * at least the following properties set: 109 * 110 * * $href 111 * * $shareAccess 112 * * $inviteStatus 113 * 114 * and optionally: 115 * 116 * * $properties 117 * 118 * @return \Sabre\DAV\Xml\Element\Sharee[] 119 */ 120 function getInvites() { 121 122 return $this->invites; 123 124 } 125} 126