Href.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Href property
  4. *
  5. * The href property represents a url within a {DAV:}href element.
  6. * This is used by many WebDAV extensions, but not really within the WebDAV core spec
  7. *
  8. * @package Sabre
  9. * @subpackage DAV
  10. * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
  11. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  12. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  13. */
  14. class Sabre_DAV_Property_Href extends Sabre_DAV_Property implements Sabre_DAV_Property_IHref {
  15. /**
  16. * href
  17. *
  18. * @var string
  19. */
  20. private $href;
  21. /**
  22. * Automatically prefix the url with the server base directory
  23. *
  24. * @var bool
  25. */
  26. private $autoPrefix = true;
  27. /**
  28. * __construct
  29. *
  30. * @param string $href
  31. * @param bool $autoPrefix
  32. */
  33. public function __construct($href, $autoPrefix = true) {
  34. $this->href = $href;
  35. $this->autoPrefix = $autoPrefix;
  36. }
  37. /**
  38. * Returns the uri
  39. *
  40. * @return string
  41. */
  42. public function getHref() {
  43. return $this->href;
  44. }
  45. /**
  46. * Serializes this property.
  47. *
  48. * It will additionally prepend the href property with the server's base uri.
  49. *
  50. * @param Sabre_DAV_Server $server
  51. * @param DOMElement $dom
  52. * @return void
  53. */
  54. public function serialize(Sabre_DAV_Server $server, DOMElement $dom) {
  55. $prefix = $server->xmlNamespaces['DAV:'];
  56. $elem = $dom->ownerDocument->createElement($prefix . ':href');
  57. $elem->nodeValue = ($this->autoPrefix?$server->getBaseUri():'') . $this->href;
  58. $dom->appendChild($elem);
  59. }
  60. /**
  61. * Unserializes this property from a DOM Element
  62. *
  63. * This method returns an instance of this class.
  64. * It will only decode {DAV:}href values. For non-compatible elements null will be returned.
  65. *
  66. * @param DOMElement $dom
  67. * @return Sabre_DAV_Property_Href
  68. */
  69. static function unserialize(DOMElement $dom) {
  70. if (Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild)==='{DAV:}href') {
  71. return new self($dom->firstChild->textContent,false);
  72. }
  73. }
  74. }