Blame view

sources/3rdparty/sabre/dav/lib/Sabre/DAV/Property/Href.php 2.25 KB
03e52840d   Kload   Init
1
  <?php
6d9380f96   Cédric Dupont   Update sources OC...
2
3
4
  namespace Sabre\DAV\Property;
  
  use Sabre\DAV;
03e52840d   Kload   Init
5
6
7
8
9
10
  /**
   * Href property
   *
   * The href property represents a url within a {DAV:}href element.
   * This is used by many WebDAV extensions, but not really within the WebDAV core spec
   *
6d9380f96   Cédric Dupont   Update sources OC...
11
12
13
   * @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   Kload   Init
14
   */
6d9380f96   Cédric Dupont   Update sources OC...
15
  class Href extends DAV\Property implements IHref {
03e52840d   Kload   Init
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
  
      /**
       * href
       *
       * @var string
       */
      private $href;
  
      /**
       * Automatically prefix the url with the server base directory
       *
       * @var bool
       */
      private $autoPrefix = true;
  
      /**
       * __construct
       *
       * @param string $href
       * @param bool $autoPrefix
       */
      public function __construct($href, $autoPrefix = true) {
  
          $this->href = $href;
          $this->autoPrefix = $autoPrefix;
  
      }
  
      /**
       * Returns the uri
       *
       * @return string
       */
      public function getHref() {
  
          return $this->href;
  
      }
  
      /**
       * Serializes this property.
       *
       * It will additionally prepend the href property with the server's base uri.
       *
6d9380f96   Cédric Dupont   Update sources OC...
60
61
       * @param DAV\Server $server
       * @param \DOMElement $dom
03e52840d   Kload   Init
62
63
       * @return void
       */
6d9380f96   Cédric Dupont   Update sources OC...
64
      public function serialize(DAV\Server $server, \DOMElement $dom) {
03e52840d   Kload   Init
65
66
  
          $prefix = $server->xmlNamespaces['DAV:'];
03e52840d   Kload   Init
67
          $elem = $dom->ownerDocument->createElement($prefix . ':href');
6d9380f96   Cédric Dupont   Update sources OC...
68
69
70
71
72
73
74
  
          if ($this->autoPrefix) {
              $value = $server->getBaseUri() . DAV\URLUtil::encodePath($this->href);
          } else {
              $value = $this->href;
          }
          $elem->appendChild($dom->ownerDocument->createTextNode($value));
03e52840d   Kload   Init
75
76
77
78
79
80
81
82
83
84
          $dom->appendChild($elem);
  
      }
  
      /**
       * Unserializes this property from a DOM Element
       *
       * This method returns an instance of this class.
       * It will only decode {DAV:}href values. For non-compatible elements null will be returned.
       *
6d9380f96   Cédric Dupont   Update sources OC...
85
86
       * @param \DOMElement $dom
       * @return DAV\Property\Href
03e52840d   Kload   Init
87
       */
6d9380f96   Cédric Dupont   Update sources OC...
88
      static function unserialize(\DOMElement $dom) {
03e52840d   Kload   Init
89

6d9380f96   Cédric Dupont   Update sources OC...
90
          if ($dom->firstChild && DAV\XMLUtil::toClarkNotation($dom->firstChild)==='{DAV:}href') {
03e52840d   Kload   Init
91
92
93
94
95
96
              return new self($dom->firstChild->textContent,false);
          }
  
      }
  
  }