6 * The principal property represents a principal from RFC3744 (ACL).
7 * The property can be used to specify a principal or pseudo principals.
11 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12 * @author Evert Pot (http://www.rooftopsolutions.nl/)
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
15 class Sabre_DAVACL_Property_Principal extends Sabre_DAV_Property implements Sabre_DAV_Property_IHref {
18 * To specify a not-logged-in user, use the UNAUTHENTICATED principal
20 const UNAUTHENTICATED = 1;
23 * To specify any principal that is logged in, use AUTHENTICATED
25 const AUTHENTICATED = 2;
28 * Specific principals can be specified with the HREF
33 * Everybody, basically
40 * Must be one of the UNAUTHENTICATED, AUTHENTICATED or HREF constants.
49 * This value is only used for the HREF principal type.
56 * Creates the property.
58 * The 'type' argument must be one of the type constants defined in this class.
60 * 'href' is only required for the HREF type.
63 * @param string|null $href
65 public function __construct($type, $href = null) {
69 if ($type===self::HREF && is_null($href)) {
70 throw new Sabre_DAV_Exception('The href argument must be specified for the HREF principal type.');
77 * Returns the principal type
81 public function getType() {
88 * Returns the principal uri.
92 public function getHref() {
99 * Serializes the property into a DOMElement.
101 * @param Sabre_DAV_Server $server
102 * @param DOMElement $node
105 public function serialize(Sabre_DAV_Server $server, DOMElement $node) {
107 $prefix = $server->xmlNamespaces['DAV:'];
108 switch($this->type) {
110 case self::UNAUTHENTICATED :
112 $node->ownerDocument->createElement($prefix . ':unauthenticated')
115 case self::AUTHENTICATED :
117 $node->ownerDocument->createElement($prefix . ':authenticated')
121 $href = $node->ownerDocument->createElement($prefix . ':href');
122 $href->nodeValue = $server->getBaseUri() . $this->href;
123 $node->appendChild($href);
131 * Deserializes a DOM element into a property object.
133 * @param DOMElement $dom
134 * @return Sabre_DAVACL_Property_Principal
136 static public function unserialize(DOMElement $dom) {
138 $parent = $dom->firstChild;
139 while(!Sabre_DAV_XMLUtil::toClarkNotation($parent)) {
140 $parent = $parent->nextSibling;
143 switch(Sabre_DAV_XMLUtil::toClarkNotation($parent)) {
145 case '{DAV:}unauthenticated' :
146 return new self(self::UNAUTHENTICATED);
147 case '{DAV:}authenticated' :
148 return new self(self::AUTHENTICATED);
150 return new self(self::HREF, $parent->textContent);
152 return new self(self::ALL);
154 throw new Sabre_DAV_Exception_BadRequest('Unexpected element (' . Sabre_DAV_XMLUtil::toClarkNotation($parent) . '). Could not deserialize');