SupportedPrivilegeSet.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * SupportedPrivilegeSet property
  4. *
  5. * This property encodes the {DAV:}supported-privilege-set property, as defined
  6. * in rfc3744. Please consult the rfc for details about it's structure.
  7. *
  8. * This class expects a structure like the one given from
  9. * Sabre_DAVACL_Plugin::getSupportedPrivilegeSet as the argument in its
  10. * constructor.
  11. *
  12. * @package Sabre
  13. * @subpackage DAVACL
  14. * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
  15. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  16. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  17. */
  18. class Sabre_DAVACL_Property_SupportedPrivilegeSet extends Sabre_DAV_Property {
  19. /**
  20. * privileges
  21. *
  22. * @var array
  23. */
  24. private $privileges;
  25. /**
  26. * Constructor
  27. *
  28. * @param array $privileges
  29. */
  30. public function __construct(array $privileges) {
  31. $this->privileges = $privileges;
  32. }
  33. /**
  34. * Serializes the property into a domdocument.
  35. *
  36. * @param Sabre_DAV_Server $server
  37. * @param DOMElement $node
  38. * @return void
  39. */
  40. public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
  41. $doc = $node->ownerDocument;
  42. $this->serializePriv($doc, $node, $this->privileges);
  43. }
  44. /**
  45. * Serializes a property
  46. *
  47. * This is a recursive function.
  48. *
  49. * @param DOMDocument $doc
  50. * @param DOMElement $node
  51. * @param array $privilege
  52. * @return void
  53. */
  54. private function serializePriv($doc,$node,$privilege) {
  55. $xsp = $doc->createElementNS('DAV:','d:supported-privilege');
  56. $node->appendChild($xsp);
  57. $xp = $doc->createElementNS('DAV:','d:privilege');
  58. $xsp->appendChild($xp);
  59. $privParts = null;
  60. preg_match('/^{([^}]*)}(.*)$/',$privilege['privilege'],$privParts);
  61. $xp->appendChild($doc->createElementNS($privParts[1],'d:'.$privParts[2]));
  62. if (isset($privilege['abstract']) && $privilege['abstract']) {
  63. $xsp->appendChild($doc->createElementNS('DAV:','d:abstract'));
  64. }
  65. if (isset($privilege['description'])) {
  66. $xsp->appendChild($doc->createElementNS('DAV:','d:description',$privilege['description']));
  67. }
  68. if (isset($privilege['aggregates'])) {
  69. foreach($privilege['aggregates'] as $subPrivilege) {
  70. $this->serializePriv($doc,$xsp,$subPrivilege);
  71. }
  72. }
  73. }
  74. }