6 * The href property represents a url within a {DAV:}href element.
7 * This is used by many WebDAV extensions, but not really within the WebDAV core spec
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_DAV_Property_Href extends Sabre_DAV_Property implements Sabre_DAV_Property_IHref {
25 * Automatically prefix the url with the server base directory
29 private $autoPrefix = true;
35 * @param bool $autoPrefix
37 public function __construct($href, $autoPrefix = true) {
40 $this->autoPrefix = $autoPrefix;
49 public function getHref() {
56 * Serializes this property.
58 * It will additionally prepend the href property with the server's base uri.
60 * @param Sabre_DAV_Server $server
61 * @param DOMElement $dom
64 public function serialize(Sabre_DAV_Server $server, DOMElement $dom) {
66 $prefix = $server->xmlNamespaces['DAV:'];
68 $elem = $dom->ownerDocument->createElement($prefix . ':href');
69 $elem->nodeValue = ($this->autoPrefix?$server->getBaseUri():'') . $this->href;
70 $dom->appendChild($elem);
75 * Unserializes this property from a DOM Element
77 * This method returns an instance of this class.
78 * It will only decode {DAV:}href values. For non-compatible elements null will be returned.
80 * @param DOMElement $dom
81 * @return Sabre_DAV_Property_Href
83 static function unserialize(DOMElement $dom) {
85 if (Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild)==='{DAV:}href') {
86 return new self($dom->firstChild->textContent,false);