]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/Property/Href.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / Property / Href.php
1 <?php
2
3 /**
4  * Href property
5  *
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
8  *
9  * @package Sabre
10  * @subpackage DAV
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
14  */
15 class Sabre_DAV_Property_Href extends Sabre_DAV_Property implements Sabre_DAV_Property_IHref {
16
17     /**
18      * href
19      *
20      * @var string
21      */
22     private $href;
23
24     /**
25      * Automatically prefix the url with the server base directory
26      *
27      * @var bool
28      */
29     private $autoPrefix = true;
30
31     /**
32      * __construct
33      *
34      * @param string $href
35      * @param bool $autoPrefix
36      */
37     public function __construct($href, $autoPrefix = true) {
38
39         $this->href = $href;
40         $this->autoPrefix = $autoPrefix;
41
42     }
43
44     /**
45      * Returns the uri
46      *
47      * @return string
48      */
49     public function getHref() {
50
51         return $this->href;
52
53     }
54
55     /**
56      * Serializes this property.
57      *
58      * It will additionally prepend the href property with the server's base uri.
59      *
60      * @param Sabre_DAV_Server $server
61      * @param DOMElement $dom
62      * @return void
63      */
64     public function serialize(Sabre_DAV_Server $server, DOMElement $dom) {
65
66         $prefix = $server->xmlNamespaces['DAV:'];
67
68         $elem = $dom->ownerDocument->createElement($prefix . ':href');
69         $elem->nodeValue = ($this->autoPrefix?$server->getBaseUri():'') . $this->href;
70         $dom->appendChild($elem);
71
72     }
73
74     /**
75      * Unserializes this property from a DOM Element
76      *
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.
79      *
80      * @param DOMElement $dom
81      * @return Sabre_DAV_Property_Href
82      */
83     static function unserialize(DOMElement $dom) {
84
85         if (Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild)==='{DAV:}href') {
86             return new self($dom->firstChild->textContent,false);
87         }
88
89     }
90
91 }