HrefList.php 2.2 KB

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