Blame view
sources/3rdparty/sabre/dav/lib/Sabre/DAVACL/Property/Principal.php
3.9 KB
|
03e52840d
|
1 |
<?php |
|
6d9380f96
|
2 3 |
namespace Sabre\DAVACL\Property; use Sabre\DAV; |
|
03e52840d
|
4 5 6 7 8 9 |
/** * Principal property * * The principal property represents a principal from RFC3744 (ACL). * The property can be used to specify a principal or pseudo principals. * |
|
6d9380f96
|
10 11 12 |
* @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License |
|
03e52840d
|
13 |
*/ |
|
6d9380f96
|
14 |
class Principal extends DAV\Property implements DAV\Property\IHref {
|
|
03e52840d
|
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
/**
* To specify a not-logged-in user, use the UNAUTHENTICATED principal
*/
const UNAUTHENTICATED = 1;
/**
* To specify any principal that is logged in, use AUTHENTICATED
*/
const AUTHENTICATED = 2;
/**
* Specific principals can be specified with the HREF
*/
const HREF = 3;
/**
* Everybody, basically
*/
const ALL = 4;
/**
* Principal-type
*
* Must be one of the UNAUTHENTICATED, AUTHENTICATED or HREF constants.
*
* @var int
*/
private $type;
/**
* Url to principal
*
* This value is only used for the HREF principal type.
*
* @var string
*/
private $href;
/**
* Creates the property.
*
* The 'type' argument must be one of the type constants defined in this class.
*
* 'href' is only required for the HREF type.
*
* @param int $type
* @param string|null $href
*/
public function __construct($type, $href = null) {
$this->type = $type;
if ($type===self::HREF && is_null($href)) {
|
|
6d9380f96
|
69 |
throw new DAV\Exception('The href argument must be specified for the HREF principal type.');
|
|
03e52840d
|
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
}
$this->href = $href;
}
/**
* Returns the principal type
*
* @return int
*/
public function getType() {
return $this->type;
}
/**
* Returns the principal uri.
*
* @return string
*/
public function getHref() {
return $this->href;
}
/**
* Serializes the property into a DOMElement.
*
|
|
6d9380f96
|
100 101 |
* @param DAV\Server $server
* @param \DOMElement $node
|
|
03e52840d
|
102 103 |
* @return void
*/
|
|
6d9380f96
|
104 |
public function serialize(DAV\Server $server, \DOMElement $node) {
|
|
03e52840d
|
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
$prefix = $server->xmlNamespaces['DAV:'];
switch($this->type) {
case self::UNAUTHENTICATED :
$node->appendChild(
$node->ownerDocument->createElement($prefix . ':unauthenticated')
);
break;
case self::AUTHENTICATED :
$node->appendChild(
$node->ownerDocument->createElement($prefix . ':authenticated')
);
break;
case self::HREF :
$href = $node->ownerDocument->createElement($prefix . ':href');
|
|
6d9380f96
|
121 |
$href->nodeValue = $server->getBaseUri() . DAV\URLUtil::encodePath($this->href); |
|
03e52840d
|
122 123 124 125 126 127 128 129 130 131 |
$node->appendChild($href);
break;
}
}
/**
* Deserializes a DOM element into a property object.
*
|
|
6d9380f96
|
132 133 |
* @param \DOMElement $dom
* @return Principal
|
|
03e52840d
|
134 |
*/ |
|
6d9380f96
|
135 |
static public function unserialize(\DOMElement $dom) {
|
|
03e52840d
|
136 137 |
$parent = $dom->firstChild;
|
|
6d9380f96
|
138 |
while(!DAV\XMLUtil::toClarkNotation($parent)) {
|
|
03e52840d
|
139 140 |
$parent = $parent->nextSibling;
}
|
|
6d9380f96
|
141 |
switch(DAV\XMLUtil::toClarkNotation($parent)) {
|
|
03e52840d
|
142 143 144 145 146 147 148 149 150 151 |
case '{DAV:}unauthenticated' :
return new self(self::UNAUTHENTICATED);
case '{DAV:}authenticated' :
return new self(self::AUTHENTICATED);
case '{DAV:}href':
return new self(self::HREF, $parent->textContent);
case '{DAV:}all':
return new self(self::ALL);
default :
|
|
6d9380f96
|
152 |
throw new DAV\Exception\BadRequest('Unexpected element (' . DAV\XMLUtil::toClarkNotation($parent) . '). Could not deserialize');
|
|
03e52840d
|
153 154 155 156 157 158 |
}
}
}
|