type = $type; if ($type===self::HREF && is_null($href)) { throw new DAV\Exception('The href argument must be specified for the HREF principal type.'); } $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. * * @param DAV\Server $server * @param \DOMElement $node * @return void */ public function serialize(DAV\Server $server, \DOMElement $node) { $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'); $href->nodeValue = $server->getBaseUri() . $this->href; $node->appendChild($href); break; } } /** * Deserializes a DOM element into a property object. * * @param \DOMElement $dom * @return Principal */ static public function unserialize(\DOMElement $dom) { $parent = $dom->firstChild; while(!DAV\XMLUtil::toClarkNotation($parent)) { $parent = $parent->nextSibling; } switch(DAV\XMLUtil::toClarkNotation($parent)) { 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 : throw new DAV\Exception\BadRequest('Unexpected element (' . DAV\XMLUtil::toClarkNotation($parent) . '). Could not deserialize'); } } }